From decc047e421bbf4ebd909602ca220886786cf20e Mon Sep 17 00:00:00 2001 From: Adubbz Date: Sun, 11 Jan 2015 16:51:04 +1100 Subject: [PATCH] Began work on readding coral --- .gitignore | 6 ++ .../biomesoplenty/api/block/BOPBlocks.java | 1 + .../biomesoplenty/api/block/BOPPlant.java | 9 +- .../common/block/BlockCoral.java | 87 +++++++++++++++++++ .../common/block/BlockSegmentedCoral.java | 13 +++ .../BlockModelRegisterEventHandler.java | 30 +++++++ .../biomesoplenty/common/init/ModBlocks.java | 2 + .../common/init/ModHandlers.java | 20 +++++ .../biomesoplenty/core/BiomesOPlenty.java | 2 + .../biomesoplenty/blockstates/coral.json | 8 +- 10 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100644 src/main/java/biomesoplenty/common/block/BlockCoral.java create mode 100644 src/main/java/biomesoplenty/common/block/BlockSegmentedCoral.java create mode 100644 src/main/java/biomesoplenty/common/handler/BlockModelRegisterEventHandler.java create mode 100644 src/main/java/biomesoplenty/common/init/ModHandlers.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..ca21b090a --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/build/ +/bin/ +/.gradle/ +/.settings/ +/.classpath +/.project diff --git a/src/main/java/biomesoplenty/api/block/BOPBlocks.java b/src/main/java/biomesoplenty/api/block/BOPBlocks.java index 720217ea4..48cefdcfb 100644 --- a/src/main/java/biomesoplenty/api/block/BOPBlocks.java +++ b/src/main/java/biomesoplenty/api/block/BOPBlocks.java @@ -14,6 +14,7 @@ public class BOPBlocks { public static Block ash_block; public static Block bamboo; + public static Block coral; public static Block flower; public static Block flower2; public static Block gem; diff --git a/src/main/java/biomesoplenty/api/block/BOPPlant.java b/src/main/java/biomesoplenty/api/block/BOPPlant.java index b9090c954..1392e8cfb 100644 --- a/src/main/java/biomesoplenty/api/block/BOPPlant.java +++ b/src/main/java/biomesoplenty/api/block/BOPPlant.java @@ -26,9 +26,9 @@ import net.minecraftforge.fml.relauncher.SideOnly; public class BOPPlant extends BOPBlock { - protected BOPPlant() + protected BOPPlant(Material material) { - super(Material.plants); + super(material); this.setTickRandomly(true); @@ -36,6 +36,11 @@ public class BOPPlant extends BOPBlock this.setStepSound(Block.soundTypeGrass); } + protected BOPPlant() + { + this(Material.plants); + } + @Override public boolean canReplace(World world, BlockPos pos, EnumFacing side, ItemStack stack) { diff --git a/src/main/java/biomesoplenty/common/block/BlockCoral.java b/src/main/java/biomesoplenty/common/block/BlockCoral.java new file mode 100644 index 000000000..ce0795de5 --- /dev/null +++ b/src/main/java/biomesoplenty/common/block/BlockCoral.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright 2014, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ + +package biomesoplenty.common.block; + +import static net.minecraft.block.BlockLiquid.LEVEL; + +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.properties.PropertyInteger; +import net.minecraft.block.state.BlockState; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.IStringSerializable; +import biomesoplenty.api.block.BOPPlant; + +public class BlockCoral extends BOPPlant +{ + public static PropertyEnum VARIANT_PROP = PropertyEnum.create("variant", CoralType.class); + + public BlockCoral() + { + super(Material.water); + + this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT_PROP, CoralType.PINK)); + } + + @Override + public IBlockState getStateFromMeta(int meta) + { + return this.getDefaultState().withProperty(VARIANT_PROP, CoralType.values()[meta]).withProperty(LEVEL, 15); + } + + @Override + public int getMetaFromState(IBlockState state) + { + int meta = ((CoralType)state.getValue(VARIANT_PROP)).ordinal(); + + return meta; + } + + @Override + protected BlockState createBlockState() + { + return new BlockState(this, new IProperty[] { VARIANT_PROP, LEVEL }); + } + + @Override + public IProperty[] getPresetProperties() + { + return new IProperty[] { VARIANT_PROP }; + } + + @Override + public String getStateName(IBlockState state, boolean fullName) + { + CoralType type = (CoralType)state.getValue(VARIANT_PROP); + + return type.getName() + (fullName && type != CoralType.ALGAE ? "_coral" : ""); + } + + public static enum CoralType implements IStringSerializable + { + PINK, + ORANGE, + BLUE, + GLOWING, + ALGAE; + + @Override + public String getName() + { + return this.name().toLowerCase(); + } + + @Override + public String toString() + { + return getName(); + } + } +} diff --git a/src/main/java/biomesoplenty/common/block/BlockSegmentedCoral.java b/src/main/java/biomesoplenty/common/block/BlockSegmentedCoral.java new file mode 100644 index 000000000..1dc4d38a3 --- /dev/null +++ b/src/main/java/biomesoplenty/common/block/BlockSegmentedCoral.java @@ -0,0 +1,13 @@ +/******************************************************************************* + * Copyright 2014, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ + +package biomesoplenty.common.block; + +public class BlockSegmentedCoral { + +} diff --git a/src/main/java/biomesoplenty/common/handler/BlockModelRegisterEventHandler.java b/src/main/java/biomesoplenty/common/handler/BlockModelRegisterEventHandler.java new file mode 100644 index 000000000..c28b07f2b --- /dev/null +++ b/src/main/java/biomesoplenty/common/handler/BlockModelRegisterEventHandler.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2014, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ + +package biomesoplenty.common.handler; + +import biomesoplenty.api.block.BOPBlocks; +import net.minecraft.block.BlockJukebox; +import net.minecraft.block.BlockLiquid; +import net.minecraft.block.properties.IProperty; +import net.minecraft.client.renderer.BlockModelShapes; +import net.minecraft.client.renderer.block.statemap.StateMap; +import net.minecraftforge.client.event.BlockModelRegisterEvent; +import net.minecraftforge.client.event.ModelBakeEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +public class BlockModelRegisterEventHandler +{ + @SubscribeEvent + public void onBlockModelRegister(BlockModelRegisterEvent event) + { + BlockModelShapes modelShapes = event.modelShapes; + + modelShapes.registerBlockWithStateMapper(BOPBlocks.coral, (new StateMap.Builder()).addPropertiesToIgnore(new IProperty[] {BlockLiquid.LEVEL}).build()); + } +} diff --git a/src/main/java/biomesoplenty/common/init/ModBlocks.java b/src/main/java/biomesoplenty/common/init/ModBlocks.java index bc9f5a58e..057db4056 100644 --- a/src/main/java/biomesoplenty/common/init/ModBlocks.java +++ b/src/main/java/biomesoplenty/common/init/ModBlocks.java @@ -29,6 +29,7 @@ import biomesoplenty.common.block.BlockBOPMushroom; import biomesoplenty.common.block.BlockBOPPlanks; import biomesoplenty.common.block.BlockBOPStone; import biomesoplenty.common.block.BlockBamboo; +import biomesoplenty.common.block.BlockCoral; import biomesoplenty.common.block.BlockGem; import biomesoplenty.common.block.BlockGemOre; import biomesoplenty.common.block.BlockHive; @@ -42,6 +43,7 @@ public class ModBlocks { ash_block = registerBlock(new BlockAsh(), "ash_block"); bamboo = registerBlock(new BlockBamboo(), "bamboo"); + coral = registerBlock(new BlockCoral(), "coral"); flower = registerBlock(new BlockBOPFlower(), "flower"); flower2 = registerBlock(new BlockBOPFlower2(), "flower2"); gem = registerBlock(new BlockGem(), "gem"); diff --git a/src/main/java/biomesoplenty/common/init/ModHandlers.java b/src/main/java/biomesoplenty/common/init/ModHandlers.java new file mode 100644 index 000000000..4d90f66d6 --- /dev/null +++ b/src/main/java/biomesoplenty/common/init/ModHandlers.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright 2014, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ + +package biomesoplenty.common.init; + +import biomesoplenty.common.handler.BlockModelRegisterEventHandler; +import net.minecraftforge.common.MinecraftForge; + +public class ModHandlers +{ + public static void init() + { + MinecraftForge.EVENT_BUS.register(new BlockModelRegisterEventHandler()); + } +} diff --git a/src/main/java/biomesoplenty/core/BiomesOPlenty.java b/src/main/java/biomesoplenty/core/BiomesOPlenty.java index 4ad060a4c..bcecc4f0b 100644 --- a/src/main/java/biomesoplenty/core/BiomesOPlenty.java +++ b/src/main/java/biomesoplenty/core/BiomesOPlenty.java @@ -19,6 +19,7 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import biomesoplenty.common.init.ModBlocks; import biomesoplenty.common.init.ModConfiguration; +import biomesoplenty.common.init.ModHandlers; import biomesoplenty.common.init.ModItems; @Mod(modid = BiomesOPlenty.MOD_ID, name = BiomesOPlenty.MOD_NAME) @@ -43,6 +44,7 @@ public class BiomesOPlenty ModConfiguration.init(configDirectory); ModItems.init(); ModBlocks.init(); + ModHandlers.init(); } @EventHandler diff --git a/src/main/resources/assets/biomesoplenty/blockstates/coral.json b/src/main/resources/assets/biomesoplenty/blockstates/coral.json index 2016d64e3..6ffecd9b7 100644 --- a/src/main/resources/assets/biomesoplenty/blockstates/coral.json +++ b/src/main/resources/assets/biomesoplenty/blockstates/coral.json @@ -4,10 +4,10 @@ "variant=kelp_middle": { "model": "biomesoplenty:kelp_middle" }, "variant=kelp_top": { "model": "biomesoplenty:kelp_top" }, "variant=kelp": { "model": "biomesoplenty:kelp" }, - "variant=pink_coral": { "model": "biomesoplenty:pink_coral" }, - "variant=orange_coral": { "model": "biomesoplenty:orange_coral" }, - "variant=blue_coral": { "model": "biomesoplenty:blue_coral" }, - "variant=glowing_coral": { "model": "biomesoplenty:glowing_coral" }, + "variant=pink": { "model": "biomesoplenty:pink_coral" }, + "variant=orange": { "model": "biomesoplenty:orange_coral" }, + "variant=blue": { "model": "biomesoplenty:blue_coral" }, + "variant=glowing": { "model": "biomesoplenty:glowing_coral" }, "variant=algae": { "model": "biomesoplenty:algae" } } }