How to Place Item in an Inventory

Hey there!

I was wondering if there’s any way to specify what slot to place an item into when creating an inventory. I see:
Inventory#set(ItemStack)
Inventory#offer(ItemStack)
but that’s it. No way to say Inventory#set(ItemStack, int slot) from what I can see .-.

Any help is greatly appreciated!

Try this code:

GridInventory inv = p.getInventory().query(GridInventory.class);
inv.set(1, 1, ItemStack.builder().itemType(ItemTypes.SLIME).build());

I think y = 0 is the hotbar and y = 1-3 is the top to bottom of your inventory, but I never actually used the inventory api so I am not sure.

No errors yet. I haven’t managed to get around to testing it, but I will soon. Thanks!

You could also directly query for the Slot:
inventory.query(SlotIndex.of(i)) or
inventory.query(SlotPos.of(x,y))
and then call set/offer on that.

Are SlotIndex and SlotPos actually implemented and being used? I’ve tried using both in an ClickInventoryEvent listener and both of them just return empty optionals :frowning: