From 16f628984492769d15eb4d15ca0ce96e07a1316b Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Sat, 23 Apr 2016 16:02:02 -0500 Subject: [PATCH] Fix dupe dropping with psi. Closes #250 --- .../common/block/BlockCacophonium.java | 19 +++++++++++--- .../block/BlockFloatingSpecialFlower.java | 24 +++++++++++++++--- .../common/block/BlockSpecialFlower.java | 25 ++++++++++++++++--- .../common/block/decor/BlockTinyPotato.java | 19 +++++++++++--- 4 files changed, 73 insertions(+), 14 deletions(-) diff --git a/src/main/java/vazkii/botania/common/block/BlockCacophonium.java b/src/main/java/vazkii/botania/common/block/BlockCacophonium.java index dab8219cf..4d83eab05 100644 --- a/src/main/java/vazkii/botania/common/block/BlockCacophonium.java +++ b/src/main/java/vazkii/botania/common/block/BlockCacophonium.java @@ -76,9 +76,22 @@ public class BlockCacophonium extends BlockMod { } @Override - public void onBlockHarvested(World par1World, BlockPos pos, IBlockState state, EntityPlayer par6EntityPlayer) { - if(!par6EntityPlayer.capabilities.isCreativeMode) - dropBlockAsItem(par1World, pos, state, 0); + public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { + if (willHarvest) { + // Copy of super.removedByPlayer but don't set to air yet + // This is so getDrops below will have a TE to work with + onBlockHarvested(world, pos, state, player); + return true; + } else { + return super.removedByPlayer(state, world, pos, player, willHarvest); + } + } + + @Override + public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack stack) { + super.harvestBlock(world, player, pos, state, te, stack); + // Now delete the block and TE + world.setBlockToAir(pos); } @Override diff --git a/src/main/java/vazkii/botania/common/block/BlockFloatingSpecialFlower.java b/src/main/java/vazkii/botania/common/block/BlockFloatingSpecialFlower.java index 632483c33..12d889143 100644 --- a/src/main/java/vazkii/botania/common/block/BlockFloatingSpecialFlower.java +++ b/src/main/java/vazkii/botania/common/block/BlockFloatingSpecialFlower.java @@ -138,13 +138,29 @@ public class BlockFloatingSpecialFlower extends BlockFloatingFlower implements I } @Override - public void onBlockHarvested(World par1World, BlockPos pos, IBlockState state, EntityPlayer par6EntityPlayer) { - if(!par6EntityPlayer.capabilities.isCreativeMode) { - dropBlockAsItem(par1World, pos, state, 0); - ((TileSpecialFlower) par1World.getTileEntity(pos)).onBlockHarvested(par1World, pos, state, par6EntityPlayer); + public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player) { + ((TileSpecialFlower) world.getTileEntity(pos)).onBlockHarvested(world, pos, state, player); + } + + @Override + public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { + if (willHarvest) { + // Copy of super.removedByPlayer but don't set to air yet + // This is so getDrops below will have a TE to work with + onBlockHarvested(world, pos, state, player); + return true; + } else { + return super.removedByPlayer(state, world, pos, player, willHarvest); } } + @Override + public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack stack) { + super.harvestBlock(world, player, pos, state, te, stack); + // Now delete the block and TE + world.setBlockToAir(pos); + } + @Override public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { ArrayList list = new ArrayList<>(); diff --git a/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java b/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java index acf05da63..53ba12318 100644 --- a/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java +++ b/src/main/java/vazkii/botania/common/block/BlockSpecialFlower.java @@ -233,13 +233,29 @@ public class BlockSpecialFlower extends BlockFlower implements ISpecialFlower, I } @Override - public void onBlockHarvested(World par1World, BlockPos pos, IBlockState state, EntityPlayer par6EntityPlayer) { - if(!par6EntityPlayer.capabilities.isCreativeMode) { - dropBlockAsItem(par1World, pos, state, 0); - ((TileSpecialFlower) par1World.getTileEntity(pos)).onBlockHarvested(par1World, pos, state, par6EntityPlayer); + public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player) { + ((TileSpecialFlower) world.getTileEntity(pos)).onBlockHarvested(world, pos, state, player); + } + + @Override + public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { + if (willHarvest) { + // Copy of super.removedByPlayer but don't set to air yet + // This is so getDrops below will have a TE to work with + onBlockHarvested(world, pos, state, player); + return true; + } else { + return super.removedByPlayer(state, world, pos, player, willHarvest); } } + @Override + public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack stack) { + super.harvestBlock(world, player, pos, state, te, stack); + // Now delete the block and TE + world.setBlockToAir(pos); + } + @Override public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { ArrayList list = new ArrayList<>(); @@ -298,6 +314,7 @@ public class BlockSpecialFlower extends BlockFlower implements ISpecialFlower, I EnumDyeColor oldColor = state.getValue(BotaniaStateProps.COLOR); if(newColor != oldColor) world.setBlockState(pos, state.withProperty(BotaniaStateProps.COLOR, newColor), 1 | 2); + return true; } return ((TileSpecialFlower) world.getTileEntity(pos)).onBlockActivated(world, pos, state, player, hand, stack, side, hitX, hitY, hitZ); diff --git a/src/main/java/vazkii/botania/common/block/decor/BlockTinyPotato.java b/src/main/java/vazkii/botania/common/block/decor/BlockTinyPotato.java index 11a25a437..832e318b1 100644 --- a/src/main/java/vazkii/botania/common/block/decor/BlockTinyPotato.java +++ b/src/main/java/vazkii/botania/common/block/decor/BlockTinyPotato.java @@ -110,9 +110,22 @@ public class BlockTinyPotato extends BlockMod implements ILexiconable { } @Override - public void onBlockHarvested(World par1World, BlockPos pos, IBlockState state, EntityPlayer par6EntityPlayer) { - if(!par6EntityPlayer.capabilities.isCreativeMode) - dropBlockAsItem(par1World, pos, state, 0); + public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { + if (willHarvest) { + // Copy of super.removedByPlayer but don't set to air yet + // This is so getDrops below will have a TE to work with + onBlockHarvested(world, pos, state, player); + return true; + } else { + return super.removedByPlayer(state, world, pos, player, willHarvest); + } + } + + @Override + public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack stack) { + super.harvestBlock(world, player, pos, state, te, stack); + // Now delete the block and TE + world.setBlockToAir(pos); } @Override