Containers
Methods
Events
GetInventory
onWindowAdded
GetOpenWindow
onWindowRemoved
CloseWindows
GetWindow
GetWindowByTitle
GetWindowByType

Methods

GetInventory

Returns the Inventory of the bot. Note: IInventory extends from IWindow, which should be used as documentation when working with the inventory.
1
IInventory GetInventory();
Copied!

GetOpenWindow

Gets the currently open window. Note: This can return null if no window is open.
1
IWindow GetOpenWindow();
Copied!

CloseWindows

Closes the currently open window, if no window is open then it will send an inventory close packet, however the server does not normally keep track if the inventory is open.
1
Task CloseWindows();
Copied!

GetWindow

Gets the window by ID. Note: the bot's inventory always has the id 0, therefore if the parameter id is 0 then the bot's inventory will be returned.
1
IWindow GetWindow(int id);
Copied!

GetWindowByTitle

Gets the window by title of the container. Note: the title must be unformatted/raw text, meaning it does not contain any color codes, or any text effects such as bold, or strikethrough.
1
IWindow GetWindowByTitle(string title);
Copied!

GetWindowByType

Gets the window by type of container. The type of the window always starts with "minecraft:" and a list of container types can be found here.
1
IWindow GetWindowByType (string type);
Copied!

Example code using Containers

The code below searches the bot's inventory for slots that have diamonds in them and then drops the slots that were found if they have less than 64 diamonds.
Commented Code
Raw Code
1
public async void OnTick() {
2
// Find all slots that have diamonds (id 264) in them.
3
var diamondSlots = Context.Containers.GetInventory().Find(264);
4
5
// Loop through each slot that has a diamond in it.
6
foreach (var diamondSlot in diamondSlots) {
7
// Check if the amount of diamonds in the current slot is
8
// less than 64. If it is less than 64, then we drop the item stack.
9
if(diamondSlot.Count < 64)
10
await diamondSlot.DropStack();
11
}
12
}
Copied!
1
public async void OnTick() {
2
var diamondSlots = Context.Containers.GetInventory().Find(264);
3
4
foreach (var diamondSlot in diamondSlots) {
5
if(diamondSlot.Count < 64)
6
await diamondSlot.DropStack();
7
}
8
}
Copied!
Last modified 2yr ago