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.
Dieser Commit ist enthalten in:
Andre LeBlanc 2013-04-06 12:00:31 -04:00 committet von Travis Watkins
Ursprung 47367210f3
Commit 5d24f2b9c0

Datei anzeigen

@ -1,7 +1,9 @@
package org.bukkit.craftbukkit.inventory; package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.IInventory; import net.minecraft.server.IInventory;
import org.bukkit.inventory.AnvilInventory; import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.ItemStack;
public class CraftInventoryAnvil extends CraftInventory implements AnvilInventory { public class CraftInventoryAnvil extends CraftInventory implements AnvilInventory {
private final IInventory resultInventory; private final IInventory resultInventory;
@ -19,6 +21,26 @@ public class CraftInventoryAnvil extends CraftInventory implements AnvilInventor
return inventory; return inventory;
} }
@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 @Override
public int getSize() { public int getSize() {
return getResultInventory().getSize() + getIngredientsInventory().getSize(); return getResultInventory().getSize() + getIngredientsInventory().getSize();