summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFrozenBrain <carstenbamsti@googlemail.com>2013-08-27 00:04:48 +0200
committerNate Mortensen <nate.richard.mortensen@gmail.com>2013-09-10 20:51:35 -0500
commit5f65cd9a1c316e2b751d423bba4f00b0ad6568a1 (patch)
tree0c1ea7db036a38ea514d61f575488f35ffe629e2 /src
parent600e1524a9976f8f44c6bf050dd670241bd210f5 (diff)
downloadcraftbukkit-5f65cd9a1c316e2b751d423bba4f00b0ad6568a1.tar
craftbukkit-5f65cd9a1c316e2b751d423bba4f00b0ad6568a1.tar.gz
craftbukkit-5f65cd9a1c316e2b751d423bba4f00b0ad6568a1.tar.lz
craftbukkit-5f65cd9a1c316e2b751d423bba4f00b0ad6568a1.tar.xz
craftbukkit-5f65cd9a1c316e2b751d423bba4f00b0ad6568a1.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java2
-rw-r--r--src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java28
2 files changed, 30 insertions, 0 deletions
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;
}