Skip to content

InventoryObject

Exposes normalized player inventory sections and items through player.inventory. Its ItemObject values provide item properties and version-dependent NBT data.

player.inventory provides the selected mainhand item, offhand item, hotbar, main inventory, and armor. Items are represented by ItemObject values even when originally read from older versions of Minecraft.

InventorySection also supports specific membership checks such as 'diamond_sword' in player.inventory.hotbar. player.inventory itself can be iterated, tested for membership, or queried through the following methods.

View the source: InventoryObject

Returns a list of valid ItemObject instances in the inventory. InventorySection.items() returns an iterator

Returns a list of items whose ID matches item_id, or [] if none

Counts the total quantity of an item (if item_id is str), the combined quantity of several items (if item_id is a list / tuple of str), or the total number of all items when unspecified. Returns int of the count

player.inventory.give(item, preserve_slot=False)

Section titled “player.inventory.give(item, preserve_slot=False)”

Gives the connected player an ItemObject, retaining item metadata supported by that Minecraft version. To place it in its original slot, set preserve_slot=True (Minecraft 1.8 or later). This complements ItemObject.take()

Clears the online player’s inventory. The target player must still be connected for give() and clear() to work

AttributeTypeDescription
player.inventory.selected_itemItemObjectItem currently held in the main hand
player.inventory.offhandItemObjectItem currently held in the offhand
player.inventory.hotbarInventorySectionSlots 0–8; supports indexing, iteration, items(), find() and count()
player.inventory.inventoryInventorySectionMain inventory, slots 0–26
player.inventory.armorInventorySectionSlots head, chest, legs, and feet
# Transfer every item from one player's inventory to another
player_1 = server.get_player('player_1')
player_2 = server.get_player('player_2')
for item in player_1.inventory:
player_2.inventory.give(item.take())