Container and GUI API

Inventory

An Inventory represents a chest-like container that can be opened as a GUI for players. Use it for custom menus, storage views, or item manipulation.


Constructor

Inventory(size=9, title="", contents=None)

Create a new inventory.

gui = Inventory(27, "§6Rewards Chest")

Attributes

size

Total number of slots.

contents

List of items in the inventory. Empty slots are None.

holder

The holder of this inventory (player, chest block, etc.), or None for virtual inventories.

title

Display title of the inventory.

first_empty

Index of the first empty slot, or -1 if the inventory is full.


Methods

open

await inventory.open(player)

Open this inventory as a GUI for a player.

gui = Inventory(27, "§bShop")
gui_contents = [Item("DIAMOND", name="§bBuy Diamond")]
await gui.open(player)

close

await inventory.close(player=None)

Close this inventory for a player.

add_item

await inventory.add_item(item)

Add an item to the first available slot.

await inventory.add_item(Item("DIAMOND", 64))

remove_item

await inventory.remove_item(item)

Remove an item from the inventory.

get_item

item = await inventory.get_item(slot)

Get the item in a specific slot.

set_item

await inventory.set_item(slot, item)

Set the item in a specific slot.

await inventory.set_item(13, Item("NETHER_STAR", name="§eSpecial"))

contains

result = await inventory.contains(material, amount=1)

Check if the inventory contains at least amount of the given material.

clear

await inventory.clear()

Remove all items from the inventory.


Example: Custom GUI

from bridge import *

@command("Open a shop GUI")
async def shop(player: Player, args: list[str]):
    gui = Inventory(27, "§6§lItem Shop")

    # Set border
    for i in range(27):
        if i < 9 or i >= 18 or i % 9 == 0 or i % 9 == 8:
            await gui.set_item(i, Item("GRAY_STAINED_GLASS_PANE", name=" "))

    # Set shop items
    await gui.set_item(11, Item("DIAMOND_SWORD", name="§bSword §7- §a$100"))
    await gui.set_item(13, Item("DIAMOND_CHESTPLATE", name="§bArmor §7- §a$500"))
    await gui.set_item(15, Item("GOLDEN_APPLE", name="§6Apple §7- §a$50"))

    await gui.open(player)

Tip: For a higher-level GUI system with click handlers, see the Menu class.