# ChestMap

It is important that you call 'chestmap.UpdateChestList' at least once before calling 'chestmap.Open', otherwise the results and unpredictable. The chest map can be updated many times afterwards, where the main purpose of this is to find newly rendered/placed chests and could be used when the bot is teleported/moved far away.

'chestmap.Open' will attempt to move to the closest chest that meets the specified criteria (e.g.: non-full). If it's successful then IWindow is returned, where it represents the opened chest containers, otherwise null is returned.

### Example usage

In the code below on the start of the plugin we initialize and populate the chest map. Every tick we attempt to open a non-full chest and attempt to store our items in it. You can imagine that Exec() returns true only if the bot's inventory is full and this could be used as a "storage on full" task.

```csharp
private ChestMap chestMap;

public async Task Start() {
    // Create and populate the chestmap. This will keep a reference of all
    // chest positions and their state (full/empty).
    chestMap = Context.Functions.CreateChestMap();
    await chestMap.UpdateChestList();
}

public async Task OnTick() {
    // Attempt to open a non-full chest.
    var openWindow = await chestMap.Open(ChestStatus.NotFull);
    if(openWindow != null) {
        // We have successfully opened a chest, store all items.
        await openWindow.Deposit();
        await openWindow.Close();
    }
}
```


---

# Agent Instructions: 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:

```
GET https://docs.minecraftbot.com/api/utility/chestmap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
