From 7d3f731504a57f79d5ecd69fa624e08df31e6ffc Mon Sep 17 00:00:00 2001 From: md_5 Date: Sun, 23 Jun 2013 13:58:40 +1000 Subject: [PATCH] Pull Bukkit/CraftBukkit#1130 - Include result slot in CraftInventoryAnvil.getItem .Fixes BUKKIT-2788 --- ...ory.getItem-use-both-containers.-Fix.patch | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 CraftBukkit-Patches/0056-Make-AnvilInventory.getItem-use-both-containers.-Fix.patch diff --git a/CraftBukkit-Patches/0056-Make-AnvilInventory.getItem-use-both-containers.-Fix.patch b/CraftBukkit-Patches/0056-Make-AnvilInventory.getItem-use-both-containers.-Fix.patch new file mode 100644 index 000000000..0b3a94792 --- /dev/null +++ b/CraftBukkit-Patches/0056-Make-AnvilInventory.getItem-use-both-containers.-Fix.patch @@ -0,0 +1,57 @@ +From 3f226c99b2d86e18422501ceb34ce61677627c14 Mon Sep 17 00:00:00 2001 +From: Andre LeBlanc +Date: Sat, 6 Apr 2013 12:00:31 -0400 +Subject: [PATCH] Make AnvilInventory.getItem() use both containers. Fixes + BUKKIT-2788 + +The AnvilInventory reports its size as the sum of the ingredient and +result inventories, but when trying to access the slots, only the ingredient +inventory is used, leading to an ArrayIndexOutOfBounds exception. + +This change overrides getItem(I) and setItem(I) to use both inventories, +with the slot number adjusted based on their size. + +diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java +index a91d81a..46a1d38 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java +@@ -1,7 +1,9 @@ + package org.bukkit.craftbukkit.inventory; + + import net.minecraft.server.IInventory; ++ + import org.bukkit.inventory.AnvilInventory; ++import org.bukkit.inventory.ItemStack; + + public class CraftInventoryAnvil extends CraftInventory implements AnvilInventory { + private final IInventory resultInventory; +@@ -20,6 +22,26 @@ public class CraftInventoryAnvil extends CraftInventory implements AnvilInventor + } + + @Override ++ public ItemStack getItem(int slot) { ++ if (slot < getIngredientsInventory().getSize()) { ++ net.minecraft.server.ItemStack item = getIngredientsInventory().getItem(slot); ++ return item == null ? null : CraftItemStack.asCraftMirror(item); ++ } else { ++ net.minecraft.server.ItemStack item = getResultInventory().getItem(slot - getIngredientsInventory().getSize()); ++ return item == null ? null : CraftItemStack.asCraftMirror(item); ++ } ++ } ++ ++ @Override ++ public void setItem(int index, ItemStack item) { ++ if (index < getIngredientsInventory().getSize()) { ++ getIngredientsInventory().setItem(index, (item == null ? null : CraftItemStack.asNMSCopy(item))); ++ } else { ++ getResultInventory().setItem((index - getIngredientsInventory().getSize()), (item == null ? null : CraftItemStack.asNMSCopy(item))); ++ } ++ } ++ ++ @Override + public int getSize() { + return getResultInventory().getSize() + getIngredientsInventory().getSize(); + } +-- +1.8.1.2 +