diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java index 434309516f..3244351d7c 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; - public ArrayList dropList = new ArrayList(1); // CraftBukkit + public final ArrayList dropList = new ArrayList(1); // CraftBukkit protected Block(int i, Material material) { this.bR = true; @@ -362,7 +362,7 @@ 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 - // This is such a hackish change it's rediculous. + // This is such a hackish change it's ridiculous. this.dropList.add(itemstack); } @@ -550,6 +550,7 @@ public class Block { this.dropList.clear(); } + // Blocks that have different drops in certain situations need to override this. IE: Sheers on BlockLeaves public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { // CraftBukkit end if (this.h() && EnchantmentManager.hasSilkTouchEnchantment(entityhuman.inventory)) { @@ -563,7 +564,8 @@ public class Block { this.dropNaturally(world, i, j, k, l, 1.0F, i1); // CraftBukkit } - return this.dropList; // CraftBukkit + + return this.dropList; } protected boolean h() { diff --git a/src/main/java/net/minecraft/server/BlockDeadBush.java b/src/main/java/net/minecraft/server/BlockDeadBush.java index 60f53b8858..fdb4573fc9 100644 --- a/src/main/java/net/minecraft/server/BlockDeadBush.java +++ b/src/main/java/net/minecraft/server/BlockDeadBush.java @@ -1,6 +1,5 @@ package net.minecraft.server; -import java.util.ArrayList; // CraftBukkit import java.util.Random; public class BlockDeadBush extends BlockFlower { @@ -38,13 +37,13 @@ public class BlockDeadBush extends BlockFlower { } // CraftBukkit start - Calculate drops - public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { + public java.util.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) { this.a(world, i, j, k, new ItemStack(Block.DEAD_BUSH, 1, l)); - return this.dropList; } else { return super.calculateDrops(world, entityhuman, i, j, k, l); } + return this.dropList; } // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/BlockLeaves.java b/src/main/java/net/minecraft/server/BlockLeaves.java index 6345fafc1a..02b7ab1237 100644 --- a/src/main/java/net/minecraft/server/BlockLeaves.java +++ b/src/main/java/net/minecraft/server/BlockLeaves.java @@ -1,6 +1,5 @@ package net.minecraft.server; -import java.util.ArrayList; // CraftBukkit import java.util.Random; import org.bukkit.event.block.LeavesDecayEvent; // CraftBukkit @@ -173,13 +172,13 @@ public class BlockLeaves extends BlockTransparant { } // CraftBukkit start - Calculate drops - public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { + public java.util.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) { this.a(world, i, j, k, new ItemStack(Block.LEAVES.id, 1, l & 3)); - return this.dropList; } else { return super.calculateDrops(world, entityhuman, i, j, k, l); } + return this.dropList; } // CraftBukkit end diff --git a/src/main/java/net/minecraft/server/BlockLongGrass.java b/src/main/java/net/minecraft/server/BlockLongGrass.java index f98ae32718..391407bf46 100644 --- a/src/main/java/net/minecraft/server/BlockLongGrass.java +++ b/src/main/java/net/minecraft/server/BlockLongGrass.java @@ -1,6 +1,5 @@ package net.minecraft.server; -import java.util.ArrayList; // CraftBukkit import java.util.Random; public class BlockLongGrass extends BlockFlower { @@ -38,13 +37,13 @@ public class BlockLongGrass extends BlockFlower { } // CraftBukkit start - Calculate drops - public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { + public java.util.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) { this.a(world, i, j, k, new ItemStack(Block.LONG_GRASS, 1, l)); - return this.dropList; } else { return super.calculateDrops(world, entityhuman, i, j, k, l); } + return this.dropList; } // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/BlockPistonExtension.java b/src/main/java/net/minecraft/server/BlockPistonExtension.java index 3ead3a4a39..0cb2fa38d8 100644 --- a/src/main/java/net/minecraft/server/BlockPistonExtension.java +++ b/src/main/java/net/minecraft/server/BlockPistonExtension.java @@ -14,7 +14,7 @@ public class BlockPistonExtension extends Block { } // CraftBukkit start - Support getDrops() in BlockBreakEvent - public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int d) { + public java.util.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 this.dropList; diff --git a/src/main/java/net/minecraft/server/BlockSnow.java b/src/main/java/net/minecraft/server/BlockSnow.java index ea63188a63..24c52a3530 100644 --- a/src/main/java/net/minecraft/server/BlockSnow.java +++ b/src/main/java/net/minecraft/server/BlockSnow.java @@ -1,6 +1,5 @@ package net.minecraft.server; -import java.util.ArrayList; // CraftBukkit import java.util.Random; import org.bukkit.craftbukkit.event.CraftEventFactory; @@ -74,7 +73,7 @@ public class BlockSnow extends Block { } // CraftBukkit start - Calculate drops - public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { + public java.util.ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { this.a(world, i, j, k, new ItemStack(Item.SNOW_BALL.id, 1, 1)); return this.dropList; } diff --git a/src/main/java/net/minecraft/server/BlockTNT.java b/src/main/java/net/minecraft/server/BlockTNT.java index 3aaf8c6d98..9a1f03983f 100644 --- a/src/main/java/net/minecraft/server/BlockTNT.java +++ b/src/main/java/net/minecraft/server/BlockTNT.java @@ -1,6 +1,5 @@ package net.minecraft.server; -import java.util.ArrayList; // CraftBukkit import java.util.Random; public class BlockTNT extends Block { @@ -57,7 +56,7 @@ public class BlockTNT extends Block { } // CraftBukkit start - Calculate drops - public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { + public java.util.ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { if ((l & 1) == 0) { this.a(world, i, j, k, new ItemStack(Block.TNT.id, 1, 0)); } diff --git a/src/main/java/net/minecraft/server/BlockVine.java b/src/main/java/net/minecraft/server/BlockVine.java index 93d8876b27..816d67347c 100644 --- a/src/main/java/net/minecraft/server/BlockVine.java +++ b/src/main/java/net/minecraft/server/BlockVine.java @@ -1,6 +1,5 @@ package net.minecraft.server; -import java.util.ArrayList; // CraftBukkit import java.util.Random; public class BlockVine extends Block { @@ -298,13 +297,13 @@ public class BlockVine extends Block { } // CraftBukkit start - Calculate drops - public ArrayList calculateDrops(World world, EntityHuman entityhuman, int i, int j, int k, int l) { + public java.util.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) { this.a(world, i, j, k, new ItemStack(Block.VINE, 1, 0)); - return this.dropList; } else { return super.calculateDrops(world, entityhuman, i, j, k, l); } + return this.dropList; } // CraftBukkit end } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 243c3339a3..91b60add35 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -1,8 +1,6 @@ package org.bukkit.craftbukkit.event; import java.net.InetAddress; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -18,7 +16,6 @@ import net.minecraft.server.EntityItem; import net.minecraft.server.EntityLiving; import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntityPotion; -import net.minecraft.server.IInventory; import net.minecraft.server.InventoryCrafting; import net.minecraft.server.Item; import net.minecraft.server.ItemStack; @@ -512,12 +509,13 @@ public class CraftEventFactory { return event; } + private static final List drops = new java.util.ArrayList(); + public static boolean callBlockBreakEvent(World world, int x, int y, int z, int id, int data, boolean creative, EntityHuman player) { net.minecraft.server.Block blockType = net.minecraft.server.Block.byId[id]; if (blockType == null) { // Illegal block ID return true; } - Block block = world.getWorld().getBlockAt(x, y, z); // Tell client the block is gone immediately then process events if (world.getTileEntity(x, y, z) == null) { @@ -528,10 +526,12 @@ public class CraftEventFactory { ((EntityPlayer) player).netServerHandler.sendPacket(packet); } - List calculatedDrops = blockType.calculateDrops(world, player, x, y, z, data); - List drops = new ArrayList(calculatedDrops.size()); + Block block = world.getWorld().getBlockAt(x, y, z); + List toDrop = blockType.calculateDrops(world, player, x, y, z, data); + drops.clear(); + if (!creative && player.b(blockType)) { - for (ItemStack stack : calculatedDrops) { + for (ItemStack stack : toDrop) { drops.add(new CraftItemStack(stack)); } } @@ -540,17 +540,16 @@ public class CraftEventFactory { world.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { - blockType.dropList.clear(); + toDrop.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(drops.size()); + toDrop.clear(); for (org.bukkit.inventory.ItemStack stack : drops) { toDrop.add(CraftItemStack.createNMSItemStack(stack)); } - blockType.dropList = toDrop; return false; // Event not cancelled }