diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java index d50ed0f49..8597ae5dd 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java @@ -183,7 +183,7 @@ public class CraftContainer extends Container { delegate = new ContainerHopper(windowId, bottom, top); break; case ANVIL: - delegate = new ContainerAnvil(windowId, bottom); + setupAnvil(top, bottom); // SPIGOT-6783 - manually set up slots so we can use the delegated inventory and not the automatically created one break; case SMITHING: delegate = new ContainerSmithing(windowId, bottom); @@ -227,8 +227,13 @@ public class CraftContainer extends Container { } // SPIGOT-4598 - we should still delegate the shift click handler - if (cachedType == InventoryType.WORKBENCH) { - delegate = new ContainerWorkbench(windowId, bottom); + switch (cachedType) { + case WORKBENCH: + delegate = new ContainerWorkbench(windowId, bottom); + break; + case ANVIL: + delegate = new ContainerAnvil(windowId, bottom); + break; } } @@ -257,6 +262,27 @@ public class CraftContainer extends Container { // End copy from ContainerWorkbench } + private void setupAnvil(IInventory top, IInventory bottom) { + // This code copied from ContainerAnvilAbstract + this.a(new Slot(top, 0, 27, 47)); + this.a(new Slot(top, 1, 76, 47)); + this.a(new Slot(top, 2, 134, 47)); + + int row; + int col; + + for (row = 0; row < 3; ++row) { + for (col = 0; col < 9; ++col) { + this.a(new Slot(bottom, col + row * 9 + 9, 8 + col * 18, 84 + row * 18)); + } + } + + for (row = 0; row < 9; ++row) { + this.a(new Slot(bottom, row, 8 + row * 18, 142)); + } + // End copy from ContainerAnvilAbstract + } + @Override public ItemStack shiftClick(EntityHuman entityhuman, int i) { return (delegate != null) ? delegate.shiftClick(entityhuman, i) : super.shiftClick(entityhuman, i);