Containers

Methods

GetInventory

Returns the Inventory of the bot. Note: IInventory extends from IWindow, which should be used as documentation when working with the inventory.

IInventory GetInventory();

GetOpenWindow

Gets the currently open window. Note: This can return null if no window is open.

IWindow GetOpenWindow();

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.

Task CloseWindows();

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.

IWindow GetWindow(int id);

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.

IWindow GetWindowByTitle(string title);

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.

IWindow GetWindowByType (string type);

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.

public async void OnTick() {
    // Find all slots that have diamonds (id 264) in them.
    var diamondSlots = Context.Containers.GetInventory().Find(264);
    
    // Loop through each slot that has a diamond in it.
    foreach (var diamondSlot in diamondSlots) {
        // Check if the amount of diamonds in the current slot is
        // less than 64. If it is less than 64, then we drop the item stack.
        if(diamondSlot.Count < 64)
            await diamondSlot.DropStack();
    }
}

Last updated