Minestom wiki
Search…
Inventories
Inventories take a large place in Minecraft, they are used both for items storage and client<->server communication.
In order to create one, you can simply call its constructor by specifying an InventoryType and its name
1
// Create the inventory
2
Inventory inventory = new Inventory(InventoryType.CHEST_1_ROW, "The inventory name");
3
4
// Open the inventory for the player
5
// (Opening the same inventory for multiple players would result in a shared interface)
6
player.openInventory(inventory);
7
8
// Close the current player inventory
9
player.closeInventory();
Copied!
Sometimes you will want to add callbacks to your inventory actions (clicks). There are currently 3 ways of interacting with them.

Adding an inventory condition

Inventory conditions are specific to only one inventory. You are able to cancel the interaction by using InventoryConditionResult#setCancel
1
inventory.addInventoryCondition((player, slot, clickType, inventoryConditionResult) -> {
2
player.sendMessage("click type inventory: " + clickType);
3
System.out.println("slot inv: " + slot);
4
inventoryConditionResult.setCancel(false);
5
});
Copied!

InventoryPreClickEvent (see the events page)

Really similar to inventory conditions except that it listens to every inventory (you can obviously add checks when needed, but its goal is to be more "general")

InventoryClickEvent (see the events page)

This event only listens to successful actions (not canceled) and is fired after setting the items in the inventory.
Last modified 9d ago