From 5a999a26608572df6b3ed461c3f6c95129de484a Mon Sep 17 00:00:00 2001 From: Travis Watkins Date: Sun, 4 Nov 2012 12:14:40 -0600 Subject: Correct digging behavior. Fixes BUKKIT-2780 If a block is air we return immediately so miss the cleanup work that would normally happen in this case in vanilla. This causes us to get in to a situation where, due to odd packet sending from the client, we never properly stop an attempt by the client to break a block and thus it eventually breaks. We also use our own variable for block damage and never sync it up with the vanilla one so damage reporting to other clients is not always correct. --- .../net/minecraft/server/ItemInWorldManager.java | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/main') diff --git a/src/main/java/net/minecraft/server/ItemInWorldManager.java b/src/main/java/net/minecraft/server/ItemInWorldManager.java index 78ab6f26..389a3ed9 100644 --- a/src/main/java/net/minecraft/server/ItemInWorldManager.java +++ b/src/main/java/net/minecraft/server/ItemInWorldManager.java @@ -131,10 +131,6 @@ public class ItemInWorldManager { float f = 1.0F; int i1 = this.world.getTypeId(i, j, k); // CraftBukkit start - Swings at air do *NOT* exist. - if (i1 <= 0) { - return; - } - if (event.useInteractedBlock() == Event.Result.DENY) { // If we denied a door from opening, we need to send a correcting update to the client, as it already opened the door. if (i1 == Block.WOODEN_DOOR.id) { @@ -145,22 +141,25 @@ public class ItemInWorldManager { } else if (i1 == Block.TRAP_DOOR.id) { ((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world)); } - } else { + } else if (i1 > 0) { Block.byId[i1].attack(this.world, i, j, k, this.player); // Allow fire punching to be blocked this.world.douseFire((EntityHuman) null, i, j, k, l); } // Handle hitting a block - float toolDamage = Block.byId[i1].getDamage(this.player, this.world, i, j, k); + if (i1 > 0) { + f = Block.byId[i1].getDamage(this.player, this.world, i, j, k); + } + if (event.useItemInHand() == Event.Result.DENY) { // If we 'insta destroyed' then the client needs to be informed. - if (toolDamage > 1.0f) { + if (f > 1.0f) { ((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world)); } return; } - org.bukkit.event.block.BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, i, j, k, this.player.inventory.getItemInHand(), toolDamage >= 1.0f); + org.bukkit.event.block.BlockDamageEvent blockEvent = CraftEventFactory.callBlockDamageEvent(this.player, i, j, k, this.player.inventory.getItemInHand(), f >= 1.0f); if (blockEvent.isCancelled()) { // Let the client know the block still exists @@ -169,11 +168,11 @@ public class ItemInWorldManager { } if (blockEvent.getInstaBreak()) { - toolDamage = 2.0f; + f = 2.0f; } + // CraftBukkit end - if (toolDamage >= 1.0F) { - // CraftBukkit end + if (i1 > 0 && f >= 1.0F) { this.breakBlock(i, j, k); } else { this.d = true; -- cgit v1.2.3