diff --git a/src/main/java/biomesoplenty/common/block/BlockBOPDoublePlant.java b/src/main/java/biomesoplenty/common/block/BlockBOPDoublePlant.java index 598087514..681db8221 100644 --- a/src/main/java/biomesoplenty/common/block/BlockBOPDoublePlant.java +++ b/src/main/java/biomesoplenty/common/block/BlockBOPDoublePlant.java @@ -18,8 +18,10 @@ 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.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.IStringSerializable; import net.minecraft.world.ColorizerFoliage; @@ -208,31 +210,35 @@ public class BlockBOPDoublePlant extends BlockDoubleDecoration implements IShear // 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 ((DoublePlantType) lowerState.getValue(VARIANT)) + // add items based on the VARIANT - default is to drop (lower) block + DoublePlantType type = (DoublePlantType) lowerState.getValue(VARIANT); + switch (type) { case FLAX: - if (rand.nextInt(8) == 0) - { - // 1 in 8 chance of getting a seed from this grass - ret.add(ForgeHooks.getGrassSeed(rand)); - } - - default: + // drop flax plant and also 1 in 8 chance of getting a seed + ret.add(this.getVariantItem(type)); + if (rand.nextInt(8) == 0) {ret.add(ForgeHooks.getGrassSeed(rand));} + + case TALL_CATTAIL: break; + + case EYEBULB: default: + // drop self + ret.add(this.getVariantItem(type)); } return ret; } @Override - public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos) { + public boolean isShearable(ItemStack item, IBlockAccess world, BlockPos pos) + { return true; } @@ -242,12 +248,17 @@ public class BlockBOPDoublePlant extends BlockDoubleDecoration implements IShear List ret = new java.util.ArrayList(); // add items based on the VARIANT + // note that the sheared items are dropped in addition to regular drops + // since the default in getLowerDrops is to drop the (lower) block, the default here is to drop nothing (so we don't have a duplicate) + // at the moment, this code is pretty useless, but if in the future we add a double block which can't be collected except with shears + // then a case will need to be inserted for it in the switch below DoublePlantType type = (DoublePlantType) lowerState.getValue(VARIANT); switch (type) { - default: - // default is to get the (lower) block unaltered + case TALL_CATTAIL: ret.add(this.getVariantItem(type)); + default: + break; } return ret; } diff --git a/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java b/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java index d51a4b14c..fe998e83a 100644 --- a/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java +++ b/src/main/java/biomesoplenty/common/block/BlockDoubleDecoration.java @@ -115,7 +115,7 @@ public class BlockDoubleDecoration extends BlockDecoration { // 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; @@ -187,14 +187,17 @@ public class BlockDoubleDecoration extends BlockDecoration { // handle drops from UPPER and LOWER separately @Override public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) - { + { + // note it is important to use the state as provided and NOT world.getBlockState(pos) + // because when this function is called, the block may have already been turned to air + // the state provided is the state before the block was destroyed if (state.getValue(HALF) == Half.UPPER) { - return this.getUpperDrops(world, this.getUpperPos(world, pos), this.getUpperState(world, pos), fortune); + return this.getUpperDrops(world, pos, state, fortune); } else { - return this.getLowerDrops(world, this.getLowerPos(world, pos), this.getLowerState(world, pos), fortune); + return this.getLowerDrops(world, pos, state, fortune); } } @@ -209,27 +212,21 @@ public class BlockDoubleDecoration extends BlockDecoration { } // 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) { - + public List onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) { List drops = new java.util.ArrayList(); if (!this.isValidDoubleBlock(world, pos)) {return drops;} 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) { + 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) { + public List getLowerShearDrops(ItemStack item, IBlockAccess world, BlockPos lowerPos, IBlockState lowerState, int fortune) + { return super.getDrops(world, lowerPos, lowerState, fortune); }