From a575e6b075ec9e63e942111657d6869e00ad42b5 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Thu, 8 Nov 2012 00:26:35 +0000 Subject: [PATCH] Use correct itemstack for dispenser behavior chaining. Fixes BUKKIT-2886 When an event changes the item to be dispensed we check to see if the new item has special behavior for dispensing and if so pass it on to that behavior handler. However, we are actually checking the old itemstack and passing the new itemstack so this check fails. --- .../server/DispenseBehaviorBoat.java | 5 ++-- .../server/DispenseBehaviorEmptyBucket.java | 5 ++-- .../server/DispenseBehaviorFilledBucket.java | 5 ++-- .../server/DispenseBehaviorFireball.java | 5 ++-- .../server/DispenseBehaviorItem.java | 23 ++++++------------- .../server/DispenseBehaviorMinecart.java | 5 ++-- .../server/DispenseBehaviorMonsterEgg.java | 5 ++-- .../server/DispenseBehaviorProjectile.java | 3 ++- 8 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorBoat.java b/src/main/java/net/minecraft/server/DispenseBehaviorBoat.java index 2cb9e3d0ea..dfaf09ed4d 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorBoat.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorBoat.java @@ -56,9 +56,10 @@ public class DispenseBehaviorBoat extends DispenseBehaviorItem { if (!event.getItem().equals(bukkitItem)) { itemstack.count++; // Chain to handler for new item - IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem()); + ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { - idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem())); + idispensebehavior.a(isourceblock, eventStack); return itemstack; } } diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorEmptyBucket.java b/src/main/java/net/minecraft/server/DispenseBehaviorEmptyBucket.java index 6e29c260d9..31348bd6fe 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorEmptyBucket.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorEmptyBucket.java @@ -51,9 +51,10 @@ public class DispenseBehaviorEmptyBucket extends DispenseBehaviorItem { if (!event.getItem().equals(bukkitItem)) { // Chain to handler for new item - IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem()); + ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { - idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem())); + idispensebehavior.a(isourceblock, eventStack); return itemstack; } } diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorFilledBucket.java b/src/main/java/net/minecraft/server/DispenseBehaviorFilledBucket.java index 28bedc9a1d..8f1d9a84f9 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorFilledBucket.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorFilledBucket.java @@ -42,9 +42,10 @@ public class DispenseBehaviorFilledBucket extends DispenseBehaviorItem { if (!event.getItem().equals(bukkitItem)) { // Chain to handler for new item - IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem()); + ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { - idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem())); + idispensebehavior.a(isourceblock, eventStack); return itemstack; } } diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorFireball.java b/src/main/java/net/minecraft/server/DispenseBehaviorFireball.java index 0824fc4f22..cc0bf8bb34 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorFireball.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorFireball.java @@ -45,9 +45,10 @@ public class DispenseBehaviorFireball extends DispenseBehaviorItem { if (!event.getItem().equals(bukkitItem)) { itemstack.count++; // Chain to handler for new item - IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem()); + ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { - idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem())); + idispensebehavior.a(isourceblock, eventStack); return itemstack; } } diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorItem.java b/src/main/java/net/minecraft/server/DispenseBehaviorItem.java index 9cf23dd96c..1337fefe0a 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorItem.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorItem.java @@ -65,30 +65,21 @@ public class DispenseBehaviorItem implements IDispenseBehavior { entityitem.motX = event.getVelocity().getX(); entityitem.motY = event.getVelocity().getY(); entityitem.motZ = event.getVelocity().getZ(); - // CraftBukkit end - world.addEntity(entityitem); - - // CraftBukkit start if (!event.getItem().equals(bukkitItem)) { - if (event.getItem().getTypeId() == Item.BUCKET.id) { - int x = isourceblock.getBlockX() + enumfacing.c(); - int y = isourceblock.getBlockY(); - int z = isourceblock.getBlockZ() + enumfacing.e(); - Material material = world.getMaterial(x, y, z); - int data = world.getData(x, y, z); - if (!(Material.WATER.equals(material) || Material.LAVA.equals(material)) || data != 0) { - return true; - } - } // Chain to handler for new item - IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem()); + ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior.getClass() != DispenseBehaviorItem.class) { - idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem())); + idispensebehavior.a(isourceblock, eventStack); + } else { + world.addEntity(entityitem); } return false; } + world.addEntity(entityitem); + return true; // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorMinecart.java b/src/main/java/net/minecraft/server/DispenseBehaviorMinecart.java index c429abe997..cc92846ea4 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorMinecart.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorMinecart.java @@ -56,9 +56,10 @@ public class DispenseBehaviorMinecart extends DispenseBehaviorItem { if (!event.getItem().equals(bukkitItem)) { itemstack.count++; // Chain to handler for new item - IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem()); + ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { - idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem())); + idispensebehavior.a(isourceblock, eventStack); return itemstack; } } diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorMonsterEgg.java b/src/main/java/net/minecraft/server/DispenseBehaviorMonsterEgg.java index 4895b81c96..25e21d25bd 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorMonsterEgg.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorMonsterEgg.java @@ -38,9 +38,10 @@ public class DispenseBehaviorMonsterEgg extends DispenseBehaviorItem { if (!event.getItem().equals(bukkitItem)) { itemstack.count++; // Chain to handler for new item - IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem()); + ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { - idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem())); + idispensebehavior.a(isourceblock, eventStack); return itemstack; } } diff --git a/src/main/java/net/minecraft/server/DispenseBehaviorProjectile.java b/src/main/java/net/minecraft/server/DispenseBehaviorProjectile.java index ce801b10d6..3968dd0ce7 100644 --- a/src/main/java/net/minecraft/server/DispenseBehaviorProjectile.java +++ b/src/main/java/net/minecraft/server/DispenseBehaviorProjectile.java @@ -33,7 +33,8 @@ public abstract class DispenseBehaviorProjectile extends DispenseBehaviorItem { if (!event.getItem().equals(bukkitItem)) { itemstack.count++; // Chain to handler for new item - IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem()); + ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem()); + IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem()); if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) { idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem())); return itemstack;