From 29f72ed3573513d7dac7ecbf5ff5710b7d7ec0df Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Wed, 17 Sep 2014 15:59:28 +0200 Subject: [PATCH] Make AOE tools creative-mode compatible again --- .../library/tools/AOEHarvestTool.java | 5 +- .../tconstruct/library/tools/HarvestTool.java | 47 ++++++++++++------- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/main/java/tconstruct/library/tools/AOEHarvestTool.java b/src/main/java/tconstruct/library/tools/AOEHarvestTool.java index e4410cbc60f..a79748aefbd 100644 --- a/src/main/java/tconstruct/library/tools/AOEHarvestTool.java +++ b/src/main/java/tconstruct/library/tools/AOEHarvestTool.java @@ -48,7 +48,7 @@ public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPla } // the code below initiates block breaks, which again call this function. But we don't want to do the aoe-break-stuff again. This is to prevent recursive, infinite-range aoe blockbreaking. - if(originalBlock) { + if(originalBlock || player.capabilities.isCreativeMode) { antiRecurse = true; MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(player.worldObj, player, false, 4.5d); if(mop == null) @@ -89,6 +89,9 @@ public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPla antiRecurse = false; } + + + return super.onBlockStartBreak(stack, x, y, z, player); } diff --git a/src/main/java/tconstruct/library/tools/HarvestTool.java b/src/main/java/tconstruct/library/tools/HarvestTool.java index bbdb05e6fcb..ff67101374b 100644 --- a/src/main/java/tconstruct/library/tools/HarvestTool.java +++ b/src/main/java/tconstruct/library/tools/HarvestTool.java @@ -215,39 +215,50 @@ public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int return used; } - protected void breakExtraBlock(World world, int x, int y, int z, int sidehit, EntityPlayer player) - { + protected void breakExtraBlock(World world, int x, int y, int z, int sidehit, EntityPlayer player) { // prevent calling that stuff for air blocks, could lead to unexpected behaviour since it fires events - if(world.isAirBlock(x,y,z)) + if (world.isAirBlock(x, y, z)) return; // check if the block can be broken, since extra block breaks shouldn't instantly break stuff like obsidian // or precious ores you can't harvest while mining stone - Block block = world.getBlock(x,y,z); - int meta = world.getBlockMetadata(x,y,z); + Block block = world.getBlock(x, y, z); + int meta = world.getBlockMetadata(x, y, z); // only effective materials - if(!isEffective(block.getMaterial())) + if (!isEffective(block.getMaterial())) return; // only harvestable blocks that aren't impossibly slow to harvest - if(!ForgeHooks.canHarvestBlock(block, player, meta) || ForgeHooks.blockStrength(block, player, world, x,y,z) <= 0.0001f) + if (!ForgeHooks.canHarvestBlock(block, player, meta) || ForgeHooks.blockStrength(block, player, world, x, y, z) <= 0.0001f) return; - // this should only be called on the client - if(!world.isRemote) { + if (player.capabilities.isCreativeMode) { + block.onBlockHarvested(world, x, y, z, meta, player); + if (block.removedByPlayer(world, player, x, y, z, false)) + block.onBlockDestroyedByPlayer(world, x, y, z, meta); + + // send update to client + if (!world.isRemote) { + ((EntityPlayerMP)player).playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); + } + return; + } + // server sided handling + if (!world.isRemote) { // serverside we EntityPlayerMP mpPlayer = (EntityPlayerMP) player; - mpPlayer.theItemInWorldManager.tryHarvestBlock(x,y,z); + + mpPlayer.theItemInWorldManager.tryHarvestBlock(x, y, z); // send block update to client mpPlayer.playerNetServerHandler.sendPacket(new S23PacketBlockChange(x, y, z, world)); - return; } - - // and this is the reason why ;o - PlayerControllerMP pcmp = Minecraft.getMinecraft().playerController; - // clientside we do a "this clock has been clicked on long enough to be broken" call. This should not send any new packets - // the code above, executed on the server, sends a block-updates that give us the correct state of the block we destroy. - pcmp.onPlayerDestroyBlock(x, y, z, sidehit); + // client sided handling + else { + PlayerControllerMP pcmp = Minecraft.getMinecraft().playerController; + // clientside we do a "this clock has been clicked on long enough to be broken" call. This should not send any new packets + // the code above, executed on the server, sends a block-updates that give us the correct state of the block we destroy. + pcmp.onPlayerDestroyBlock(x, y, z, sidehit); + } } -} +} \ No newline at end of file