From c2b80ce5fd042e3c946914858e5d669591add24a Mon Sep 17 00:00:00 2001 From: Cheeserolls Date: Fri, 3 Apr 2015 18:33:58 +0100 Subject: [PATCH 1/4] Add double-height decorations (flax) --- .../biomesoplenty/api/block/BOPBlocks.java | 2 + .../common/block/BlockDecoration.java | 9 +- .../common/block/BlockDoubleDecoration.java | 229 ++++++++++++++++++ .../common/block/BlockDoubleFoliage.java | 178 ++++++++++++++ .../biomesoplenty/common/init/ModBlocks.java | 3 +- .../blockstates/double_foliage.json | 6 + .../models/block/flax_lower.json | 6 + .../models/block/flax_upper.json | 8 + .../biomesoplenty/models/item/flax.json | 18 ++ .../textures/blocks/flax_flowers.png | Bin 0 -> 567 bytes .../textures/blocks/flax_lower.png | Bin 0 -> 596 bytes .../textures/blocks/flax_upper.png | Bin 0 -> 524 bytes .../biomesoplenty/textures/items/flax.png | Bin 0 -> 15571 bytes 13 files changed, 453 insertions(+), 6 deletions(-) create mode 100644 src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java create mode 100644 src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java create mode 100644 src/main/resources/assets/biomesoplenty/blockstates/double_foliage.json create mode 100644 src/main/resources/assets/biomesoplenty/models/block/flax_lower.json create mode 100644 src/main/resources/assets/biomesoplenty/models/block/flax_upper.json create mode 100644 src/main/resources/assets/biomesoplenty/models/item/flax.json create mode 100644 src/main/resources/assets/biomesoplenty/textures/blocks/flax_flowers.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/blocks/flax_lower.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/blocks/flax_upper.png create mode 100644 src/main/resources/assets/biomesoplenty/textures/items/flax.png diff --git a/src/main/java/biomesoplenty/api/block/BOPBlocks.java b/src/main/java/biomesoplenty/api/block/BOPBlocks.java index e0b56e4cc..749cf1b74 100644 --- a/src/main/java/biomesoplenty/api/block/BOPBlocks.java +++ b/src/main/java/biomesoplenty/api/block/BOPBlocks.java @@ -117,6 +117,8 @@ public class BOPBlocks public static Block pine_sapling; public static Block mahogany_sapling; + public static Block double_foliage; + } diff --git a/src/main/java/biomesoplenty/common/block/BlockDecoration.java b/src/main/java/biomesoplenty/common/block/BlockDecoration.java index 0419f2046..3267713a5 100644 --- a/src/main/java/biomesoplenty/common/block/BlockDecoration.java +++ b/src/main/java/biomesoplenty/common/block/BlockDecoration.java @@ -55,21 +55,20 @@ public class BlockDecoration extends Block implements IBOPBlock } // utility function for setting the block bounds - typically decoration blocks are smaller than full block size - public BlockDecoration setBlockBoundsByRadiusAndHeight(float radius, float height) + public void setBlockBoundsByRadiusAndHeight(float radius, float height) { - return this.setBlockBoundsByRadiusAndHeight(radius,height,false); + this.setBlockBoundsByRadiusAndHeight(radius,height,false); } - public BlockDecoration setBlockBoundsByRadiusAndHeight(float radius, float height, boolean fromTop) + public void setBlockBoundsByRadiusAndHeight(float radius, float height, boolean fromTop) { this.setBlockBounds(0.5F - radius, (fromTop ? 1.0F - height : 0.0F), 0.5F - radius, 0.5F + radius, (fromTop ? 1.0F : height), 0.5F + radius); - return this; } // add a canBlockStay() check before placing this block @Override public boolean canReplace(World world, BlockPos pos, EnumFacing side, ItemStack stack) { - return super.canReplace(world, pos, side, stack) && this.canBlockStay(world, pos, this.getStateFromMeta(stack.getMetadata())); + return world.getBlockState(pos).getBlock().isReplaceable(world, pos) && this.canBlockStay(world, pos, this.getStateFromMeta(stack.getMetadata())); } // check this block is still able to remain after neighbor change diff --git a/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java b/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java new file mode 100644 index 000000000..78ee2035f --- /dev/null +++ b/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java @@ -0,0 +1,229 @@ +/******************************************************************************* + * 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 java.util.List; + +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.entity.EntityLivingBase; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.IStringSerializable; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +class BlockDoubleDecoration extends BlockDecoration { + + // add half property + public static enum Half implements IStringSerializable {LOWER, UPPER; public String getName() {return this.name().toLowerCase();}}; + public static final PropertyEnum HALF = PropertyEnum.create("half", Half.class); + protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { HALF });} + + public float radius; + public float height; + public boolean fromTop; + + public BlockDoubleDecoration() + { + this(Material.plants); + } + public BlockDoubleDecoration(Material material) + { + super(material); + this.radius = 0.5F; + this.height = 1.0F; + this.fromTop = false; + this.setDefaultState(this.blockState.getBaseState().withProperty(HALF, Half.LOWER)); + } + + // map from state to meta and vice verca + @Override + public IBlockState getStateFromMeta(int meta) + { + return this.getDefaultState().withProperty(HALF, Half.values()[meta]); + } + @Override + public int getMetaFromState(IBlockState state) + { + return ((Half) state.getValue(HALF)).ordinal(); + } + + + + + // utility functions + public BlockPos getLowerPos(IBlockAccess world, BlockPos pos) + { + IBlockState state = world.getBlockState(pos); + if (state.getBlock() != this) {return pos;} + return world.getBlockState(pos).getValue(HALF) == Half.UPPER ? pos.down() : pos; + } + public BlockPos getUpperPos(IBlockAccess world, BlockPos pos) + { + IBlockState state = world.getBlockState(pos); + if (state.getBlock() != this) {return pos.up();} + return world.getBlockState(pos).getValue(HALF) == Half.UPPER ? pos : pos.up(); + } + public IBlockState getLowerState(IBlockAccess world, BlockPos pos) + { + return world.getBlockState(this.getLowerPos(world, pos)); + } + public IBlockState getUpperState(IBlockAccess world, BlockPos pos) + { + return world.getBlockState(this.getUpperPos(world, pos)); + } + public boolean isValidDoubleBlock(IBlockAccess world, BlockPos pos) + { + IBlockState lowerState = this.getLowerState(world, pos); + IBlockState upperState = this.getUpperState(world, pos); + return lowerState.getBlock() == this && lowerState.getValue(HALF) == Half.LOWER && upperState.getBlock() == this && upperState.getValue(HALF) == Half.UPPER; + } + + + + // drop block as item if it cannot remain here - return whether on not it could stay + @Override + protected boolean checkAndDropBlock(World worldIn, BlockPos pos, IBlockState state) + { + if (this.isValidDoubleBlock(worldIn, pos) && this.canBlockStay(worldIn, this.getLowerPos(worldIn, pos), state)) + { + return true; + } + else + { + this.dropBlockAsItem(worldIn, pos, state, 0); + worldIn.setBlockState(pos, Blocks.air.getDefaultState(), 3); + return false; + } + } + + // This DoubleDecoration can replace the block at pos if both the block and the one above it are replaceable and the environment is suitable (canBlockStay) + @Override + public boolean canReplace(World world, BlockPos pos, EnumFacing side, ItemStack stack) + { + return world.getBlockState(pos).getBlock().isReplaceable(world, pos) && world.getBlockState(pos.up()).getBlock().isReplaceable(world, pos.up()) && this.canBlockStay(world, pos, this.getStateFromMeta(stack.getMetadata())); + } + + // Called by ItemBlock before the block is placed - the placed block must always be Half.LOWER + public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) + { + return this.getStateFromMeta(meta).withProperty(HALF, Half.LOWER); + } + + // Called by ItemBlock after the (lower) block has been placed + // Use it to add the top half of the block + public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { + worldIn.setBlockState(pos.up(), this.getStateFromMeta(stack.getMetadata()).withProperty(HALF, Half.UPPER), 3); + } + + @Override + // child classes should put code in here which checks the ground is ok + public boolean canBlockStay(World world, BlockPos lowerPos, IBlockState state) + { + return true; + } + + + + + + @Override + // utility function for setting the block bounds - + public void setBlockBoundsByRadiusAndHeight(float radius, float height, boolean fromTop) + { + this.radius = radius; + this.height = height; + this.fromTop = fromTop; + } + @Override + public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) + { + IBlockState state = worldIn.getBlockState(pos); + switch ((Half) state.getValue(HALF)) + { + case LOWER: + super.setBlockBoundsByRadiusAndHeight(this.radius, this.fromTop ? this.height : 1.0F, this.fromTop); + break; + case UPPER: + super.setBlockBoundsByRadiusAndHeight(this.radius, this.fromTop ? 1.0F : this.height, this.fromTop); + break; + } + } + + + // handle drops from UPPER and LOWER separately + @Override + public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) + { + if (state.getValue(HALF) == Half.UPPER) + { + return this.getUpperDrops(world, this.getUpperPos(world, pos), this.getUpperState(world, pos), fortune); + } + else + { + return this.getLowerDrops(world, this.getLowerPos(world, pos), this.getLowerState(world, pos), fortune); + } + } + + // default behavior is that UPPER drops nothing, and LOWER drops the default item + public List getUpperDrops(IBlockAccess world, BlockPos upperPos, IBlockState upperState, int fortune) + { + return new java.util.ArrayList(); + } + public List getLowerDrops(IBlockAccess world, BlockPos lowerPos, IBlockState lowerState, int fortune) + { + return super.getDrops(world, lowerPos, lowerState, fortune); + } + + // if a child class chooses to implement IShearable make shearing the upper or lower block act as shearing both + public List onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) { + + List drops = new java.util.ArrayList(); + drops.addAll( this.getUpperShearDrops(item, world, this.getUpperPos(world, pos), this.getUpperState(world, pos), fortune) ); + drops.addAll( this.getLowerShearDrops(item, world, this.getLowerPos(world, pos), this.getLowerState(world, pos), fortune) ); + + // whichever half was sheared, turn the other to air (to prevent it dropping an additional item when it pops) + if (world instanceof World) + { + ((World)world).setBlockToAir( pos.add(0, world.getBlockState(pos).getValue(HALF) == Half.UPPER ? -1 : 1, 0) ); + } + + return drops; + } + + // default behavior is that UPPER drops nothing, and LOWER drops the default item + public List getUpperShearDrops(ItemStack item, IBlockAccess world, BlockPos upperPos, IBlockState upperState, int fortune) { + return new java.util.ArrayList(); + } + public List getLowerShearDrops(ItemStack item, IBlockAccess world, BlockPos lowerPos, IBlockState lowerState, int fortune) { + return super.getDrops(world, lowerPos, lowerState, fortune); + } + + + + // discard the HALF info in the items dropped - make them all Half.LOWER so that they can stack - keep other state info such as VARIANT + @Override + public int damageDropped(IBlockState state) + { + return this.getMetaFromState( state.withProperty(HALF, Half.LOWER) ); + } + + + + + + + +} \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java b/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java new file mode 100644 index 000000000..eb7095427 --- /dev/null +++ b/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java @@ -0,0 +1,178 @@ +/******************************************************************************* + * 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 java.util.List; +import java.util.Random; + +import biomesoplenty.api.block.BOPBlocks; +import net.minecraft.block.Block; +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.ItemStack; +import net.minecraft.util.BlockPos; +import net.minecraft.util.IStringSerializable; +import net.minecraft.world.ColorizerGrass; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeColorHelper; +import net.minecraftforge.common.ForgeHooks; +import net.minecraftforge.common.IShearable; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public class BlockDoubleFoliage extends BlockDoubleDecoration implements IShearable +{ + + // add properties (note we inherit HALF from BlockDoubleDecoration) + public static enum FoliageType implements IStringSerializable {FLAX; public String getName() {return this.name().toLowerCase();}}; + public static final PropertyEnum VARIANT = PropertyEnum.create("variant", FoliageType.class); + @Override + protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { HALF, VARIANT });} + + public BlockDoubleFoliage() + { + super(); + + // define named states + for(FoliageType foliageType : FoliageType.values()) + { + this.namedStates.put(foliageType.getName(), this.blockState.getBaseState().withProperty(HALF, Half.LOWER) .withProperty(VARIANT, foliageType)); + } + this.setDefaultState(this.getNamedState("flax")); + } + + // map from state to meta and vice verca - use highest bit for Half, and lower bits for variant + @Override + public IBlockState getStateFromMeta(int meta) + { + return this.getDefaultState().withProperty(HALF, Half.values()[meta >> 3]).withProperty(VARIANT, FoliageType.values()[meta & 7]); + } + @Override + public int getMetaFromState(IBlockState state) + { + return ((Half) state.getValue(HALF)).ordinal() * 8 + ((FoliageType) state.getValue(VARIANT)).ordinal(); + } + + + + // TODO: comment these + @Override + @SideOnly(Side.CLIENT) + public int getBlockColor() + { + return ColorizerGrass.getGrassColor(0.5D, 1.0D); + } + + @Override + @SideOnly(Side.CLIENT) + public int getRenderColor(IBlockState state) + { + return this.getBlockColor(); + } + + @Override + @SideOnly(Side.CLIENT) + public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) + { + switch ((FoliageType) worldIn.getBlockState(pos).getValue(VARIANT)) + { + default: + return BiomeColorHelper.getGrassColorAtPos(worldIn, pos); + } + } + + + // different variants have different sizes + @Override + public void setBlockBoundsBasedOnState(IBlockAccess worldIn, BlockPos pos) + { + switch ((FoliageType) worldIn.getBlockState(pos).getValue(VARIANT)) + { + default: + this.setBlockBoundsByRadiusAndHeight(0.4F, 0.8F); + break; + } + } + + + + @Override + public boolean canBlockStay(World world, BlockPos lowerPos, IBlockState state) + { + IBlockState groundState = world.getBlockState(lowerPos.down()); + Block groundBlock = groundState.getBlock(); + boolean onFertile = (groundBlock == Blocks.dirt || groundBlock == BOPBlocks.dirt || groundBlock == Blocks.mycelium || groundBlock == Blocks.grass); + if (groundBlock instanceof BlockBOPGrass) + { + switch ((BlockBOPGrass.BOPGrassType) groundState.getValue(BlockBOPGrass.VARIANT)) + { + case SPECTRAL_MOSS: case SMOLDERING: + break; + case OVERGROWN_NETHERRACK: case LOAMY: case SANDY: case SILTY: case ORIGIN: default: + onFertile = true; + break; + } + } + return onFertile; + + } + + + // get the items dropped when you bash the bush + @Override + public List getLowerDrops(IBlockAccess world, BlockPos lowerPos, IBlockState lowerState, int fortune) + { + Random rand = world instanceof World ? ((World)world).rand : RANDOM; + + // start with an empty stack + List ret = new java.util.ArrayList(); + + // add items based on the VARIANT - default is to return nothing (require shears to collect the block) + switch ((FoliageType) lowerState.getValue(VARIANT)) + { + case FLAX: + if (rand.nextInt(8) == 0) + { + // 1 in 8 chance of getting a seed from this grass + ret.add(ForgeHooks.getGrassSeed(rand)); + } + + default: + break; + } + return ret; + } + + + @Override + public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos) { + return true; + } + + @Override + public List getLowerShearDrops(ItemStack item, IBlockAccess world, BlockPos lowerPos, IBlockState lowerState, int fortune) { + // start with an empty stack + List ret = new java.util.ArrayList(); + + // add items based on the VARIANT + switch ((FoliageType) lowerState.getValue(VARIANT)) + { + default: + // default is to get the (lower) block unaltered + ret.add(new ItemStack(this, 1, this.getMetaFromState(lowerState.withProperty(HALF, Half.LOWER) ))); + } + return ret; + } + + +} \ 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 bb1a4ddd2..f96d0c939 100644 --- a/src/main/java/biomesoplenty/common/init/ModBlocks.java +++ b/src/main/java/biomesoplenty/common/init/ModBlocks.java @@ -46,6 +46,7 @@ import biomesoplenty.common.block.BlockBamboo; import biomesoplenty.common.block.BlockBones; import biomesoplenty.common.block.BlockCoral; import biomesoplenty.common.block.BlockCrystal; +import biomesoplenty.common.block.BlockDoubleFoliage; import biomesoplenty.common.block.BlockFoliage; import biomesoplenty.common.block.BlockFruit; import biomesoplenty.common.block.BlockGem; @@ -231,7 +232,7 @@ public class ModBlocks dark_leaves = registerBlock( new BlockBOPLeaves( new ItemStack(dark_sapling, 1, 0), new ItemStack(Items.apple, 1, 0), 20, true ), "dark_leaves" ); bamboo_leaves = registerBlock( new BlockBOPLeaves( new ItemStack(bamboo_sapling, 1, 0), new ItemStack(Items.apple, 1, 0), 20, true ), "bamboo_leaves" ); - + double_foliage = registerBlock( new BlockDoubleFoliage(), "double_foliage" ); } diff --git a/src/main/resources/assets/biomesoplenty/blockstates/double_foliage.json b/src/main/resources/assets/biomesoplenty/blockstates/double_foliage.json new file mode 100644 index 000000000..3e645d109 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/blockstates/double_foliage.json @@ -0,0 +1,6 @@ +{ + "variants": { + "half=upper,variant=flax": { "model": "biomesoplenty:flax_upper" }, + "half=lower,variant=flax": { "model": "biomesoplenty:flax_lower" } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/biomesoplenty/models/block/flax_lower.json b/src/main/resources/assets/biomesoplenty/models/block/flax_lower.json new file mode 100644 index 000000000..3d976e09c --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/block/flax_lower.json @@ -0,0 +1,6 @@ +{ + "parent": "block/tallgrass", + "textures": { + "cross": "biomesoplenty:blocks/flax_lower" + } +} diff --git a/src/main/resources/assets/biomesoplenty/models/block/flax_upper.json b/src/main/resources/assets/biomesoplenty/models/block/flax_upper.json new file mode 100644 index 000000000..dfab1d144 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/block/flax_upper.json @@ -0,0 +1,8 @@ +{ + "parent": "biomesoplenty:block/cross_with_overlay", + "textures": { + "colored": "biomesoplenty:blocks/flax_flowers", + "greyscale": "biomesoplenty:blocks/flax_upper", + "particle": "biomesoplenty:blocks/flax_upper" + } +} diff --git a/src/main/resources/assets/biomesoplenty/models/item/flax.json b/src/main/resources/assets/biomesoplenty/models/item/flax.json new file mode 100644 index 000000000..020c4d495 --- /dev/null +++ b/src/main/resources/assets/biomesoplenty/models/item/flax.json @@ -0,0 +1,18 @@ +{ + "parent": "builtin/generated", + "textures": { + "layer0": "biomesoplenty:items/flax" + }, + "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/flax_flowers.png b/src/main/resources/assets/biomesoplenty/textures/blocks/flax_flowers.png new file mode 100644 index 0000000000000000000000000000000000000000..f136990328c59774a21d34d94d2b2ec9e1d4a690 GIT binary patch literal 567 zcmV-70?7S|P)N2bZe?^J zG%heMGmPe!Pyhe{wMj%lR5(w4l1Xn9K@f%e4|6~WK`bGJL}Z*`Cnka*C1hbcz=b<^ zlzXJyxLL8hFEif8%VWMW)tLy1!|U!URlR=ox`QM`qtOV{>D11P#UiZN>#$m_4CFSO zO{^{AUO;1(W!BX1_hY`->xJcVX`sf*sEb98{d0-J!C(+(vso;DT>I1GoM zr8G^WPmo6fW@L9FP^t~3-v@fQ+swl|l@M?dYKcRq(+RbY+qp?#3`TN(`93oRoPm#Y z@JYJ;`9SPpr#g^sUI`MMM<$Z-pw(*GyiQR6BJtduPk-cVzT1t=N5BXuDZaV?gXc#R zGx*7V&uSgE(BM+J`Q0~((TYUm_s%3Ibl5T)jbh?iJ<;ZRSFbPf=x@%6*m1s?j{$Ha zd2i2kyItEc3>BVt{F88}0k>gd z$Pxrd<$Dst%u{;9|6p_boB+x0g~LBqyWNgCE=bcf`~e;E_^>?(v_1d;002ovPDHLk FV1k^s{*3?t literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/biomesoplenty/textures/blocks/flax_lower.png b/src/main/resources/assets/biomesoplenty/textures/blocks/flax_lower.png new file mode 100644 index 0000000000000000000000000000000000000000..c7417022ec3c8de2bd56c5657fe8a43551969492 GIT binary patch literal 596 zcmV-a0;~OrP)N2bZe?^J zG%heMGmPe!Pyhe{(n&-?R5(vnQ)i2^K@5C63zkpf@3SBluotjk?+q*V@?$xc>FQLEMDV-oB2n!eBHqdyvrOuX4_()M^f^od+9C(Gs19C|*Vv=@to z*zI;}yWL8=-6jVcd$-#aQvnzbhcX_I85|4-(&=y^T2`&vO~ua74l zj|;Ab-RX3G3kVd8MIJx`ybTBnwZY+P`~BXC_NVf0w-cAkWtB=LL!!d(JK_T!BT%o` z1)_6OXajRcc03Nh-%sxGc<^b%#)1aeF(rtsycGxp*hMOpB8kTYwILE-A~=jp<5&<^ zZT@7lSt@=$pQTVJNGKE%a9*#Mu}CB$+5yhRVlj@@B*2PBqo!s2wIL#Gx7$s9!r?Hd i6buH*qoYhFBmV&4jZOV^#Wy1W0000N2bZe?^J zG%heMGmPe!Pyhe{ib+I4R5(w4Q^~3VF%XRV?#aKJU+|)+AmXkAinv_VgNh5H;?b-B z*pDiw;{@Rq45{=|>F#8VBAreL%tbUB4cHfI%jI%h9mHa>fEg2y$89ipCX*poWV6{1 z(V#>kVIq+TxdJwzSS&J5{Z1^@!+`U0xrkPyBL5Ohnt7&1OtoEEYea4lv>Mdd(o;_odV6*b^(2icF_d z?w`-6wf~^o?b3HXA2tKA(%;9IvNVt1)0W9CCfX-)1}>lcVI-YUNba zXf(cp`T|Fzk)Q=6>(}e`7>EfqTWPgga=+gxg0j&&eBd~!TrSJ;c%<$1 zdPzQ?H)gln(V+cne>(lg<3T}vwiqU2Q>oPVJ)l2L03cGWR_$JW{eE9iMYGwoKB8W) z%k6ff5vO~eC*jFM5Lc@$fw$Xj;hR7iAj{>FPW=PJg9G;ay(9Qx#{2=d=(Y2n*@lh) O0000AtX$a7Dz~4nn0%pLTH0Y+v$v%kOWVLBos(O83#j4_as@8 z*Yb|rrqh2`Gy3uN?f1RC&%U?1e{Ms~!UYBS-^-^cs=!@UQ47B(sqeho;pe?qZ}IT! z+u^FEGDS`7Ro^+=N+wRGsM3D1zCmg5{D2drppN%SO+Xh5hT&|Avd@i$d7%X;bQAE4 zA&2J5;UgMa^g1+4%pScb>;lbVRYwHWbu6qGI$DHMuV$_@-yY*&fFMwKIu;CsWG?2= z#N%@Cw>r#d==c<+#i1!z6VeTy8rmgA0BzQpwSwNj($-QPYc^Z0hB>rB&zcxL%dkc* zTgsVCoL)~SUm9mV{AG`LeOztD{A4<4IW*0R66P4Dt*uShX4FX$Kf{)mmNI$+V=!pp z46WQAQuvrQB;S_^G90G@$U;O6E20#l)wq0<6jdA=jhZO+N?unmoJtgulk6ZxCdP*u zR;OpOiM&Ee6OKj#@uhhM1_VG5gcKR-*sQv6v!qCJvouD^lzYs?a8Ep*RPLJ`zK-kcGURL_`e2QhIBnd(W%;-!$- zAv?TQ&J_W?B1P&YDd0?0SS1<`O*%%Q_JwV&_8LD`haqf_;@F4-X zE1YmZCyHLK2^einR+~jDu!5j9HJJo0Z?hV-7T#tt`OLrzY-}8W$CD`^6}mzaqH3!o zLwjLptKMfYTWvnA!6%rtCf3@dsONq_{2%Os%&-3M_F#NX^q=iP)&uGPxe@6i7Ml5xA9$V2aQzMsjBoD} zJ36wlhR=i1jc8Z@ia6NBu&VfY^T2ay)L1%mVt#|#jDcu;eyK$dUks~$CZ(BfRJs%| z&2*#Ev~qDsRGfxnHe@(MrT$+g&ht8WYX_Vbv)O32Gw3j?s1aiz&`=@5gI89M6V{T{ zppLA7Xk!t5?pvbh?n3(fZ$Dn z3(p7f5?lxnyh(83`5<0`3ju;R2`)Sz#7l4?K=3BPh3A8K2`&T(-Xys2d=M|eg#f{u z1Q(tU;w88cAb6AD!t+7A1Q!AXZxUR1K8Tm#LV(~+f(y?F@e*7J5WGon;rSq5f(rqH zHwi90AH+*=AwcjZ!G-68cnK~92;L;P@O%(2!G!?9n*!X`!mtLs1>Y6xI0{MP0uIzdxg>sGg!eZ=@)02SpW1TOK|(pQ64c zyDQ4;WBo5|IaPhvqM~DWyfJj4=*^kC>0{fMY+j#p+wyg1X7v`%e|52tcW2q_wDYbH zJLh-@&N*78^Y2aFJZYNiX~WbVJy+#Lxvua9&*k$sF28j|UifxN*{y?vrsL-xyU>1M z&O^tV7L`xR>-*UmV6j+U@9CLcwrSI*M{>3ve6s7b{)^u}&dz`BVt(Ji6OE6a`YJMU z9sML&+TY*5C3v>Dtm>M*TDX!^W?p(gUYhcCXWiPbs-r2Wj!1k5Bdh5aB=~{*i#;R_(0W z59jFL|JrnOsAI#IV&A0`-@REh-8!MArR9OU^YrUuXwc^>?$Z@EkN?d6lx=AHfI<@`CP-v4y@MDJn Date: Fri, 3 Apr 2015 18:47:55 +0100 Subject: [PATCH 2/4] Fix item rendering for blocks with a tinted model but non-tinted item (flax and berry_bush) --- .../java/biomesoplenty/api/block/IBOPBlock.java | 1 + .../biomesoplenty/common/block/BlockBOPDirt.java | 2 ++ .../biomesoplenty/common/block/BlockBOPDoor.java | 2 ++ .../biomesoplenty/common/block/BlockBOPFence.java | 2 ++ .../common/block/BlockBOPFenceGate.java | 2 ++ .../common/block/BlockBOPGeneric.java | 2 ++ .../biomesoplenty/common/block/BlockBOPGrass.java | 2 ++ .../biomesoplenty/common/block/BlockBOPLeaves.java | 2 ++ .../common/block/BlockBOPLilypad.java | 2 ++ .../biomesoplenty/common/block/BlockBOPLog.java | 2 ++ .../biomesoplenty/common/block/BlockBOPStairs.java | 2 ++ .../biomesoplenty/common/block/BlockBOPStone.java | 2 ++ .../biomesoplenty/common/block/BlockBOPVine.java | 2 ++ .../biomesoplenty/common/block/BlockBones.java | 1 + .../biomesoplenty/common/block/BlockCrystal.java | 2 ++ .../common/block/BlockDecoration.java | 2 ++ .../common/block/BlockDoubleFoliage.java | 14 ++++++++++++++ .../biomesoplenty/common/block/BlockFlesh.java | 2 ++ .../biomesoplenty/common/block/BlockFoliage.java | 14 ++++++++++++++ .../java/biomesoplenty/common/block/BlockGem.java | 2 ++ .../biomesoplenty/common/block/BlockGemOre.java | 2 ++ .../java/biomesoplenty/common/block/BlockHive.java | 2 ++ .../java/biomesoplenty/common/block/BlockMud.java | 2 ++ .../biomesoplenty/common/block/BlockTurnip.java | 2 ++ .../biomesoplenty/common/item/ItemBOPBlock.java | 7 ++++--- 25 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/main/java/biomesoplenty/api/block/IBOPBlock.java b/src/main/java/biomesoplenty/api/block/IBOPBlock.java index 89b9bf6f2..923914d2f 100644 --- a/src/main/java/biomesoplenty/api/block/IBOPBlock.java +++ b/src/main/java/biomesoplenty/api/block/IBOPBlock.java @@ -18,5 +18,6 @@ public interface IBOPBlock { public Map getNamedStates(); public IBlockState getNamedState(String name); public Class getItemClass(); + public int getItemRenderColor(IBlockState state, int tintIndex); } \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPDirt.java b/src/main/java/biomesoplenty/common/block/BlockBOPDirt.java index a013eb376..6884220bb 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPDirt.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPDirt.java @@ -43,6 +43,8 @@ public class BlockBOPDirt extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPDoor.java b/src/main/java/biomesoplenty/common/block/BlockBOPDoor.java index 386ee0fc4..bf5f50db3 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPDoor.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPDoor.java @@ -29,6 +29,8 @@ public class BlockBOPDoor extends BlockDoor implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return null;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + private Item doorItem; diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPFence.java b/src/main/java/biomesoplenty/common/block/BlockBOPFence.java index bebe470dc..403572392 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPFence.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPFence.java @@ -25,6 +25,8 @@ public class BlockBOPFence extends BlockFence implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockBOPFence() { diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPFenceGate.java b/src/main/java/biomesoplenty/common/block/BlockBOPFenceGate.java index 7390eab47..28a4efb70 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPFenceGate.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPFenceGate.java @@ -28,6 +28,8 @@ public class BlockBOPFenceGate extends BlockFenceGate implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockBOPFenceGate() { diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPGeneric.java b/src/main/java/biomesoplenty/common/block/BlockBOPGeneric.java index e1b014a4f..f6512f1a1 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPGeneric.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPGeneric.java @@ -26,6 +26,8 @@ public class BlockBOPGeneric extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockBOPGeneric() { // use rock as default material diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPGrass.java b/src/main/java/biomesoplenty/common/block/BlockBOPGrass.java index af6ae067d..0b286d846 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPGrass.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPGrass.java @@ -54,6 +54,8 @@ public class BlockBOPGrass extends BlockGrass implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockBOPGrass() diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java b/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java index 926e332d6..7ed6c4639 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java @@ -43,6 +43,8 @@ public class BlockBOPLeaves extends BlockLeaves implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + private ItemStack sapling; private ItemStack fruit; diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPLilypad.java b/src/main/java/biomesoplenty/common/block/BlockBOPLilypad.java index 2caae873b..f82c182d5 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPLilypad.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPLilypad.java @@ -37,6 +37,8 @@ public class BlockBOPLilypad extends BlockLilyPad implements IBOPBlock public IBlockState getNamedState(String name) {return this.namedStates.get(name);} // need to use a custom item class because of the unique way lilies are placed public Class getItemClass() {return ItemBOPLilypad.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockBOPLilypad() diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPLog.java b/src/main/java/biomesoplenty/common/block/BlockBOPLog.java index a408b5985..c28a873db 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPLog.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPLog.java @@ -31,6 +31,8 @@ public class BlockBOPLog extends BlockLog implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockBOPLog() { diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPStairs.java b/src/main/java/biomesoplenty/common/block/BlockBOPStairs.java index 7c8a3f494..9e61babf4 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPStairs.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPStairs.java @@ -25,6 +25,8 @@ public class BlockBOPStairs extends BlockStairs implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockBOPStairs(IBlockState modelState) { diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPStone.java b/src/main/java/biomesoplenty/common/block/BlockBOPStone.java index 443b81ef8..615e60ba9 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPStone.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPStone.java @@ -42,6 +42,8 @@ public class BlockBOPStone extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockBOPStone() { diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPVine.java b/src/main/java/biomesoplenty/common/block/BlockBOPVine.java index fd1779047..3a7601d95 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPVine.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPVine.java @@ -28,6 +28,8 @@ public class BlockBOPVine extends BlockVine implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + // if set to true, (the default), use BlockVine getBlockColor(), getRenderColor() and colorMultiplier() functions to color the texture based on biome // if set to false, use 0xFFFFFF for all the color functions so that the texture is used as it is diff --git a/src/main/java/biomesoplenty/common/block/BlockBones.java b/src/main/java/biomesoplenty/common/block/BlockBones.java index 5f33ce8b2..22e38b039 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBones.java +++ b/src/main/java/biomesoplenty/common/block/BlockBones.java @@ -45,6 +45,7 @@ public class BlockBones extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} public BlockBones() diff --git a/src/main/java/biomesoplenty/common/block/BlockCrystal.java b/src/main/java/biomesoplenty/common/block/BlockCrystal.java index 0f6369365..25a717018 100644 --- a/src/main/java/biomesoplenty/common/block/BlockCrystal.java +++ b/src/main/java/biomesoplenty/common/block/BlockCrystal.java @@ -29,6 +29,8 @@ public class BlockCrystal extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockCrystal() { super(Material.glass); diff --git a/src/main/java/biomesoplenty/common/block/BlockDecoration.java b/src/main/java/biomesoplenty/common/block/BlockDecoration.java index 3267713a5..c4d821a64 100644 --- a/src/main/java/biomesoplenty/common/block/BlockDecoration.java +++ b/src/main/java/biomesoplenty/common/block/BlockDecoration.java @@ -36,6 +36,8 @@ public class BlockDecoration extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + // constructor public BlockDecoration() { diff --git a/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java b/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java index eb7095427..8e058ee8b 100644 --- a/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java +++ b/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Random; import biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.common.block.BlockFoliage.FoliageType; import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; @@ -91,6 +92,19 @@ public class BlockDoubleFoliage extends BlockDoubleDecoration implements ISheara } } + // flax item should not be tinted, even though the model is + @Override + public int getItemRenderColor(IBlockState state, int tintIndex) + { + switch ((FoliageType) state.getValue(VARIANT)) + { + case FLAX: + return 0xFFFFFF; + default: + return this.getRenderColor(state); + } + } + // different variants have different sizes @Override diff --git a/src/main/java/biomesoplenty/common/block/BlockFlesh.java b/src/main/java/biomesoplenty/common/block/BlockFlesh.java index 2121c622a..75357a8cc 100644 --- a/src/main/java/biomesoplenty/common/block/BlockFlesh.java +++ b/src/main/java/biomesoplenty/common/block/BlockFlesh.java @@ -39,6 +39,8 @@ public class BlockFlesh extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockFlesh() { super(Material.sponge); diff --git a/src/main/java/biomesoplenty/common/block/BlockFoliage.java b/src/main/java/biomesoplenty/common/block/BlockFoliage.java index 68715fe47..5abaa0687 100644 --- a/src/main/java/biomesoplenty/common/block/BlockFoliage.java +++ b/src/main/java/biomesoplenty/common/block/BlockFoliage.java @@ -157,6 +157,20 @@ public class BlockFoliage extends BlockDecoration implements IShearable return BiomeColorHelper.getGrassColorAtPos(worldIn, pos); } } + + // berrybush item should not be tinted, even though the model is + @Override + public int getItemRenderColor(IBlockState state, int tintIndex) + { + switch ((FoliageType) state.getValue(VARIANT)) + { + case BERRYBUSH: + return 0xFFFFFF; + default: + return this.getRenderColor(state); + } + } + // different variants have different sizes diff --git a/src/main/java/biomesoplenty/common/block/BlockGem.java b/src/main/java/biomesoplenty/common/block/BlockGem.java index 6094f5248..e6e667d00 100644 --- a/src/main/java/biomesoplenty/common/block/BlockGem.java +++ b/src/main/java/biomesoplenty/common/block/BlockGem.java @@ -36,6 +36,8 @@ public class BlockGem extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockGem() diff --git a/src/main/java/biomesoplenty/common/block/BlockGemOre.java b/src/main/java/biomesoplenty/common/block/BlockGemOre.java index 8ac6fea69..e820a1100 100644 --- a/src/main/java/biomesoplenty/common/block/BlockGemOre.java +++ b/src/main/java/biomesoplenty/common/block/BlockGemOre.java @@ -38,6 +38,8 @@ public class BlockGemOre extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockGemOre() diff --git a/src/main/java/biomesoplenty/common/block/BlockHive.java b/src/main/java/biomesoplenty/common/block/BlockHive.java index 912b4f309..dd068fe94 100644 --- a/src/main/java/biomesoplenty/common/block/BlockHive.java +++ b/src/main/java/biomesoplenty/common/block/BlockHive.java @@ -42,6 +42,8 @@ public class BlockHive extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + public BlockHive() { diff --git a/src/main/java/biomesoplenty/common/block/BlockMud.java b/src/main/java/biomesoplenty/common/block/BlockMud.java index 4a7cb54d4..c0f8dafdb 100644 --- a/src/main/java/biomesoplenty/common/block/BlockMud.java +++ b/src/main/java/biomesoplenty/common/block/BlockMud.java @@ -45,6 +45,8 @@ public class BlockMud extends Block implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return ItemBOPBlock.class;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + // constructor public BlockMud() { diff --git a/src/main/java/biomesoplenty/common/block/BlockTurnip.java b/src/main/java/biomesoplenty/common/block/BlockTurnip.java index 8a8b3dcf2..1db2c2478 100644 --- a/src/main/java/biomesoplenty/common/block/BlockTurnip.java +++ b/src/main/java/biomesoplenty/common/block/BlockTurnip.java @@ -27,6 +27,8 @@ public class BlockTurnip extends BlockCrops implements IBOPBlock public Map getNamedStates() {return this.namedStates;} public IBlockState getNamedState(String name) {return this.namedStates.get(name);} public Class getItemClass() {return null;} + public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + @Override protected Item getSeed() diff --git a/src/main/java/biomesoplenty/common/item/ItemBOPBlock.java b/src/main/java/biomesoplenty/common/item/ItemBOPBlock.java index 38ee914b1..9a27631cf 100644 --- a/src/main/java/biomesoplenty/common/item/ItemBOPBlock.java +++ b/src/main/java/biomesoplenty/common/item/ItemBOPBlock.java @@ -59,10 +59,11 @@ public class ItemBOPBlock extends ItemBlock } } + // TODO: renderPass is actually tintIndex - use for berries etc? @SideOnly(Side.CLIENT) - public int getColorFromItemStack(ItemStack stack, int renderPass) - { - return this.block.getRenderColor(this.block.getStateFromMeta(stack.getMetadata())); + public int getColorFromItemStack(ItemStack stack, int tintIndex) + { + return this.bopBlock.getItemRenderColor(this.block.getStateFromMeta(stack.getMetadata()), tintIndex); } @Override From 68e56e5324f35e7baa8c209972640833154d9385 Mon Sep 17 00:00:00 2001 From: Cheeserolls Date: Fri, 3 Apr 2015 22:32:02 +0100 Subject: [PATCH 3/4] Scrap concept of "named states", go back to looping through properties for block sub-types --- .../biomesoplenty/api/block/IBOPBlock.java | 9 ++- .../common/block/BlockBOPDirt.java | 33 +++----- .../common/block/BlockBOPDoor.java | 16 ++-- .../common/block/BlockBOPFence.java | 19 +++-- .../common/block/BlockBOPFenceGate.java | 18 ++--- .../common/block/BlockBOPFlower1.java | 24 +++--- .../common/block/BlockBOPFlower2.java | 22 ++--- .../common/block/BlockBOPGeneric.java | 16 ++-- .../common/block/BlockBOPGrass.java | 39 +++++---- .../common/block/BlockBOPLeaves.java | 18 ++--- .../common/block/BlockBOPLilypad.java | 36 ++++----- .../common/block/BlockBOPLog.java | 18 ++--- .../common/block/BlockBOPMushroom.java | 27 ++++--- .../common/block/BlockBOPStairs.java | 18 ++--- .../common/block/BlockBOPStone.java | 33 +++----- .../common/block/BlockBOPVine.java | 19 +++-- .../common/block/BlockBamboo.java | 4 +- .../common/block/BlockBones.java | 29 +++---- .../common/block/BlockCoral.java | 26 +++--- .../common/block/BlockCrystal.java | 15 ++-- .../common/block/BlockDecoration.java | 15 ++-- .../common/block/BlockDoubleDecoration.java | 2 + .../common/block/BlockDoubleFoliage.java | 19 +++-- .../common/block/BlockFlesh.java | 17 ++-- .../common/block/BlockFoliage.java | 20 ++--- .../common/block/BlockFruit.java | 22 ++--- .../biomesoplenty/common/block/BlockGem.java | 34 +++----- .../common/block/BlockGemOre.java | 42 +++++----- .../biomesoplenty/common/block/BlockHive.java | 29 +++---- .../biomesoplenty/common/block/BlockMud.java | 27 +++---- .../common/block/BlockStoneFormations.java | 18 +++-- .../common/block/BlockTurnip.java | 18 ++--- .../biomesoplenty/common/init/ModBlocks.java | 18 +++-- .../common/item/ItemBOPBlock.java | 20 +++-- .../common/util/block/BlockStateUtils.java | 81 +++++++++++++++++++ 35 files changed, 430 insertions(+), 391 deletions(-) diff --git a/src/main/java/biomesoplenty/api/block/IBOPBlock.java b/src/main/java/biomesoplenty/api/block/IBOPBlock.java index 923914d2f..5f9634f56 100644 --- a/src/main/java/biomesoplenty/api/block/IBOPBlock.java +++ b/src/main/java/biomesoplenty/api/block/IBOPBlock.java @@ -8,16 +8,17 @@ package biomesoplenty.api.block; -import java.util.Map; - +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemBlock; public interface IBOPBlock { - public Map getNamedStates(); - public IBlockState getNamedState(String name); public Class getItemClass(); public int getItemRenderColor(IBlockState state, int tintIndex); + public IProperty[] getPresetProperties(); + public IProperty[] getRenderProperties(); + public IBlockState getDefaultState(); + public String getStateName(IBlockState state); } \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPDirt.java b/src/main/java/biomesoplenty/common/block/BlockBOPDirt.java index 6884220bb..11b3609a2 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPDirt.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPDirt.java @@ -8,9 +8,6 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; @@ -38,14 +35,15 @@ public class BlockBOPDirt extends Block implements IBOPBlock @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { COARSE, VARIANT });} - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} - - + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {COARSE, VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {COARSE, VARIANT}; } + public String getStateName(IBlockState state) + { + return (Boolean.TRUE.equals(state.getValue(COARSE)) ? "coarse_" : "") + ((BOPDirtType) state.getValue(VARIANT)).getName() + "_dirt"; + } public BlockBOPDirt() { @@ -55,17 +53,8 @@ public class BlockBOPDirt extends Block implements IBOPBlock // set some defaults this.setHardness(0.5F); this.setHarvestLevel("shovel", 0); - this.setStepSound(Block.soundTypeGravel); - - // define named states - this.namedStates.put("loamy_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(false)).withProperty(VARIANT, BOPDirtType.LOAMY) ); - this.namedStates.put("sandy_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(false)).withProperty(VARIANT, BOPDirtType.SANDY) ); - this.namedStates.put("silty_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(false)).withProperty(VARIANT, BOPDirtType.SILTY) ); - this.namedStates.put("coarse_loamy_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(true)).withProperty(VARIANT, BOPDirtType.LOAMY) ); - this.namedStates.put("coarse_sandy_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(true)).withProperty(VARIANT, BOPDirtType.SANDY) ); - this.namedStates.put("coarse_silty_dirt", this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(true)).withProperty(VARIANT, BOPDirtType.SILTY) ); - - this.setDefaultState(this.namedStates.get("loamy_dirt")); + this.setStepSound(Block.soundTypeGravel); + this.setDefaultState( this.blockState.getBaseState().withProperty(COARSE, Boolean.valueOf(false)).withProperty(VARIANT, BOPDirtType.LOAMY) ); } diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPDoor.java b/src/main/java/biomesoplenty/common/block/BlockBOPDoor.java index bf5f50db3..57c690fa0 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPDoor.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPDoor.java @@ -8,12 +8,10 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import biomesoplenty.api.block.IBOPBlock; import net.minecraft.block.BlockDoor; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; @@ -24,13 +22,13 @@ import net.minecraftforge.fml.relauncher.SideOnly; public class BlockBOPDoor extends BlockDoor implements IBOPBlock { - // implement IDHBlock - protected Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return null;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + // implement IBOPBlock + public Class getItemClass() { return null; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {FACING, OPEN, HINGE, HALF}; } + public String getStateName(IBlockState state) {return "";} private Item doorItem; diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPFence.java b/src/main/java/biomesoplenty/common/block/BlockBOPFence.java index 403572392..655220413 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPFence.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPFence.java @@ -8,24 +8,23 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.item.ItemBOPBlock; import net.minecraft.block.BlockFence; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemBlock; public class BlockBOPFence extends BlockFence implements IBOPBlock -{ - // implement IDHBlock - protected Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} +{ + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {NORTH, EAST, SOUTH, WEST}; } + public String getStateName(IBlockState state) {return "";} public BlockBOPFence() diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPFenceGate.java b/src/main/java/biomesoplenty/common/block/BlockBOPFenceGate.java index 28a4efb70..6910072a7 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPFenceGate.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPFenceGate.java @@ -8,12 +8,10 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.item.ItemBOPBlock; import net.minecraft.block.BlockFenceGate; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemBlock; @@ -22,13 +20,13 @@ import net.minecraft.item.ItemBlock; //this kind of thing going on: this.registerBlockWithStateMapper(Blocks.oak_fence_gate, (new StateMap.Builder()).addPropertiesToIgnore(new IProperty[] {BlockFenceGate.POWERED}).build()); public class BlockBOPFenceGate extends BlockFenceGate implements IBOPBlock { - - // implement IDHBlock - protected Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {FACING, OPEN, IN_WALL}; } + public String getStateName(IBlockState state) {return "";} public BlockBOPFenceGate() diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPFlower1.java b/src/main/java/biomesoplenty/common/block/BlockBOPFlower1.java index a5c938ed9..ba7e36533 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPFlower1.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPFlower1.java @@ -45,20 +45,22 @@ public class BlockBOPFlower1 extends BlockDecoration { }; public static final PropertyEnum VARIANT = PropertyEnum.create("variant", FlowerType.class); @Override - protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} + protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} + + + // implement IBOPBlock + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + return ((FlowerType) state.getValue(VARIANT)).getName(); + } + public BlockBOPFlower1() { - super(); - - // define named states - for(FlowerType flowerType : FlowerType.values()) - { - this.namedStates.put(flowerType.getName(), this.blockState.getBaseState().withProperty(VARIANT, flowerType)); - } - - this.setDefaultState(this.getNamedState("clover")); - + super(); + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, FlowerType.CLOVER) ); } diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPFlower2.java b/src/main/java/biomesoplenty/common/block/BlockBOPFlower2.java index 3ffb17471..b0e3337e5 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPFlower2.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPFlower2.java @@ -33,20 +33,22 @@ public class BlockBOPFlower2 extends BlockDecoration { }; public static final PropertyEnum VARIANT = PropertyEnum.create("variant", FlowerType.class); @Override - protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} + protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} + + + // implement IBOPBlock + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + return ((FlowerType) state.getValue(VARIANT)).getName(); + } + public BlockBOPFlower2() { super(); - - // define named states - for(FlowerType flowerType : FlowerType.values()) - { - this.namedStates.put(flowerType.getName(), this.blockState.getBaseState().withProperty(VARIANT, flowerType)); - } - - this.setDefaultState(this.getNamedState("lavender")); - + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, FlowerType.LAVENDER) ); } diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPGeneric.java b/src/main/java/biomesoplenty/common/block/BlockBOPGeneric.java index f6512f1a1..4b92895da 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPGeneric.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPGeneric.java @@ -8,25 +8,23 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - 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.state.IBlockState; import net.minecraft.item.ItemBlock; public class BlockBOPGeneric extends Block implements IBOPBlock { - // implement IDHBlock - protected Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {}; } + public String getStateName(IBlockState state) {return "";} public BlockBOPGeneric() { diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPGrass.java b/src/main/java/biomesoplenty/common/block/BlockBOPGrass.java index 0b286d846..7d38253d5 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPGrass.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPGrass.java @@ -8,8 +8,6 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import biomesoplenty.api.block.BOPBlocks; @@ -47,15 +45,24 @@ public class BlockBOPGrass extends BlockGrass implements IBOPBlock public static enum BOPGrassType implements IStringSerializable {SPECTRAL_MOSS, SMOLDERING, LOAMY, SANDY, SILTY, ORIGIN, OVERGROWN_NETHERRACK; public String getName() {return this.name().toLowerCase();}}; public static final PropertyEnum VARIANT = PropertyEnum.create("variant", BOPGrassType.class); @Override - protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT, SNOWY });} + protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { SNOWY, VARIANT });} - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} - + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {SNOWY, VARIANT}; } + public String getStateName(IBlockState state) { + BOPGrassType grassType = (BOPGrassType)state.getValue(VARIANT); + switch (grassType) + { + case SPECTRAL_MOSS: case OVERGROWN_NETHERRACK: + return grassType.getName(); + default: + return grassType.getName() + "_grass_block"; + } + } public BlockBOPGrass() @@ -66,17 +73,7 @@ public class BlockBOPGrass extends BlockGrass implements IBOPBlock this.setHardness(0.6F); this.setHarvestLevel("shovel", 0); // TODO: I think this just determines which tool speeds up digging - need to investigate more this.setStepSound(Block.soundTypeGrass); - - // define named states - this.namedStates.put("spectral_moss", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.SPECTRAL_MOSS) ); - this.namedStates.put("smoldering_grass_block", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.SMOLDERING) ); - this.namedStates.put("loamy_grass_block", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.LOAMY) ); - this.namedStates.put("sandy_grass_block", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.SANDY) ); - this.namedStates.put("silty_grass_block", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.SILTY) ); - this.namedStates.put("origin_grass_block", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.ORIGIN) ); - this.namedStates.put("overgrown_netherrack", this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.OVERGROWN_NETHERRACK) ); - - this.setDefaultState(this.namedStates.get("loamy_grass_block")); + this.setDefaultState(this.blockState.getBaseState().withProperty(SNOWY, Boolean.valueOf(false)).withProperty(VARIANT, BOPGrassType.LOAMY)); } diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java b/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java index 7ed6c4639..33435be42 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPLeaves.java @@ -8,9 +8,7 @@ package biomesoplenty.common.block; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Random; import biomesoplenty.api.block.IBOPBlock; @@ -37,15 +35,15 @@ public class BlockBOPLeaves extends BlockLeaves implements IBOPBlock // add properties - note CHECK_DECAY and DECAYABLE are both inherited from BlockLeaves @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] {CHECK_DECAY, DECAYABLE});} - - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {}; } + public String getStateName(IBlockState state) {return "";} - + private ItemStack sapling; private ItemStack fruit; private int saplingDropChance; diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPLilypad.java b/src/main/java/biomesoplenty/common/block/BlockBOPLilypad.java index f82c182d5..95cefa630 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPLilypad.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPLilypad.java @@ -8,9 +8,6 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.item.ItemBOPLilypad; import net.minecraft.block.BlockLilyPad; @@ -30,26 +27,29 @@ public class BlockBOPLilypad extends BlockLilyPad implements IBOPBlock public static final PropertyEnum VARIANT = PropertyEnum.create("variant", LilypadType.class); @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} - - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - // need to use a custom item class because of the unique way lilies are placed - public Class getItemClass() {return ItemBOPLilypad.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + // implement IBOPBlock + // need to use a custom item class because of the unique way lilies are placed + public Class getItemClass() { return ItemBOPLilypad.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) { + LilypadType type = (LilypadType) state.getValue(VARIANT); + switch (type) + { + case DUCKWEED: + return type.getName(); + default: + return "lily_"+type.getName(); + } + } + public BlockBOPLilypad() { - // define named states - this.namedStates.put("lily_medium", this.blockState.getBaseState().withProperty(VARIANT, LilypadType.MEDIUM) ); - this.namedStates.put("lily_small", this.blockState.getBaseState().withProperty(VARIANT, LilypadType.SMALL) ); - this.namedStates.put("lily_tiny", this.blockState.getBaseState().withProperty(VARIANT, LilypadType.TINY) ); - this.namedStates.put("duckweed", this.blockState.getBaseState().withProperty(VARIANT, LilypadType.DUCKWEED) ); - - this.setDefaultState(this.namedStates.get("lily_medium")); + this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, LilypadType.MEDIUM)); } @Override diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPLog.java b/src/main/java/biomesoplenty/common/block/BlockBOPLog.java index c28a873db..131e93fb3 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPLog.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPLog.java @@ -8,9 +8,6 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.item.ItemBOPBlock; import net.minecraft.block.BlockLog; @@ -25,13 +22,14 @@ public class BlockBOPLog extends BlockLog implements IBOPBlock // add properties (note we inherit LOG_AXIS property from parent BlockLog) @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { LOG_AXIS });} - - // implement IDHBlock - protected Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {LOG_AXIS}; } + public String getStateName(IBlockState state) {return "";} public BlockBOPLog() diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPMushroom.java b/src/main/java/biomesoplenty/common/block/BlockBOPMushroom.java index 1958680aa..bf04cdefb 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPMushroom.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPMushroom.java @@ -9,12 +9,14 @@ package biomesoplenty.common.block; import biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.common.item.ItemBOPBlock; import net.minecraft.block.Block; 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; @@ -30,22 +32,24 @@ public class BlockBOPMushroom extends BlockDecoration public static final PropertyEnum VARIANT = PropertyEnum.create("variant", MushroomType.class); @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + return ((MushroomType) state.getValue(VARIANT)).getName(); + } + public BlockBOPMushroom() { // set some defaults - this.setBlockBoundsByRadiusAndHeight(0.2F, 0.4F); - - // define named states - this.namedStates.put("toadstool", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.TOADSTOOL)); - this.namedStates.put("portobello", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.PORTOBELLO)); - this.namedStates.put("blue_milk_cap", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.BLUE_MILK_CAP)); - this.namedStates.put("glowshroom", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.GLOWSHROOM)); - this.namedStates.put("flat_mushroom", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.FLAT_MUSHROOM)); - this.namedStates.put("shadow_shroom", this.blockState.getBaseState().withProperty(VARIANT, MushroomType.SHADOW_SHROOM)); - - this.setDefaultState(this.namedStates.get("toadstool")); + this.setBlockBoundsByRadiusAndHeight(0.2F, 0.4F); + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, MushroomType.TOADSTOOL) ); } // map from state to meta and vice verca @@ -94,7 +98,6 @@ public class BlockBOPMushroom extends BlockDecoration boolean onStone = (groundBlock == Blocks.stone || groundBlock == BOPBlocks.stone); // TODO: hard dirt too? the other edge cases? boolean onEndstone = (groundBlock == Blocks.end_stone); - //System.out.println("ground block is " + BlockStateUtils.getStateInfoAsString(groundState)); if (groundBlock instanceof BlockBOPGrass) { switch ((BlockBOPGrass.BOPGrassType) groundState.getValue(BlockBOPGrass.VARIANT)) diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPStairs.java b/src/main/java/biomesoplenty/common/block/BlockBOPStairs.java index 9e61babf4..6212779f4 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPStairs.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPStairs.java @@ -8,24 +8,22 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.item.ItemBOPBlock; import net.minecraft.block.BlockStairs; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemBlock; public class BlockBOPStairs extends BlockStairs implements IBOPBlock { - - // implement IDHBlock - protected Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {FACING, HALF, SHAPE}; } + public String getStateName(IBlockState state) {return "";} public BlockBOPStairs(IBlockState modelState) diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPStone.java b/src/main/java/biomesoplenty/common/block/BlockBOPStone.java index 615e60ba9..e8d73f14f 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPStone.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPStone.java @@ -8,9 +8,6 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.item.ItemBOPBlock; import net.minecraft.block.Block; @@ -37,13 +34,17 @@ public class BlockBOPStone extends Block implements IBOPBlock @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT, POLISHED });} - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} - + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT, POLISHED}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT, POLISHED}; } + public String getStateName(IBlockState state) + { + return (Boolean.TRUE.equals(state.getValue(POLISHED)) ? "polished_" : "") + ((StoneType) state.getValue(VARIANT)).getName(); + } + public BlockBOPStone() { @@ -51,20 +52,10 @@ public class BlockBOPStone extends Block implements IBOPBlock // set some defaults this.setStepSound(Block.soundTypeStone); - this.setHarvestLevel("pickaxe", 1, this.getDefaultState().withProperty(VARIANT, StoneType.LIMESTONE)); this.setHarvestLevel("pickaxe", 2, this.getDefaultState().withProperty(VARIANT, StoneType.SILTSTONE)); this.setHarvestLevel("pickaxe", 3, this.getDefaultState().withProperty(VARIANT, StoneType.SHALE)); - - // define named states - this.namedStates.put("limestone", this.blockState.getBaseState().withProperty(VARIANT, StoneType.LIMESTONE).withProperty(POLISHED, Boolean.valueOf(false)) ); - this.namedStates.put("siltstone", this.blockState.getBaseState().withProperty(VARIANT, StoneType.SILTSTONE).withProperty(POLISHED, Boolean.valueOf(false)) ); - this.namedStates.put("shale", this.blockState.getBaseState().withProperty(VARIANT, StoneType.SHALE).withProperty(POLISHED, Boolean.valueOf(false)) ); - this.namedStates.put("polished_limestone", this.blockState.getBaseState().withProperty(VARIANT, StoneType.LIMESTONE).withProperty(POLISHED, Boolean.valueOf(true)) ); - this.namedStates.put("polished_siltstone", this.blockState.getBaseState().withProperty(VARIANT, StoneType.SILTSTONE).withProperty(POLISHED, Boolean.valueOf(true)) ); - this.namedStates.put("polished_shale", this.blockState.getBaseState().withProperty(VARIANT, StoneType.SHALE).withProperty(POLISHED, Boolean.valueOf(true)) ); - - this.setDefaultState(this.namedStates.get("limestone")); + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, StoneType.LIMESTONE).withProperty(POLISHED, Boolean.valueOf(false)) ); } diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPVine.java b/src/main/java/biomesoplenty/common/block/BlockBOPVine.java index 3a7601d95..08c9f7d2d 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPVine.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPVine.java @@ -8,12 +8,10 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.item.ItemBOPBlock; import net.minecraft.block.BlockVine; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemBlock; import net.minecraft.util.BlockPos; @@ -23,13 +21,14 @@ import net.minecraftforge.fml.relauncher.SideOnly; public class BlockBOPVine extends BlockVine implements IBOPBlock { - // implement IDHBlock - protected Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} - + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {UP, NORTH, EAST, SOUTH, WEST}; } + public String getStateName(IBlockState state) {return "";} + // if set to true, (the default), use BlockVine getBlockColor(), getRenderColor() and colorMultiplier() functions to color the texture based on biome // if set to false, use 0xFFFFFF for all the color functions so that the texture is used as it is diff --git a/src/main/java/biomesoplenty/common/block/BlockBamboo.java b/src/main/java/biomesoplenty/common/block/BlockBamboo.java index 7a3e08aca..1164b688e 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBamboo.java +++ b/src/main/java/biomesoplenty/common/block/BlockBamboo.java @@ -27,7 +27,8 @@ public class BlockBamboo extends BlockDecoration // add properties public static final PropertyInteger AGE = PropertyInteger.create("age", 0, 15); @Override - protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { AGE });} + protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { AGE });} + public BlockBamboo() { @@ -96,7 +97,6 @@ public class BlockBamboo extends BlockDecoration int age = ((Integer)state.getValue(AGE)).intValue(); int treeHeight = 1; while (worldIn.getBlockState(pos.down(treeHeight)).getBlock() == this) {++treeHeight;} - //System.out.println("Banboo age: "+age+" tree height: "+treeHeight); if (treeHeight < 4) { diff --git a/src/main/java/biomesoplenty/common/block/BlockBones.java b/src/main/java/biomesoplenty/common/block/BlockBones.java index 22e38b039..a15c2787a 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBones.java +++ b/src/main/java/biomesoplenty/common/block/BlockBones.java @@ -8,9 +8,6 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; @@ -40,13 +37,15 @@ public class BlockBones extends Block implements IBOPBlock @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { AXIS, VARIANT });} - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} - + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {AXIS, VARIANT}; } + public String getStateName(IBlockState state) + { + return ((BoneType) state.getValue(VARIANT)).getName() + "_bone_segment"; + } public BlockBones() { @@ -56,14 +55,8 @@ public class BlockBones extends Block implements IBOPBlock this.setHardness(3.0F); this.setResistance(5.0F); this.setStepSound(Block.soundTypeStone); - - // define named states - this.namedStates.put("small_bone_segment", this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.Y).withProperty(VARIANT, BoneType.SMALL)); - this.namedStates.put("medium_bone_segment", this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.Y).withProperty(VARIANT, BoneType.MEDIUM)); - this.namedStates.put("large_bone_segment", this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.Y).withProperty(VARIANT, BoneType.LARGE)); - - this.setDefaultState(this.namedStates.get("large_bone_segment")); - + + this.setDefaultState(this.blockState.getBaseState().withProperty(AXIS, EnumFacing.Axis.Y).withProperty(VARIANT, BoneType.LARGE)); } diff --git a/src/main/java/biomesoplenty/common/block/BlockCoral.java b/src/main/java/biomesoplenty/common/block/BlockCoral.java index b25e8fc90..8f726da6a 100644 --- a/src/main/java/biomesoplenty/common/block/BlockCoral.java +++ b/src/main/java/biomesoplenty/common/block/BlockCoral.java @@ -34,6 +34,22 @@ public class BlockCoral extends BlockDecoration @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { LEVEL, VARIANT });} + // implement IBOPBlock + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + CoralType type = (CoralType) state.getValue(VARIANT); + switch (type) + { + case ALGAE: + return type.getName(); + default: + return type.getName()+"_coral"; + } + } + + public BlockCoral() { super(Material.water); @@ -42,15 +58,7 @@ public class BlockCoral extends BlockDecoration this.setHardness(0.6F); this.setStepSound(Block.soundTypeSand); this.setBlockBoundsByRadiusAndHeight(0.4F, 0.8F); - - // define named states - this.namedStates.put("pink_coral", this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.PINK) ); - this.namedStates.put("orange_coral", this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.ORANGE) ); - this.namedStates.put("blue_coral", this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.BLUE) ); - this.namedStates.put("glowing_coral", this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.GLOWING) ); - this.namedStates.put("algae", this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.ALGAE) ); - - this.setDefaultState(this.namedStates.get("pink_coral")); + this.setDefaultState( this.blockState.getBaseState().withProperty(LEVEL, 15).withProperty(VARIANT, CoralType.PINK) ); } diff --git a/src/main/java/biomesoplenty/common/block/BlockCrystal.java b/src/main/java/biomesoplenty/common/block/BlockCrystal.java index 25a717018..909a79a7f 100644 --- a/src/main/java/biomesoplenty/common/block/BlockCrystal.java +++ b/src/main/java/biomesoplenty/common/block/BlockCrystal.java @@ -8,8 +8,6 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import biomesoplenty.api.block.IBOPBlock; @@ -17,6 +15,7 @@ import biomesoplenty.api.item.BOPItems; 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.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; @@ -24,12 +23,12 @@ import net.minecraft.item.ItemBlock; public class BlockCrystal extends Block implements IBOPBlock { - // implement IDHBlock - protected Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {}; } + public String getStateName(IBlockState state) {return "";} public BlockCrystal() { diff --git a/src/main/java/biomesoplenty/common/block/BlockDecoration.java b/src/main/java/biomesoplenty/common/block/BlockDecoration.java index c4d821a64..716e952b0 100644 --- a/src/main/java/biomesoplenty/common/block/BlockDecoration.java +++ b/src/main/java/biomesoplenty/common/block/BlockDecoration.java @@ -8,12 +8,11 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.item.ItemBlock; @@ -31,12 +30,12 @@ import biomesoplenty.common.item.ItemBOPBlock; public class BlockDecoration extends Block implements IBOPBlock { - // implement IDHBlock - protected Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {}; } + public String getStateName(IBlockState state) {return "";} // constructor diff --git a/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java b/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java index 78ee2035f..88fb96d47 100644 --- a/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java +++ b/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java @@ -30,6 +30,8 @@ class BlockDoubleDecoration extends BlockDecoration { public static enum Half implements IStringSerializable {LOWER, UPPER; public String getName() {return this.name().toLowerCase();}}; public static final PropertyEnum HALF = PropertyEnum.create("half", Half.class); protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { HALF });} + + public IProperty[] getRenderProperties() { return new IProperty[] {HALF}; } public float radius; public float height; diff --git a/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java b/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java index 8e058ee8b..6be5c220c 100644 --- a/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java +++ b/src/main/java/biomesoplenty/common/block/BlockDoubleFoliage.java @@ -12,7 +12,6 @@ import java.util.List; import java.util.Random; import biomesoplenty.api.block.BOPBlocks; -import biomesoplenty.common.block.BlockFoliage.FoliageType; import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; @@ -40,16 +39,20 @@ public class BlockDoubleFoliage extends BlockDoubleDecoration implements ISheara @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { HALF, VARIANT });} + + // implement IBOPBlock + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {HALF, VARIANT}; } + public String getStateName(IBlockState state) + { + return ((FoliageType) state.getValue(VARIANT)).getName(); + } + + public BlockDoubleFoliage() { super(); - - // define named states - for(FoliageType foliageType : FoliageType.values()) - { - this.namedStates.put(foliageType.getName(), this.blockState.getBaseState().withProperty(HALF, Half.LOWER) .withProperty(VARIANT, foliageType)); - } - this.setDefaultState(this.getNamedState("flax")); + this.setDefaultState( this.blockState.getBaseState().withProperty(HALF, Half.LOWER) .withProperty(VARIANT, FoliageType.FLAX) ); } // map from state to meta and vice verca - use highest bit for Half, and lower bits for variant diff --git a/src/main/java/biomesoplenty/common/block/BlockFlesh.java b/src/main/java/biomesoplenty/common/block/BlockFlesh.java index 75357a8cc..56c63d41b 100644 --- a/src/main/java/biomesoplenty/common/block/BlockFlesh.java +++ b/src/main/java/biomesoplenty/common/block/BlockFlesh.java @@ -8,13 +8,11 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; - +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; @@ -34,13 +32,12 @@ import biomesoplenty.common.item.ItemBOPBlock; public class BlockFlesh extends Block implements IBOPBlock { - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} - + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {}; } + public String getStateName(IBlockState state) {return "";} public BlockFlesh() { super(Material.sponge); diff --git a/src/main/java/biomesoplenty/common/block/BlockFoliage.java b/src/main/java/biomesoplenty/common/block/BlockFoliage.java index 5abaa0687..5f35c312f 100644 --- a/src/main/java/biomesoplenty/common/block/BlockFoliage.java +++ b/src/main/java/biomesoplenty/common/block/BlockFoliage.java @@ -52,18 +52,20 @@ public class BlockFoliage extends BlockDecoration implements IShearable @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} + + // implement IBOPBlock + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + return ((FoliageType) state.getValue(VARIANT)).getName(); + } + + public BlockFoliage() { super(); - - // define named states - for(FoliageType foliageType : FoliageType.values()) - { - this.namedStates.put(foliageType.getName(), this.blockState.getBaseState().withProperty(VARIANT, foliageType)); - } - - this.setDefaultState(this.getNamedState("shortgrass")); - + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, FoliageType.SHORTGRASS) ); } // map from state to meta and vice verca diff --git a/src/main/java/biomesoplenty/common/block/BlockFruit.java b/src/main/java/biomesoplenty/common/block/BlockFruit.java index 594f6302c..d7e6fb5f2 100644 --- a/src/main/java/biomesoplenty/common/block/BlockFruit.java +++ b/src/main/java/biomesoplenty/common/block/BlockFruit.java @@ -33,22 +33,24 @@ public class BlockFruit extends BlockDecoration public static final PropertyEnum VARIANT = PropertyEnum.create("variant", FruitType.class); @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} + + + // implement IBOPBlock + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + return ((FruitType) state.getValue(VARIANT)).getName() + "_block"; + } + // constructor public BlockFruit() { // set some defaults this.setStepSound(Block.soundTypeGrass); - this.setBlockBoundsByRadiusAndHeight(0.25F, 0.25F, true); - - // define named states - this.namedStates.put("apple_block", this.blockState.getBaseState().withProperty(VARIANT, FruitType.APPLE)); - this.namedStates.put("persimmon_block", this.blockState.getBaseState().withProperty(VARIANT, FruitType.PERSIMMON)); - this.namedStates.put("peach_block", this.blockState.getBaseState().withProperty(VARIANT, FruitType.PEACH)); - this.namedStates.put("pear_block", this.blockState.getBaseState().withProperty(VARIANT, FruitType.PEAR)); - - this.setDefaultState(this.namedStates.get("apple_block")); - + this.setBlockBoundsByRadiusAndHeight(0.25F, 0.25F, true); + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, FruitType.APPLE) ); } // map from state to meta and vice verca diff --git a/src/main/java/biomesoplenty/common/block/BlockGem.java b/src/main/java/biomesoplenty/common/block/BlockGem.java index e6e667d00..1be25c9f2 100644 --- a/src/main/java/biomesoplenty/common/block/BlockGem.java +++ b/src/main/java/biomesoplenty/common/block/BlockGem.java @@ -8,9 +8,6 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; - import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.item.ItemBOPBlock; import net.minecraft.block.Block; @@ -30,14 +27,17 @@ public class BlockGem extends Block implements IBOPBlock public static final PropertyEnum VARIANT = PropertyEnum.create("variant", GemType.class); @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} + - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} - + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + return ((GemType) state.getValue(VARIANT)).getName() + "_block"; + } public BlockGem() @@ -49,19 +49,7 @@ public class BlockGem extends Block implements IBOPBlock this.setResistance(10.0F); this.setStepSound(Block.soundTypeMetal); this.setHarvestLevel("pickaxe", 2); - - // define named states - this.namedStates.put("amethyst_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.AMETHYST) ); - this.namedStates.put("ruby_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.RUBY) ); - this.namedStates.put("peridot_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.PERIDOT) ); - this.namedStates.put("topaz_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.TOPAZ) ); - this.namedStates.put("tanzanite_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.TANZANITE) ); - this.namedStates.put("malachite_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.MALACHITE) ); - this.namedStates.put("sapphire_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.SAPPHIRE) ); - this.namedStates.put("amber_block", this.blockState.getBaseState().withProperty(VARIANT, GemType.AMBER) ); - - this.setDefaultState(this.namedStates.get("amethyst_block")); - + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, GemType.AMETHYST) ); } // map from state to meta and vice verca diff --git a/src/main/java/biomesoplenty/common/block/BlockGemOre.java b/src/main/java/biomesoplenty/common/block/BlockGemOre.java index e820a1100..904dc60a8 100644 --- a/src/main/java/biomesoplenty/common/block/BlockGemOre.java +++ b/src/main/java/biomesoplenty/common/block/BlockGemOre.java @@ -10,14 +10,13 @@ package biomesoplenty.common.block; import static biomesoplenty.common.block.BlockGem.VARIANT; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.api.item.BOPItems; import biomesoplenty.common.block.BlockGem.GemType; import biomesoplenty.common.item.ItemBOPBlock; +import biomesoplenty.common.util.block.BlockStateUtils; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; @@ -32,15 +31,18 @@ public class BlockGemOre extends Block implements IBOPBlock // add properties (note VARIANT is imported statically from the BlockGem class) @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} - - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + return ((GemType) state.getValue(VARIANT)).getName() + "_ore"; + } + public BlockGemOre() { @@ -49,23 +51,15 @@ public class BlockGemOre extends Block implements IBOPBlock // set some defaults this.setHardness(3.0F); this.setResistance(5.0F); - this.setStepSound(Block.soundTypePiston); - - // define named states - this.namedStates.put("amethyst_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.AMETHYST) ); - this.namedStates.put("ruby_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.RUBY) ); - this.namedStates.put("peridot_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.PERIDOT) ); - this.namedStates.put("topaz_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.TOPAZ) ); - this.namedStates.put("tanzanite_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.TANZANITE) ); - this.namedStates.put("malachite_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.MALACHITE) ); - this.namedStates.put("sapphire_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.SAPPHIRE) ); - this.namedStates.put("amber_ore", this.blockState.getBaseState().withProperty(VARIANT, GemType.AMBER) ); - - this.setDefaultState(this.namedStates.get("amethyst_ore")); + this.setStepSound(Block.soundTypePiston); + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, GemType.AMETHYST) ); // all variants need pickaxe:2 to harvest, except amethyst which needs pickaxe:3 - for (IBlockState state : this.namedStates.values()) {this.setHarvestLevel("pickaxe", 2, state);} - this.setHarvestLevel("pickaxe", 3, this.namedStates.get("amethyst_ore")); + for (IBlockState state : BlockStateUtils.getBlockPresets(this)) + { + this.setHarvestLevel("pickaxe", 2, state); + } + this.setHarvestLevel("pickaxe", 3, this.blockState.getBaseState().withProperty(VARIANT, GemType.AMETHYST)); } diff --git a/src/main/java/biomesoplenty/common/block/BlockHive.java b/src/main/java/biomesoplenty/common/block/BlockHive.java index dd068fe94..2e307f167 100644 --- a/src/main/java/biomesoplenty/common/block/BlockHive.java +++ b/src/main/java/biomesoplenty/common/block/BlockHive.java @@ -8,8 +8,6 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import net.minecraft.block.Block; @@ -37,13 +35,16 @@ public class BlockHive extends Block implements IBOPBlock @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} - + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + return ((HiveType) state.getValue(VARIANT)).getName() + "_block"; + } public BlockHive() { @@ -52,15 +53,7 @@ public class BlockHive extends Block implements IBOPBlock // set some defaults this.setHardness(0.5F); this.setStepSound(Block.soundTypeGrass); - - // define named states - this.namedStates.put("hive_block", this.blockState.getBaseState().withProperty(VARIANT, HiveType.HIVE) ); - this.namedStates.put("honeycomb_block", this.blockState.getBaseState().withProperty(VARIANT, HiveType.HONEYCOMB) ); - this.namedStates.put("empty_honeycomb_block", this.blockState.getBaseState().withProperty(VARIANT, HiveType.EMPTY_HONEYCOMB) ); - this.namedStates.put("filled_honeycomb_block", this.blockState.getBaseState().withProperty(VARIANT, HiveType.FILLED_HONEYCOMB) ); - - this.setDefaultState(this.namedStates.get("hive_block")); - + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, HiveType.HIVE) ); } // map from state to meta and vice verca diff --git a/src/main/java/biomesoplenty/common/block/BlockMud.java b/src/main/java/biomesoplenty/common/block/BlockMud.java index c0f8dafdb..6f02c0b4c 100644 --- a/src/main/java/biomesoplenty/common/block/BlockMud.java +++ b/src/main/java/biomesoplenty/common/block/BlockMud.java @@ -8,8 +8,6 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; import java.util.Random; import net.minecraft.block.Block; @@ -40,15 +38,17 @@ public class BlockMud extends Block implements IBOPBlock @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return ItemBOPBlock.class;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} + + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + return ((MudType) state.getValue(VARIANT)).getName(); + } - - // constructor public BlockMud() { super(Material.sand); @@ -56,12 +56,7 @@ public class BlockMud extends Block implements IBOPBlock // set some defaults this.setHardness(0.6F); this.setStepSound(Block.soundTypeSand); - - // define named states - this.namedStates.put("mud", this.blockState.getBaseState().withProperty(VARIANT, MudType.MUD) ); - this.namedStates.put("quicksand", this.blockState.getBaseState().withProperty(VARIANT, MudType.QUICKSAND) ); - - this.setDefaultState(this.namedStates.get("mud")); + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, MudType.MUD) ); } diff --git a/src/main/java/biomesoplenty/common/block/BlockStoneFormations.java b/src/main/java/biomesoplenty/common/block/BlockStoneFormations.java index beef0b415..19bf23093 100644 --- a/src/main/java/biomesoplenty/common/block/BlockStoneFormations.java +++ b/src/main/java/biomesoplenty/common/block/BlockStoneFormations.java @@ -27,6 +27,16 @@ public class BlockStoneFormations extends BlockDecoration public static final PropertyEnum VARIANT = PropertyEnum.create("variant", StoneFormationType.class); @Override protected BlockState createBlockState() {return new BlockState(this, new IProperty[] { VARIANT });} + + + // implement IBOPBlock + public IProperty[] getPresetProperties() { return new IProperty[] {VARIANT}; } + public IProperty[] getRenderProperties() { return new IProperty[] {VARIANT}; } + public String getStateName(IBlockState state) + { + return ((StoneFormationType) state.getValue(VARIANT)).getName(); + } + // constructor public BlockStoneFormations() { @@ -34,13 +44,7 @@ public class BlockStoneFormations extends BlockDecoration // set some defaults this.setHardness(0.5F); this.setStepSound(Block.soundTypePiston); - - // define named states - this.namedStates.put("stalactite", this.blockState.getBaseState().withProperty(VARIANT, StoneFormationType.STALACTITE) ); - this.namedStates.put("stalagmite", this.blockState.getBaseState().withProperty(VARIANT, StoneFormationType.STALAGMITE) ); - - this.setDefaultState(this.namedStates.get("stalagmite")); - + this.setDefaultState( this.blockState.getBaseState().withProperty(VARIANT, StoneFormationType.STALAGMITE) ); } // map from state to meta and vice verca diff --git a/src/main/java/biomesoplenty/common/block/BlockTurnip.java b/src/main/java/biomesoplenty/common/block/BlockTurnip.java index 1db2c2478..6a2f31629 100644 --- a/src/main/java/biomesoplenty/common/block/BlockTurnip.java +++ b/src/main/java/biomesoplenty/common/block/BlockTurnip.java @@ -8,27 +8,27 @@ package biomesoplenty.common.block; -import java.util.HashMap; -import java.util.Map; import net.minecraft.block.BlockCrops; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.api.item.BOPItems; +import biomesoplenty.common.item.ItemBOPBlock; // TODO: stop snow settling on this (floats above it) public class BlockTurnip extends BlockCrops implements IBOPBlock { - // implement IDHBlock - private Map namedStates = new HashMap(); - public Map getNamedStates() {return this.namedStates;} - public IBlockState getNamedState(String name) {return this.namedStates.get(name);} - public Class getItemClass() {return null;} - public int getItemRenderColor(IBlockState state, int tintIndex) {return this.getRenderColor(state);} - + // implement IBOPBlock + public Class getItemClass() { return ItemBOPBlock.class; } + public int getItemRenderColor(IBlockState state, int tintIndex) { return this.getRenderColor(state); } + public IProperty[] getPresetProperties() { return new IProperty[] {}; } + public IProperty[] getRenderProperties() { return new IProperty[] {AGE}; } + public String getStateName(IBlockState state) {return "";} + @Override protected Item getSeed() diff --git a/src/main/java/biomesoplenty/common/init/ModBlocks.java b/src/main/java/biomesoplenty/common/init/ModBlocks.java index f96d0c939..38f673d5f 100644 --- a/src/main/java/biomesoplenty/common/init/ModBlocks.java +++ b/src/main/java/biomesoplenty/common/init/ModBlocks.java @@ -10,7 +10,7 @@ package biomesoplenty.common.init; import static biomesoplenty.api.block.BOPBlocks.*; -import java.util.Map; +import com.google.common.collect.ImmutableSet; import net.minecraft.block.Block; import net.minecraft.block.material.Material; @@ -57,6 +57,7 @@ import biomesoplenty.common.block.BlockStoneFormations; import biomesoplenty.common.block.BlockTurnip; import biomesoplenty.common.block.BlockFlesh; import biomesoplenty.common.handler.GuiEventHandler; +import biomesoplenty.common.util.block.BlockStateUtils; import biomesoplenty.common.util.inventory.CreativeTabBOP; import biomesoplenty.core.BiomesOPlenty; @@ -282,21 +283,22 @@ public class ModBlocks if (block instanceof IBOPBlock) { - // if this block supports the IBOPBlock interface then we can use getNamedStates() and getItemClass() + // if this block supports the IBOPBlock interface then we can determine the item block class, and sub-blocks automatically IBOPBlock bopBlock = (IBOPBlock)block; GameRegistry.registerBlock(block, bopBlock.getItemClass(), blockName); - if (bopBlock.getNamedStates().isEmpty()) + ImmutableSet presets = BlockStateUtils.getBlockPresets(bopBlock); + + if (presets.isEmpty()) { - // block has no named variants to register + // block has no sub-blocks to register registerBlockVariant(block, blockName, block.getMetaFromState(block.getDefaultState())); } else { - // register all the named variants - for (Map.Entry entry : bopBlock.getNamedStates().entrySet()) + // register all the sub-blocks + for (IBlockState state : presets) { - String stateName = entry.getKey(); - IBlockState state = entry.getValue(); + String stateName = bopBlock.getStateName(state); int stateMeta = block.getMetaFromState(state); registerBlockVariant(block, stateName, stateMeta); } diff --git a/src/main/java/biomesoplenty/common/item/ItemBOPBlock.java b/src/main/java/biomesoplenty/common/item/ItemBOPBlock.java index 9a27631cf..889f32f65 100644 --- a/src/main/java/biomesoplenty/common/item/ItemBOPBlock.java +++ b/src/main/java/biomesoplenty/common/item/ItemBOPBlock.java @@ -11,8 +11,12 @@ package biomesoplenty.common.item; import java.util.List; import java.util.Map; +import com.google.common.collect.ImmutableSet; + +import biomesoplenty.api.block.BOPBlocks; import biomesoplenty.api.block.IBOPBlock; import biomesoplenty.common.block.BlockBOPGrass; +import biomesoplenty.common.util.block.BlockStateUtils; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; @@ -45,14 +49,15 @@ public class ItemBOPBlock extends ItemBlock @Override @SideOnly(Side.CLIENT) public void getSubItems(Item itemIn, CreativeTabs tab, List subItems) - { - if (bopBlock.getNamedStates().isEmpty()) + { + ImmutableSet presets = BlockStateUtils.getBlockPresets(bopBlock); + if (presets.isEmpty()) { subItems.add(new ItemStack(this.block, 1, this.block.getMetaFromState( this.block.getDefaultState() ))); } else { - for (IBlockState state : this.bopBlock.getNamedStates().values()) + for (IBlockState state : presets) { subItems.add(new ItemStack(this.block, 1, this.block.getMetaFromState(state))); } @@ -75,17 +80,18 @@ public class ItemBOPBlock extends ItemBlock @Override public String getUnlocalizedName(ItemStack stack) { - if (bopBlock.getNamedStates().isEmpty()) + ImmutableSet presets = BlockStateUtils.getBlockPresets(bopBlock); + if (presets.isEmpty()) { return super.getUnlocalizedName(); } else { int meta = stack.getMetadata(); - for (Map.Entry entry : bopBlock.getNamedStates().entrySet()) { - if (block.getMetaFromState(entry.getValue()) == meta) + for (IBlockState state : presets) { + if (block.getMetaFromState(state) == meta) { - return super.getUnlocalizedName() + "." + entry.getKey(); + return super.getUnlocalizedName() + "." + bopBlock.getStateName(state); } } return super.getUnlocalizedName() + "." + meta; diff --git a/src/main/java/biomesoplenty/common/util/block/BlockStateUtils.java b/src/main/java/biomesoplenty/common/util/block/BlockStateUtils.java index 080b93a50..05f0b24cb 100644 --- a/src/main/java/biomesoplenty/common/util/block/BlockStateUtils.java +++ b/src/main/java/biomesoplenty/common/util/block/BlockStateUtils.java @@ -11,11 +11,15 @@ package biomesoplenty.common.util.block; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Set; +import java.util.Stack; import java.util.Map.Entry; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; +import biomesoplenty.api.block.BOPBlocks; +import biomesoplenty.api.block.IBOPBlock; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; @@ -42,6 +46,81 @@ public class BlockStateUtils } + public static ImmutableSet getBlockPresets(IBOPBlock block) + { + return getStatesSet(block.getDefaultState(), block.getPresetProperties()); + } + + public static ImmutableSet getBlockRenderStates(IBOPBlock block) + { + return getStatesSet(block.getDefaultState(), block.getRenderProperties()); + } + + public static ImmutableSet getStatesSet(IBlockState baseState, IProperty... properties) + { + Stack propStack = new Stack(); + List states = new ArrayList(); + for (IProperty prop : properties) {propStack.push(prop);} + if (!propStack.isEmpty()) + { + AddStatesToList(baseState, states, propStack); + } + ImmutableSet ret = ImmutableSet.copyOf(states); + return ret; + } + + private static void AddStatesToList(IBlockState state, List list, Stack stack) + { + if (stack.empty()) + { + list.add(state); + return; + } + else + { + IProperty prop = stack.pop(); + for (Object value : prop.getAllowedValues()) + { + AddStatesToList(state.withProperty(prop, (Comparable)value), list, stack); + } + stack.push(prop); + } + } + + /* + public static Map getStatesSetNamed(IBlockState baseState, IProperty... properties) + { + Stack propStack = new Stack(); + Map states = new HashMap(); + for (IProperty prop : properties) {propStack.push(prop);} + AddStatesToMap(baseState, states, propStack); + return states; + } + + private static void AddStatesToMap(IBlockState state, Map map, Stack stack) + { + if (stack.empty()) + { + map.put(state.getBlock().getStateName(state), state); + return; + } + else + { + IProperty prop = stack.pop(); + for (Object value : prop.getAllowedValues()) + { + AddStatesToMap(state.withProperty(prop, (Comparable)value), map, stack); + } + stack.push(prop); + } + } + */ + + + + + + public static IProperty getPropertyByName(IBlockState blockState, String propertyName) { for (IProperty property : (ImmutableSet) blockState.getProperties().keySet()) @@ -52,6 +131,7 @@ public class BlockStateUtils return null; } + public static boolean isValidPropertyName(IBlockState blockState, String propertyName) { @@ -199,4 +279,5 @@ public class BlockStateUtils return validValues.get(counter); } } + } From c8e097ee37b551ace0ffcbbea41a044a79fc26cd Mon Sep 17 00:00:00 2001 From: Cheeserolls Date: Sat, 4 Apr 2015 02:18:29 +0100 Subject: [PATCH 4/4] Correct utterly shameful uppercase letter sin --- .../biomesoplenty/common/util/block/BlockStateUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/biomesoplenty/common/util/block/BlockStateUtils.java b/src/main/java/biomesoplenty/common/util/block/BlockStateUtils.java index 05f0b24cb..b2cf014a1 100644 --- a/src/main/java/biomesoplenty/common/util/block/BlockStateUtils.java +++ b/src/main/java/biomesoplenty/common/util/block/BlockStateUtils.java @@ -63,13 +63,13 @@ public class BlockStateUtils for (IProperty prop : properties) {propStack.push(prop);} if (!propStack.isEmpty()) { - AddStatesToList(baseState, states, propStack); + addStatesToList(baseState, states, propStack); } ImmutableSet ret = ImmutableSet.copyOf(states); return ret; } - private static void AddStatesToList(IBlockState state, List list, Stack stack) + private static void addStatesToList(IBlockState state, List list, Stack stack) { if (stack.empty()) { @@ -81,7 +81,7 @@ public class BlockStateUtils IProperty prop = stack.pop(); for (Object value : prop.getAllowedValues()) { - AddStatesToList(state.withProperty(prop, (Comparable)value), list, stack); + addStatesToList(state.withProperty(prop, (Comparable)value), list, stack); } stack.push(prop); }