So I have a DoubleChest custom inventory that I’m displaying to the player, and I’m trying to get that inventory from Player#getOpenInventory
but I’m having some trouble figuring out how I’m supposed to distinguish between the three GridInventory
's that result from querying the player’s open inventory. I know one is the chest, one is the player’s grid, and one is the player’s grid plus hotbar, but is there a simple and concise way of fetching the chest? Is it guaranteed to be the first one?
My current method is ultra janky but works well enough to let me continue testing other aspects of my custom inventory system.
Current method:
static Optional<GridInventory> searchForSizedGrid(Player player, Vector2i size) {
return player.getOpenInventory().map(c -> {
Inventory inventory = c.query(QueryOperationTypes.INVENTORY_TYPE.of(GridInventory.class));
for (Inventory inv : inventory) {
if (inv instanceof GridInventory) {
GridInventory gridInventory = (GridInventory) inv;
if (gridInventory.getDimensions().equals(size)) {
return gridInventory;
}
}
}
return null;
});
}