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.
This commit is contained in:
Travis Watkins 2012-11-04 12:14:40 -06:00
parent 7f7192f8fd
commit 5a999a2660

View file

@ -131,10 +131,6 @@ public class ItemInWorldManager {
float f = 1.0F; float f = 1.0F;
int i1 = this.world.getTypeId(i, j, k); int i1 = this.world.getTypeId(i, j, k);
// CraftBukkit start - Swings at air do *NOT* exist. // CraftBukkit start - Swings at air do *NOT* exist.
if (i1 <= 0) {
return;
}
if (event.useInteractedBlock() == Event.Result.DENY) { 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 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) { if (i1 == Block.WOODEN_DOOR.id) {
@ -145,22 +141,25 @@ public class ItemInWorldManager {
} else if (i1 == Block.TRAP_DOOR.id) { } else if (i1 == Block.TRAP_DOOR.id) {
((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world)); ((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); Block.byId[i1].attack(this.world, i, j, k, this.player);
// Allow fire punching to be blocked // Allow fire punching to be blocked
this.world.douseFire((EntityHuman) null, i, j, k, l); this.world.douseFire((EntityHuman) null, i, j, k, l);
} }
// Handle hitting a block // 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 (event.useItemInHand() == Event.Result.DENY) {
// If we 'insta destroyed' then the client needs to be informed. // 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)); ((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world));
} }
return; 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()) { if (blockEvent.isCancelled()) {
// Let the client know the block still exists // Let the client know the block still exists
@ -169,11 +168,11 @@ public class ItemInWorldManager {
} }
if (blockEvent.getInstaBreak()) { if (blockEvent.getInstaBreak()) {
toolDamage = 2.0f; f = 2.0f;
} }
if (toolDamage >= 1.0F) {
// CraftBukkit end // CraftBukkit end
if (i1 > 0 && f >= 1.0F) {
this.breakBlock(i, j, k); this.breakBlock(i, j, k);
} else { } else {
this.d = true; this.d = true;