From c30e339af6dd7594cca7e0c1ca31f0ea34a0afa9 Mon Sep 17 00:00:00 2001 From: feildmaster Date: Sun, 25 Mar 2012 17:53:59 -0500 Subject: [PATCH] [Bleeding] Fixed item duping in certain occasions. Fixes BUKKIT-1310 --- src/main/java/net/minecraft/server/Block.java | 7 ++----- src/main/java/net/minecraft/server/BlockVine.java | 3 +-- .../bukkit/craftbukkit/event/CraftEventFactory.java | 11 ++++++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java index 7b3962a7a8..434309516f 100644 --- a/src/main/java/net/minecraft/server/Block.java +++ b/src/main/java/net/minecraft/server/Block.java @@ -164,7 +164,7 @@ public class Block { public final Material material; public float frictionFactor; private String name; - protected ArrayList dropList = new ArrayList(); // CraftBukkit + public ArrayList dropList = new ArrayList(1); // CraftBukkit protected Block(int i, Material material) { this.bR = true; @@ -338,6 +338,7 @@ public class Block { } public final void b(World world, int i, int j, int k, int l, int i1) { + this.dropList.clear(); // CraftBukkit this.dropNaturally(world, i, j, k, l, 1.0F, i1); this.doActualDrop(world, i, j, k); // CraftBukkit } @@ -549,10 +550,6 @@ public class Block { this.dropList.clear(); } - public void setDrops(ArrayList drops) { - this.dropList = drops; - } - public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { // CraftBukkit end if (this.h() && EnchantmentManager.hasSilkTouchEnchantment(entityhuman.inventory)) { diff --git a/src/main/java/net/minecraft/server/BlockVine.java b/src/main/java/net/minecraft/server/BlockVine.java index 2180dc179e..93d8876b27 100644 --- a/src/main/java/net/minecraft/server/BlockVine.java +++ b/src/main/java/net/minecraft/server/BlockVine.java @@ -300,9 +300,8 @@ public class BlockVine extends Block { // CraftBukkit start - Calculate drops public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { if (!world.isStatic && entityhuman.U() != null && entityhuman.U().id == Item.SHEARS.id) { - super.dropList = new ArrayList(); this.a(world, i, j, k, new ItemStack(Block.VINE, 1, 0)); - return super.dropList; + return this.dropList; } else { return super.calculateDrops(world, entityhuman, i, j, k, l); } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 39f01117f6..243c3339a3 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -528,9 +528,10 @@ public class CraftEventFactory { ((EntityPlayer) player).netServerHandler.sendPacket(packet); } - List drops = new ArrayList(); + List calculatedDrops = blockType.calculateDrops(world, player, x, y, z, data); + List drops = new ArrayList(calculatedDrops.size()); if (!creative && player.b(blockType)) { - for (ItemStack stack : blockType.calculateDrops(world, player, x, y, z, data)) { + for (ItemStack stack : calculatedDrops) { drops.add(new CraftItemStack(stack)); } } @@ -539,17 +540,17 @@ public class CraftEventFactory { world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { - blockType.setDrops(new ArrayList()); + blockType.dropList.clear(); // Let the client know the block still exists ((EntityPlayer) player).netServerHandler.sendPacket(new Packet53BlockChange(x, y, z, world)); return true; } - ArrayList toDrop = new ArrayList(); + ArrayList toDrop = new ArrayList(drops.size()); for (org.bukkit.inventory.ItemStack stack : drops) { toDrop.add(CraftItemStack.createNMSItemStack(stack)); } - blockType.setDrops(toDrop); + blockType.dropList = toDrop; return false; // Event not cancelled }