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
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.

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

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

Project Versions

Previous topic

infini – InfiniCraft

Next topic

location – Locations

This Page