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.
This commit is contained in:
FrozenBrain 2013-08-27 00:04:48 +02:00 committed by Nate Mortensen
parent 600e1524a9
commit 5f65cd9a1c
2 changed files with 30 additions and 0 deletions

View file

@ -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:

View file

@ -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;
}