mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-11 09:23:42 +01:00
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:
parent
600e1524a9
commit
5f65cd9a1c
2 changed files with 30 additions and 0 deletions
|
@ -224,6 +224,8 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||||
getHandle().openHopper((TileEntityHopper) craftinv.getInventory());
|
getHandle().openHopper((TileEntityHopper) craftinv.getInventory());
|
||||||
} else if (craftinv.getInventory() instanceof EntityMinecartHopper) {
|
} else if (craftinv.getInventory() instanceof EntityMinecartHopper) {
|
||||||
getHandle().openMinecartHopper((EntityMinecartHopper) craftinv.getInventory());
|
getHandle().openMinecartHopper((EntityMinecartHopper) craftinv.getInventory());
|
||||||
|
} else {
|
||||||
|
openCustomInventory(inventory, player, 9);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CREATIVE:
|
case CREATIVE:
|
||||||
|
|
|
@ -115,6 +115,9 @@ public class CraftContainer extends Container {
|
||||||
case ANVIL:
|
case ANVIL:
|
||||||
typeID = 8;
|
typeID = 8;
|
||||||
break;
|
break;
|
||||||
|
case HOPPER:
|
||||||
|
typeID = 9;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
typeID = 0;
|
typeID = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -146,6 +149,9 @@ public class CraftContainer extends Container {
|
||||||
case BREWING:
|
case BREWING:
|
||||||
setupBrewing(top, bottom);
|
setupBrewing(top, bottom);
|
||||||
break;
|
break;
|
||||||
|
case HOPPER:
|
||||||
|
setupHopper(top, bottom);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,6 +287,28 @@ public class CraftContainer extends Container {
|
||||||
// End copy from ContainerBrewingStand
|
// 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) {
|
public boolean a(EntityHuman entity) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue