From 591bdebe5efce93bdfeebc31c4be9d92c05e33cb Mon Sep 17 00:00:00 2001 From: Cheeserolls Date: Sat, 23 May 2015 19:14:48 +0100 Subject: [PATCH] Add kelp --- .../biomesoplenty/api/block/BOPBlocks.java | 1 + .../java/biomesoplenty/api/item/BOPItems.java | 2 - .../common/block/BlockCoral.java | 2 +- .../common/block/BlockSeaweed.java | 160 ++++++++++++++++++ .../biomesoplenty/common/init/ModBlocks.java | 1 + .../common/init/ModCrafting.java | 2 +- .../biomesoplenty/blockstates/seaweed.json | 9 + .../block/{kelp.json => kelp_single.json} | 2 +- .../biomesoplenty/models/item/kelp.json | 2 +- .../models/item/kelp_bottom.json | 18 -- .../models/item/kelp_middle.json | 18 -- .../biomesoplenty/models/item/kelp_top.json | 18 -- .../blocks/{kelp.png => kelp_single.png} | Bin 13 files changed, 175 insertions(+), 60 deletions(-) create mode 100644 src/main/java/biomesoplenty/common/block/BlockSeaweed.java create mode 100644 src/main/resources/assets/biomesoplenty/blockstates/seaweed.json rename src/main/resources/assets/biomesoplenty/models/block/{kelp.json => kelp_single.json} (52%) delete mode 100644 src/main/resources/assets/biomesoplenty/models/item/kelp_bottom.json delete mode 100644 src/main/resources/assets/biomesoplenty/models/item/kelp_middle.json delete mode 100644 src/main/resources/assets/biomesoplenty/models/item/kelp_top.json rename src/main/resources/assets/biomesoplenty/textures/blocks/{kelp.png => kelp_single.png} (100%) diff --git a/src/main/java/biomesoplenty/api/block/BOPBlocks.java b/src/main/java/biomesoplenty/api/block/BOPBlocks.java index a252da949..9d1601925 100644 --- a/src/main/java/biomesoplenty/api/block/BOPBlocks.java +++ b/src/main/java/biomesoplenty/api/block/BOPBlocks.java @@ -18,6 +18,7 @@ public class BOPBlocks public static Block bamboo; public static Block bone_segment; public static Block coral; + public static Block seaweed; public static Block gem_block; public static Block gem_ore; public static Block hive; diff --git a/src/main/java/biomesoplenty/api/item/BOPItems.java b/src/main/java/biomesoplenty/api/item/BOPItems.java index 55f854fbf..e5314688e 100644 --- a/src/main/java/biomesoplenty/api/item/BOPItems.java +++ b/src/main/java/biomesoplenty/api/item/BOPItems.java @@ -116,8 +116,6 @@ public class BOPItems // TODO: public static Item ancientStaff; // TODO: public static Item bop_bucket; - // TODO: public static Item flower_band; - // TODO: public static Item flippers; } \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/block/BlockCoral.java b/src/main/java/biomesoplenty/common/block/BlockCoral.java index 79302e02f..bff6ff1ed 100644 --- a/src/main/java/biomesoplenty/common/block/BlockCoral.java +++ b/src/main/java/biomesoplenty/common/block/BlockCoral.java @@ -70,7 +70,7 @@ public class BlockCoral extends BlockDecoration // set some defaults this.setHardness(0.6F); this.setStepSound(Block.soundTypeSand); - this.setBlockBoundsByRadiusAndHeight(0.4F, 0.8F); + this.setBlockBoundsByRadiusAndHeight(0.4F, 0.8F); // TODO: account for offset this.setDefaultState( this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.PINK) ); } diff --git a/src/main/java/biomesoplenty/common/block/BlockSeaweed.java b/src/main/java/biomesoplenty/common/block/BlockSeaweed.java new file mode 100644 index 000000000..04e1cc2af --- /dev/null +++ b/src/main/java/biomesoplenty/common/block/BlockSeaweed.java @@ -0,0 +1,160 @@ +/******************************************************************************* + * 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 biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.api.block.IBOPBlock; +import biomesoplenty.common.item.ItemBOPBlock; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyEnum; +import net.minecraft.block.state.BlockState; +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemBlock; +import net.minecraft.util.BlockPos; +import net.minecraft.util.IStringSerializable; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +public class BlockSeaweed extends BlockDecoration implements IBOPBlock +{ + + // TODO: is it supposed to grow? + + public static enum SeaweedType implements IStringSerializable + { + KELP; + @Override + public String getName() + { + return this.name().toLowerCase(); + } + @Override + public String toString() + { + return this.getName(); + } + }; + + public static enum SeaweedPosition implements IStringSerializable + { + SINGLE, BOTTOM, MIDDLE, TOP; + @Override + public String getName() + { + return this.name().toLowerCase(); + } + @Override + public String toString() + { + return this.getName(); + } + } + + public static final PropertyEnum VARIANT = PropertyEnum.create("variant", SeaweedType.class); + public static final PropertyEnum POSITION = PropertyEnum.create("position", SeaweedPosition.class); + + @Override + protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { LEVEL, POSITION, VARIANT });} + + + // implement IBOPBlock + @Override + public Class getItemClass() { return ItemBOPBlock.class; } + @Override + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + @Override + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + @Override + public IProperty[] getNonRenderingProperties() { return new IProperty[] {LEVEL}; } + @Override + public String getStateName(IBlockState state) { + SeaweedType type = (SeaweedType)state.getValue(VARIANT); + return type.getName(); + } + + + public BlockSeaweed() + { + super(Material.water); + + // set some defaults + this.setStepSound(Block.soundTypeSand); + this.setDefaultState( this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(POSITION, SeaweedPosition.SINGLE).withProperty(VARIANT, SeaweedType.KELP) ); + } + + // examine neighbors to figure out the SeaweedPosition value + @Override + public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) + { + boolean seaweedAbove = (worldIn.getBlockState(pos.up()).getBlock() == this); + boolean seaweedBelow = (worldIn.getBlockState(pos.down()).getBlock() == this); + SeaweedPosition position; + if (seaweedAbove && seaweedBelow) {position = SeaweedPosition.MIDDLE;} + else if (seaweedAbove) {position = SeaweedPosition.BOTTOM;} + else if (seaweedBelow) {position = SeaweedPosition.TOP;} + else {position = SeaweedPosition.SINGLE;} + return state.withProperty(POSITION, position); + } + + // map from state to meta and vice verca - note the LEVEL and POSITION properties are ignored + @Override + public IBlockState getStateFromMeta(int meta) + { + return this.getDefaultState().withProperty(VARIANT, SeaweedType.values()[meta]); + } + @Override + public int getMetaFromState(IBlockState state) + { + return ((SeaweedType) state.getValue(VARIANT)).ordinal(); + } + + @Override + public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos) + { + this.setBlockBoundsByRadiusAndHeightWithXZOffset(0.4F, 0.8F, pos); + } + + + // require water or seaweed above and earth or seaweed below + @Override + public boolean canBlockStay(World world, BlockPos pos, IBlockState state) + { + + IBlockState stateAbove = world.getBlockState(pos.up()); + Block blockAbove = stateAbove.getBlock(); + IBlockState stateBelow = world.getBlockState(pos.down()); + Block blockBelow = stateBelow.getBlock(); + + boolean hasWaterAbove = (blockAbove == Blocks.water || blockAbove == Blocks.flowing_water); + boolean sameSeaweedAbove = ( (blockAbove == this) && ((SeaweedType)state.getValue(VARIANT) == (SeaweedType)stateAbove.getValue(VARIANT)) ); + boolean hasEarthBelow = (blockBelow == Blocks.dirt || blockBelow == BOPBlocks.dirt || blockBelow == BOPBlocks.mud || blockBelow == Blocks.sand || blockBelow == Blocks.sponge || blockBelow == Blocks.stone || blockBelow == Blocks.clay || blockBelow == Blocks.gravel); + boolean sameSeaweedBelow = ( (blockBelow == this) && ((SeaweedType)state.getValue(VARIANT) == (SeaweedType)stateBelow.getValue(VARIANT)) ); + + return (hasWaterAbove || sameSeaweedAbove) && (hasEarthBelow || sameSeaweedBelow); + } + + @Override + public int damageDropped(IBlockState state) + { + return this.getMetaFromState(state); + } + + @Override + public void onBlockDestroyedByPlayer(World world, BlockPos pos, IBlockState state) + { + world.setBlockState(pos, Blocks.water.getDefaultState() ); + } + + + +} \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/init/ModBlocks.java b/src/main/java/biomesoplenty/common/init/ModBlocks.java index f92072f40..c9310682c 100644 --- a/src/main/java/biomesoplenty/common/init/ModBlocks.java +++ b/src/main/java/biomesoplenty/common/init/ModBlocks.java @@ -53,6 +53,7 @@ public class ModBlocks bamboo = registerBlock( new BlockBamboo(), "bamboo" ); bone_segment = registerBlock( new BlockBones(), "bone_segment" ); coral = registerBlock( new BlockCoral(), "coral" ); + seaweed = registerBlock( new BlockSeaweed(), "seaweed" ); gem_block = registerBlock( new BlockGem(), "gem_block" ); gem_ore = registerBlock( new BlockGemOre(), "gem_ore" ); hive = registerBlock( new BlockHive(), "hive" ); diff --git a/src/main/java/biomesoplenty/common/init/ModCrafting.java b/src/main/java/biomesoplenty/common/init/ModCrafting.java index 1029af082..81e2d7057 100644 --- a/src/main/java/biomesoplenty/common/init/ModCrafting.java +++ b/src/main/java/biomesoplenty/common/init/ModCrafting.java @@ -192,7 +192,7 @@ public class ModCrafting GameRegistry.addShapedRecipe(new ItemStack(BOPBlocks.bamboo, 8), new Object [] {" #", "# ", '#', new ItemStack(BOPBlocks.bamboo_thatching)}); GameRegistry.addShapedRecipe(new ItemStack(BOPBlocks.bamboo, 8), new Object [] {"# ", " #", '#', new ItemStack(BOPBlocks.bamboo_thatching)}); GameRegistry.addShapedRecipe(new ItemStack(BOPItems.jar_empty, 3, 0), new Object[] {"# #", "# #", "###", '#', Blocks.glass}); - GameRegistry.addShapelessRecipe(new ItemStack(BOPItems.ambrosia), new Object[] {new ItemStack(BOPItems.pixie_dust), new ItemStack(Items.potionitem, 1, 0), BlockBOPFlower.paging.getVariantItem(BOPFlowers.MINERS_DELIGHT), /* TODO: add kelp new ItemStack(BOPCBlocks.coral1, 1, 11), */ BlockBOPPlant.paging.getVariantItem(BOPPlants.ROOT), new ItemStack(BOPItems.crystal_shard), new ItemStack(BOPItems.jar_filled, 1, ItemJarFilled.JarContents.HONEY.ordinal()), new ItemStack(BOPItems.berries), Items.sugar}); + GameRegistry.addShapelessRecipe(new ItemStack(BOPItems.ambrosia), new Object[] {new ItemStack(BOPItems.pixie_dust), new ItemStack(Items.potionitem, 1, 0), BlockBOPFlower.paging.getVariantItem(BOPFlowers.MINERS_DELIGHT), new ItemStack(BOPBlocks.seaweed, 1, BlockSeaweed.SeaweedType.KELP.ordinal()), BlockBOPPlant.paging.getVariantItem(BOPPlants.ROOT), new ItemStack(BOPItems.crystal_shard), new ItemStack(BOPItems.jar_filled, 1, ItemJarFilled.JarContents.HONEY.ordinal()), new ItemStack(BOPItems.berries), Items.sugar}); GameRegistry.addShapedRecipe(new ItemStack(BOPBlocks.flesh), new Object[] {"##", "##", '#', new ItemStack(BOPItems.fleshchunk)}); GameRegistry.addShapedRecipe(new ItemStack(Items.rotten_flesh), new Object[] {"FFF", "FPF", "FFF", 'F', new ItemStack(BOPItems.fleshchunk), 'P', new ItemStack(BOPItems.jar_filled, 1, ItemJarFilled.JarContents.POISON.ordinal())}); diff --git a/src/main/resources/assets/biomesoplenty/blockstates/seaweed.json b/src/main/resources/assets/biomesoplenty/blockstates/seaweed.json new file mode 100644 index 000000000..20c2af6e8 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/blockstates/seaweed.json @@ -0,0 +1,9 @@ +{ + "variants": { + "position=single,variant=kelp": { "model": "biomesoplenty:kelp_single" }, + "position=bottom,variant=kelp": { "model": "biomesoplenty:kelp_bottom" }, + "position=middle,variant=kelp": { "model": "biomesoplenty:kelp_middle" }, + "position=top,variant=kelp": { "model": "biomesoplenty:kelp_top" } + } +} + \ No newline at end of file diff --git a/src/main/resources/assets/biomesoplenty/models/block/kelp.json b/src/main/resources/assets/biomesoplenty/models/block/kelp_single.json similarity index 52% rename from src/main/resources/assets/biomesoplenty/models/block/kelp.json rename to src/main/resources/assets/biomesoplenty/models/block/kelp_single.json index 4007fe0d7..316487d40 100644 --- a/src/main/resources/assets/biomesoplenty/models/block/kelp.json +++ b/src/main/resources/assets/biomesoplenty/models/block/kelp_single.json @@ -1,6 +1,6 @@ { "parent": "block/cross", "textures": { - "cross": "biomesoplenty:blocks/kelp" + "cross": "biomesoplenty:blocks/kelp_single" } } diff --git a/src/main/resources/assets/biomesoplenty/models/item/kelp.json b/src/main/resources/assets/biomesoplenty/models/item/kelp.json index c12796e70..9f9eb337a 100644 --- a/src/main/resources/assets/biomesoplenty/models/item/kelp.json +++ b/src/main/resources/assets/biomesoplenty/models/item/kelp.json @@ -1,7 +1,7 @@ { "parent": "builtin/generated", "textures": { - "layer0": "biomesoplenty:blocks/kelp" + "layer0": "biomesoplenty:blocks/kelp_middle" }, "display": { "thirdperson": { diff --git a/src/main/resources/assets/biomesoplenty/models/item/kelp_bottom.json b/src/main/resources/assets/biomesoplenty/models/item/kelp_bottom.json deleted file mode 100644 index 78a721cb4..000000000 --- a/src/main/resources/assets/biomesoplenty/models/item/kelp_bottom.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "parent": "builtin/generated", - "textures": { - "layer0": "biomesoplenty:blocks/kelp_bottom" - }, - "display": { - "thirdperson": { - "rotation": [ -90, 0, 0 ], - "translation": [ 0, 1, -3 ], - "scale": [ 0.55, 0.55, 0.55 ] - }, - "firstperson": { - "rotation": [ 0, -135, 25 ], - "translation": [ 0, 4, 2 ], - "scale": [ 1.7, 1.7, 1.7 ] - } - } -} diff --git a/src/main/resources/assets/biomesoplenty/models/item/kelp_middle.json b/src/main/resources/assets/biomesoplenty/models/item/kelp_middle.json deleted file mode 100644 index 9f9eb337a..000000000 --- a/src/main/resources/assets/biomesoplenty/models/item/kelp_middle.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "parent": "builtin/generated", - "textures": { - "layer0": "biomesoplenty:blocks/kelp_middle" - }, - "display": { - "thirdperson": { - "rotation": [ -90, 0, 0 ], - "translation": [ 0, 1, -3 ], - "scale": [ 0.55, 0.55, 0.55 ] - }, - "firstperson": { - "rotation": [ 0, -135, 25 ], - "translation": [ 0, 4, 2 ], - "scale": [ 1.7, 1.7, 1.7 ] - } - } -} diff --git a/src/main/resources/assets/biomesoplenty/models/item/kelp_top.json b/src/main/resources/assets/biomesoplenty/models/item/kelp_top.json deleted file mode 100644 index fb7767031..000000000 --- a/src/main/resources/assets/biomesoplenty/models/item/kelp_top.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "parent": "builtin/generated", - "textures": { - "layer0": "biomesoplenty:blocks/kelp_top" - }, - "display": { - "thirdperson": { - "rotation": [ -90, 0, 0 ], - "translation": [ 0, 1, -3 ], - "scale": [ 0.55, 0.55, 0.55 ] - }, - "firstperson": { - "rotation": [ 0, -135, 25 ], - "translation": [ 0, 4, 2 ], - "scale": [ 1.7, 1.7, 1.7 ] - } - } -} diff --git a/src/main/resources/assets/biomesoplenty/textures/blocks/kelp.png b/src/main/resources/assets/biomesoplenty/textures/blocks/kelp_single.png similarity index 100% rename from src/main/resources/assets/biomesoplenty/textures/blocks/kelp.png rename to src/main/resources/assets/biomesoplenty/textures/blocks/kelp_single.png