ChestMap

Allows you to easily and efficiently (remember full/empty chests) find and open chests by criteria. Create with 'Context.Functions.CreateChestMap()'.

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.

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();
    }
}

Last updated