From 40e096273576ec5f0f49490f3167095d8678cbd8 Mon Sep 17 00:00:00 2001 From: feildmaster Date: Fri, 23 Mar 2012 06:08:54 -0500 Subject: [PATCH] Seriously fix natural drops. Fixes BUKKIT-1297 and fixes BUKKIT-1295 --- src/main/java/net/minecraft/server/Block.java | 19 ++++++++----------- .../net/minecraft/server/BlockDeadBush.java | 5 ++--- .../net/minecraft/server/BlockLeaves.java | 5 ++--- .../net/minecraft/server/BlockLongGrass.java | 5 ++--- .../server/BlockPistonExtension.java | 6 +++--- .../java/net/minecraft/server/BlockSnow.java | 7 +++---- .../java/net/minecraft/server/BlockVine.java | 2 +- .../java/net/minecraft/server/Explosion.java | 5 +++-- .../minecraft/server/ItemInWorldManager.java | 2 +- .../org/bukkit/craftbukkit/CraftWorld.java | 1 + .../bukkit/craftbukkit/block/CraftBlock.java | 5 +---- 11 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java index d61be04ca8..805caf9000 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; // CraftBukkit + protected ArrayList dropList = new ArrayList(); // CraftBukkit protected Block(int i, Material material) { this.bR = true; @@ -339,6 +339,7 @@ public class Block { public final void b(World world, int i, int j, int k, int l, int i1) { this.dropNaturally(world, i, j, k, l, 1.0F, i1); + this.doActualDrop(world, i, j, k); // CraftBukkit } public void dropNaturally(World world, int i, int j, int k, int l, float f, int i1) { @@ -360,15 +361,11 @@ public class Block { protected void a(World world, int i, int j, int k, ItemStack itemstack) { // CraftBukkit start - the logic of this function is moved into finishDrop - if (this.dropList != null) { - this.dropList.add(itemstack); - } else { - this.finishDrop(world, i, j, k, itemstack); - } + // This is such a hackish change it's rediculous. + this.dropList.add(itemstack); } public final void finishDrop(World world, int i, int j, int k, ItemStack itemstack) { - this.dropList = null; // CraftBukkit end if (!world.isStatic) { float f = 0.7F; @@ -542,13 +539,14 @@ public class Block { entityhuman.a(StatisticList.C[this.id], 1); entityhuman.c(0.025F); // CraftBukkit start - A way to separate statistics from the logic of determining what to drop - this.doActualDrop(world, entityhuman, i, j, k, l); + this.doActualDrop(world, i, j, k); } - public void doActualDrop(World world, EntityHuman entityhuman, int i, int j, int k, int l) { - for (ItemStack stack : dropList) { + public void doActualDrop(World world, int i, int j, int k) { + for (ItemStack stack : this.dropList) { finishDrop(world, i, j, k, stack); } + this.dropList.clear(); } public void setDrops(ArrayList drops) { @@ -556,7 +554,6 @@ public class Block { } public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { - this.dropList = new ArrayList(); // CraftBukkit end if (this.h() && EnchantmentManager.hasSilkTouchEnchantment(entityhuman.inventory)) { ItemStack itemstack = this.a_(l); diff --git a/src/main/java/net/minecraft/server/BlockDeadBush.java b/src/main/java/net/minecraft/server/BlockDeadBush.java index 7486f92eb9..60f53b8858 100644 --- a/src/main/java/net/minecraft/server/BlockDeadBush.java +++ b/src/main/java/net/minecraft/server/BlockDeadBush.java @@ -30,7 +30,7 @@ public class BlockDeadBush extends BlockFlower { /* CraftBukkit start - moved this line into calculateDrops this.a(world, i, j, k, new ItemStack(Block.DEAD_BUSH, 1, l)); */ - this.doActualDrop(world, entityhuman, i, j, k, l); + this.doActualDrop(world, i, j, k); // CraftBukkit end } else { super.a(world, entityhuman, i, j, k, l); @@ -40,9 +40,8 @@ public class BlockDeadBush extends BlockFlower { // 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.DEAD_BUSH, 1, l)); - return super.dropList; + return this.dropList; } else { return super.calculateDrops(world, entityhuman, i, j, k, l); } diff --git a/src/main/java/net/minecraft/server/BlockLeaves.java b/src/main/java/net/minecraft/server/BlockLeaves.java index 686f0f89d4..6345fafc1a 100644 --- a/src/main/java/net/minecraft/server/BlockLeaves.java +++ b/src/main/java/net/minecraft/server/BlockLeaves.java @@ -165,7 +165,7 @@ public class BlockLeaves extends BlockTransparant { /* CraftBukkit start - moved this line into calculateDrops this.a(world, i, j, k, new ItemStack(Block.LEAVES.id, 1, l & 3)); */ - this.doActualDrop(world, entityhuman, i, j, k, l); + this.doActualDrop(world, i, j, k); // CraftBukkit end } else { super.a(world, entityhuman, i, j, k, l); @@ -175,9 +175,8 @@ public class BlockLeaves extends BlockTransparant { // 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.LEAVES.id, 1, l & 3)); - return super.dropList; + return this.dropList; } else { return super.calculateDrops(world, entityhuman, i, j, k, l); } diff --git a/src/main/java/net/minecraft/server/BlockLongGrass.java b/src/main/java/net/minecraft/server/BlockLongGrass.java index 4a052a5a40..f98ae32718 100644 --- a/src/main/java/net/minecraft/server/BlockLongGrass.java +++ b/src/main/java/net/minecraft/server/BlockLongGrass.java @@ -30,7 +30,7 @@ public class BlockLongGrass extends BlockFlower { /* CraftBukkit start - moved this line into calculateDrops this.a(world, i, j, k, new ItemStack(Block.LONG_GRASS, 1, l)); */ - this.doActualDrop(world, entityhuman, i, j, k, l); + this.doActualDrop(world, i, j, k); // CraftBukkit end } else { super.a(world, entityhuman, i, j, k, l); @@ -40,9 +40,8 @@ public class BlockLongGrass extends BlockFlower { // 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.LONG_GRASS, 1, l)); - return super.dropList; + return this.dropList; } else { return super.calculateDrops(world, entityhuman, i, j, k, l); } diff --git a/src/main/java/net/minecraft/server/BlockPistonExtension.java b/src/main/java/net/minecraft/server/BlockPistonExtension.java index 28adc7f345..3ead3a4a39 100644 --- a/src/main/java/net/minecraft/server/BlockPistonExtension.java +++ b/src/main/java/net/minecraft/server/BlockPistonExtension.java @@ -17,7 +17,7 @@ public class BlockPistonExtension extends Block { public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int d) { super.calculateDrops(world, entityhuman, i, j, k, d); int l = world.getData(i, j, k) & 0x7; - if (l > 5 || l < 0) return super.dropList; + if (l > 5 || l < 0) return this.dropList; int i1 = Facing.OPPOSITE_FACING[b(l)]; i += Facing.b[i1]; @@ -26,9 +26,9 @@ public class BlockPistonExtension extends Block { int j1 = world.getTypeId(i, j, k); if (j1 == Block.PISTON.id || j1 == Block.PISTON_STICKY.id) { - super.dropList.add(new ItemStack(Block.byId[j1], 1)); + this.dropList.add(new ItemStack(Block.byId[j1], 1)); } - return super.dropList; + return this.dropList; } // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/BlockSnow.java b/src/main/java/net/minecraft/server/BlockSnow.java index 3c6cfe1597..ea63188a63 100644 --- a/src/main/java/net/minecraft/server/BlockSnow.java +++ b/src/main/java/net/minecraft/server/BlockSnow.java @@ -66,8 +66,8 @@ public class BlockSnow extends Block { entityitem.pickupDelay = 10; world.addEntity(entityitem); - // */ - super.doActualDrop(world, entityhuman, i, j, k, l); + */ + this.doActualDrop(world, i, j, k); // CraftBukkit end world.setTypeId(i, j, k, 0); entityhuman.a(StatisticList.C[this.id], 1); @@ -75,9 +75,8 @@ public class BlockSnow extends Block { // CraftBukkit start - Calculate drops public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { - super.dropList = new ArrayList(); this.a(world, i, j, k, new ItemStack(Item.SNOW_BALL.id, 1, 1)); - return super.dropList; + return this.dropList; } // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/BlockVine.java b/src/main/java/net/minecraft/server/BlockVine.java index 0fbdbb4997..2180dc179e 100644 --- a/src/main/java/net/minecraft/server/BlockVine.java +++ b/src/main/java/net/minecraft/server/BlockVine.java @@ -290,7 +290,7 @@ public class BlockVine extends Block { /* CraftBukkit start - moved this line into calculateDrops this.a(world, i, j, k, new ItemStack(Block.VINE, 1, 0)); */ - this.doActualDrop(world, entityhuman, i, j, k, l); + this.doActualDrop(world, i, j, k); // CraftBukkit end } else { super.a(world, entityhuman, i, j, k, l); diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java index e4ba32070e..d00d42329b 100644 --- a/src/main/java/net/minecraft/server/Explosion.java +++ b/src/main/java/net/minecraft/server/Explosion.java @@ -243,10 +243,11 @@ public class Explosion { this.world.a("smoke", d0, d1, d2, d3, d4, d5); } - // CraftBukkit - stop explosions from putting out fire + // CraftBukkit start - stop explosions from putting out fire if (i1 > 0 && i1 != Block.FIRE.id) { - // CraftBukkit Block.byId[i1].dropNaturally(this.world, j, k, l, this.world.getData(j, k, l), event.getYield(), 0); + Block.byId[i1].doActualDrop(this.world, j, k, l); + // CraftBukkit end this.world.setTypeId(j, k, l, 0); Block.byId[i1].wasExploded(this.world, j, k, l); } diff --git a/src/main/java/net/minecraft/server/ItemInWorldManager.java b/src/main/java/net/minecraft/server/ItemInWorldManager.java index 8a3ece842c..fbaf45ba85 100644 --- a/src/main/java/net/minecraft/server/ItemInWorldManager.java +++ b/src/main/java/net/minecraft/server/ItemInWorldManager.java @@ -218,7 +218,7 @@ public class ItemInWorldManager { if (this.isCreative()) { // CraftBukkit start - honour additions to drop list - Block.byId[l].doActualDrop(this.world, this.player, i, j, k, i1); + Block.byId[l].doActualDrop(this.world, i, j, k); // CraftBukkit end ((EntityPlayer) this.player).netServerHandler.sendPacket(new Packet53BlockChange(i, j, k, this.world)); } else { diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 25967d9126..602f806f1d 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1056,6 +1056,7 @@ public class CraftWorld implements World { int blockZ = block.getZ(); // following code is lifted from Explosion.a(boolean), and modified net.minecraft.server.Block.byId[blockId].dropNaturally(this.world, blockX, blockY, blockZ, block.getData(), yield, 0); + net.minecraft.server.Block.byId[blockId].doActualDrop(this.world, blockX, blockY, blockZ); block.setType(org.bukkit.Material.AIR); // not sure what this does, seems to have something to do with the 'base' material of a block. // For example, WOODEN_STAIRS does something with WOOD in this method diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java index b667b21dd0..6e89ef4de9 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -348,10 +348,7 @@ public class CraftBlock implements Block { setTypeId(Material.AIR.getId()); if (block != null) { - block.dropNaturally(chunk.getHandle().world, x, y, z, data, 1.0F, 0); - for (ItemStack item : getDrops()) { - block.finishDrop(chunk.getHandle().world, x, y, z, CraftItemStack.createNMSItemStack(item)); - } + block.b(chunk.getHandle().world, x, y, z, data, 0); return true; } return false;