> For the complete documentation index, see [llms.txt](https://wiki.microtus.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.microtus.dev/feature/inventories.md).

# 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

```java
// Create the inventory
Inventory inventory = new Inventory(InventoryType.CHEST_1_ROW, "The inventory name");

// Open the inventory for the player 
// (Opening the same inventory for multiple players would result in a shared interface)
player.openInventory(inventory);

// Close the current player inventory
player.closeInventory();
```

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

```java
inventory.addInventoryCondition((player, slot, clickType, inventoryConditionResult) -> {
   player.sendMessage("click type inventory: " + clickType);
   System.out.println("slot inv: " + slot);
   inventoryConditionResult.setCancel(false);
});
```

### InventoryPreClickEvent (see [the events page](/feature/events.md))

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](/feature/events.md))

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://wiki.microtus.dev/feature/inventories.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
