From 5f65cd9a1c316e2b751d423bba4f00b0ad6568a1 Mon Sep 17 00:00:00 2001 From: FrozenBrain Date: Tue, 27 Aug 2013 00:04:48 +0200 Subject: Add support for custom Hopper inventories. Fixes BUKKIT-4722 Opening a hopper inventory created by Server.createInventory will currently have no effect as proper handling code is missing in CraftEntityHuman for hopper inventories that aren't associated with a tile entity or minecart. Initialization logic for hoppers is also missing from CraftContainer, which is necessary for the opening of custom hopper inventories. This commit fixes the two aforementioned by adding proper handling to CraftHumanEntity for opening inventories not associated with a tile entity, and by adding initialization logic for hoppers to CraftContainer. --- .../craftbukkit/entity/CraftHumanEntity.java | 2 ++ .../craftbukkit/inventory/CraftContainer.java | 28 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) (limited to 'src') diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java index 2b1040b7..19d8842e 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java @@ -224,6 +224,8 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { getHandle().openHopper((TileEntityHopper) craftinv.getInventory()); } else if (craftinv.getInventory() instanceof EntityMinecartHopper) { getHandle().openMinecartHopper((EntityMinecartHopper) craftinv.getInventory()); + } else { + openCustomInventory(inventory, player, 9); } break; case CREATIVE: diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java index 0b38125c..c032dec8 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java @@ -115,6 +115,9 @@ public class CraftContainer extends Container { case ANVIL: typeID = 8; break; + case HOPPER: + typeID = 9; + break; default: typeID = 0; break; @@ -146,6 +149,9 @@ public class CraftContainer extends Container { case BREWING: setupBrewing(top, bottom); break; + case HOPPER: + setupHopper(top, bottom); + break; } } @@ -281,6 +287,28 @@ public class CraftContainer extends Container { // End copy from ContainerBrewingStand } + private void setupHopper(IInventory top, IInventory bottom) { + // This code copied from ContainerHopper + byte b0 = 51; + + int i; + + for (i = 0; i < top.getSize(); ++i) { + this.a(new Slot(top, i, 44 + i * 18, 20)); + } + + for (i = 0; i < 3; ++i) { + for (int j = 0; j < 9; ++j) { + this.a(new Slot(bottom, j + i * 9 + 9, 8 + j * 18, i * 18 + b0)); + } + } + + for (i = 0; i < 9; ++i) { + this.a(new Slot(bottom, i, 8 + i * 18, 58 + b0)); + } + // End copy from ContainerHopper + } + public boolean a(EntityHuman entity) { return true; } -- cgit v1.2.3