inventory – Inventories

The inventory module contains all kinds of windows and window parts like inventory, crafting and storage slots.

Generally to create a window you must create a Window object (of specific class derived from Window) and pass arguments like: window ID, player’s inventory, slot’s or tile’s inventory, coordinates etc.

Generic construction (never use in your code :)

window = Window( id, Inventory(), Workbench(), ...)

Please note that player’s inventory window is a special case. It is created when user logins and stays always opened. You probably will never have to create it.

def authenticated(self):

    # Init player, and copy data into it.
    self.player = yield
    # Init players' inventory window.
    self.inventory = InventoryWindow(self.player.inventory)

Every windows have own class. For instanse, to create a workbench window:

i = WorkbenchWindow(self.wid, self.player.inventory)


bigx, smallx, bigz, smallz, y = coords
furnace = self.chunks[x, y].tiles[(smallx, y, smallz)]
window = FurnaceWindow(self.wid, self.player.inventory, furnace.inventory, coords)
class bravo.inventory.Inventory[source]

Bases: bravo.inventory.SerializableSlots

The class represents Player’s inventory

add(item, quantity)[source]

Attempt to add an item to the inventory.

Parameters:item (tuple) – a key representing the item
Returns:quantity of items that did not fit inventory
consume(item, index)[source]

Attempt to remove a used holdable from the inventory.

A return value of False indicates that there were no holdables of the given type and slot to consume.

  • item (tuple) – a key representing the type of the item
  • slot (int) – which slot was selected

whether the item was successfully removed

select_armor(index, alternate, shift, selected=None)[source]

Handle a slot selection on an armor slot.

Returns tuple:( True/False, new selection )
class bravo.inventory.SerializableSlots[source]

Bases: object

Base class for all slots configurations

class bravo.inventory.slots.Crafting[source]

Bases: bravo.inventory.slots.SlotsSet

Base crafting class. Never shall be instantiated directly.


See if the crafting table matches any recipes.


Clear crafting areas and return items to drop and packets to send to client


Reduce a crafting table according to a recipe.

This function returns None; the crafting table is modified in-place.

This function assumes that the recipe already fits the crafting table and will not do additional checks to verify this assumption.

select_crafted(index, alternate, shift, selected=None)[source]

Handle a slot selection on a crafted output.

  • index – index of the selection
  • alternate – whether this was an alternate selection
  • shift – whether this was a shifted selection
  • selected – the current selection

a tuple of a bool indicating whether the selection was valid, and the newly selected slot

class bravo.inventory.slots.LargeChestStorage(chest1, chest2)[source]

Bases: bravo.inventory.slots.SlotsSet

LargeChest is a wrapper around 2 ChestStorages

class bravo.inventory.slots.SlotsSet[source]

Bases: bravo.inventory.SerializableSlots

Base calss for different slot configurations except player’s inventory



Special case of window - player’s inventory window

creative(slot, primary, secondary, quantity)[source]

Process inventory changes made in creative mode

class, inventory, slots, coords)[source]


Base class for all windows with shared containers (like chests, furnace and dispenser)

  • wid (int) – window ID
  • inventory (Inventory) – player’s inventory object
  • tile (Tile) – tile object
  • coords (tuple) – world coords of the tile (bigx, smallx, bigz, smallz, y)

Generate update packets for dirty usually privided by another window (sic!)

class, inventory, slots)[source]

Bases: bravo.inventory.SerializableSlots

Item manager

The Window covers all kinds of inventory and crafting windows, ranging from user inventories to furnaces and workbenches.

The Window agregates player’s inventory and other crafting/storage slots as building blocks of the window.

  • wid (int) – window ID
  • inventory (Inventory) – player’s inventory object
  • slots (SlotsSet) – other window slots

Clear crafting areas and return items to drop and packets to send to client


Retrieve the table and index for a given slot.

There is an isomorphism here which allows all of the tables of this Window to be viewed as a single large table of slots.


Load data from a packet container.

select(slot, alternate=False, shift=False)[source]

Handle a slot selection.

This method implements the basic public interface for interacting with Inventory objects. It is directly equivalent to mouse clicks made upon slots.

  • slot (int) – which slot was selected
  • alternate (bool) – whether the selection is alternate; e.g., if it was done with a right-click
  • shift (bool) – whether the shift key is toogled
select_stack(container, index)[source]

Handle stacking of items (Shift + RMB/LMB)

slot_for_container(table, index)[source]

Retrieve slot number for given table and index.