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):
BetaServerProtocol.authenticated(self)
# Init player, and copy data into it.
self.player = yield self.factory.world.load_player(self.username)
...
# 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)
Furnace:
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
- 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.
- reduce_recipe()[source]¶
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.
Parameters: - index – index of the selection
- alternate – whether this was an alternate selection
- shift – whether this was a shifted selection
- selected – the current selection
Returns: 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
- class bravo.inventory.windows.InventoryWindow(inventory)[source]¶
Bases: bravo.inventory.windows.Window
Special case of window - player’s inventory window
Bases: bravo.inventory.windows.Window
Base class for all windows with shared containers (like chests, furnace and dispenser)
Parameters: Generate update packets for dirty usually privided by another window (sic!)
- class bravo.inventory.windows.Window(wid, 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.
Parameters: - wid (int) – window ID
- inventory (Inventory) – player’s inventory object
- slots (SlotsSet) – other window slots
- container_for_slot(slot)[source]¶
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.