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.
1
private ChestMap chestMap;
2
3
public async Task Start() {
4
// Create and populate the chestmap. This will keep a reference of all
5
// chest positions and their state (full/empty).
6
chestMap = Context.Functions.CreateChestMap();
7
await chestMap.UpdateChestList();
8
}
9
10
public async Task OnTick() {
11
// Attempt to open a non-full chest.
12
var openWindow = await chestMap.Open(ChestStatus.NotFull);
13
if(openWindow != null) {
14
// We have successfully opened a chest, store all items.
15
await openWindow.Deposit();
16
await openWindow.Close();
17
}
18
}
Copied!
Last modified 2yr ago
Copy link