diff options
author | Andre LeBlanc <andre@norcode.com> | 2013-04-06 12:00:31 -0400 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2014-04-18 13:21:21 -0500 |
commit | 5d24f2b9c0ef2d6d136e36a64c530a1fde657f5c (patch) | |
tree | 22f83666c5f7a4c3f58fad095cdabe3e5a282a07 /src/main/java | |
parent | 47367210f3f74acc831d3f8a15a52aa693fbe7bb (diff) | |
download | craftbukkit-5d24f2b9c0ef2d6d136e36a64c530a1fde657f5c.tar craftbukkit-5d24f2b9c0ef2d6d136e36a64c530a1fde657f5c.tar.gz craftbukkit-5d24f2b9c0ef2d6d136e36a64c530a1fde657f5c.tar.lz craftbukkit-5d24f2b9c0ef2d6d136e36a64c530a1fde657f5c.tar.xz craftbukkit-5d24f2b9c0ef2d6d136e36a64c530a1fde657f5c.zip |
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.
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventoryAnvil.java index a91d81ae..46a1d387 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(); } |