endstone.inventory

Classes relating to player inventories and item interactions.

Classes relating to player inventories and item interactions.

Classes

NameDescription
EquipmentSlot
Inventory

Interface to the various inventories.

ItemFactory
ItemMeta

Represents the metadata of a generic item.

ItemStack

Represents a stack of items.

ItemType

Represents an item type.

MapMeta

Represents the metadata for a map item.

PlayerInventory

Interface to the inventory of a Player, including the four armor slots and any extra slots.

classEquipmentSlot

Bases: Enum

EquipmentSlot()

Attributes

NameTypeDescription
BODY

Only for certain entities such as horses and wolves.

CHEST
FEET
HAND
HEAD
LEGS
OFF_HAND

attrBODY

BODY = 6

Only for certain entities such as horses and wolves.

attrCHEST

CHEST = 4

attrFEET

FEET = 2

attrHAND

HAND = 0

attrHEAD

HEAD = 5

attrLEGS

LEGS = 3

attrOFF_HAND

OFF_HAND = 1

classInventory

Inventory()

Interface to the various inventories.

Methods

NameDescription
add_item

Stores the given ItemStacks in the inventory. This will try to fill existing stacks and empty slots as well as it can.

get_item

Returns the ItemStack found in the slot at the given index

remove_item

Removes the given ItemStacks from the inventory. It will try to remove 'as much as possible' from the types and amounts you give as arguments.

set_item

Stores the ItemStack at the given index of the inventory.

Attributes

NameTypeDescription
contentslist[ItemStack | None]

Returns all ItemStacks from the inventory

first_emptyint

Returns the first empty Slot.

is_emptybool

Check whether this inventory is empty. An inventory is considered to be empty if there are no ItemStacks in any slot of this inventory.

max_stack_sizeint

Returns the maximum stack size for an ItemStack in this inventory.

sizeint

Returns the size of the inventory

attrcontentsproperty

contents: list[ItemStack | None]

Returns all ItemStacks from the inventory

attrfirst_emptyproperty

first_empty: int

Returns the first empty Slot.

attris_emptyproperty

is_empty: bool

Check whether this inventory is empty. An inventory is considered to be empty if there are no ItemStacks in any slot of this inventory.

attrmax_stack_sizeproperty

max_stack_size: int

Returns the maximum stack size for an ItemStack in this inventory.

attrsizeproperty

size: int

Returns the size of the inventory

methadd_item

add_item(*args) -> dict[int, ItemStack]

Stores the given ItemStacks in the inventory. This will try to fill existing stacks and empty slots as well as it can.

The returned map contains what it couldn't store, where the key is the index, and the value is the ItemStack. If all items are stored, it will return an empty dict.

methget_item

get_item(index: int) -> ItemStack | None

Returns the ItemStack found in the slot at the given index

methremove_item

remove_item(*args) -> dict[int, ItemStack]

Removes the given ItemStacks from the inventory. It will try to remove 'as much as possible' from the types and amounts you give as arguments.

The returned HashMap contains what it couldn't remove, where the key is the index, and the value is the ItemStack. If all the given ItemStacks are removed, it will return an empty dict.

methset_item

set_item(index: int, item: ItemStack | None) -> None

Stores the ItemStack at the given index of the inventory.

classItemFactory

ItemFactory()

Methods

NameDescription
as_meta_for

Returns an appropriate item meta for the specified item type.

equals

This method is used to compare two ItemMeta objects.

get_item_meta

This creates a new item meta for the item type.

is_applicable

This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified ItemStack

methas_meta_for

as_meta_for(meta: ItemMeta, type: str) -> ItemMeta

Returns an appropriate item meta for the specified item type.

methequals

equals(meta1: ItemMeta, meta2: ItemMeta) -> bool

This method is used to compare two ItemMeta objects.

methget_item_meta

get_item_meta(type: str) -> ItemMeta

This creates a new item meta for the item type.

methis_applicable

is_applicable(meta: ItemMeta, type: str) -> bool

This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified ItemStack

classItemMeta

ItemMeta()

Represents the metadata of a generic item.

Methods

NameDescription
add_enchant

Adds the specified enchantment to this item meta.

clone

Creates a clone of the current metadata.

get_enchant_level

Checks for the level of the specified enchantment.

has_enchant

Checks for existence of the specified enchantment.

remove_enchant

Removes the specified enchantment from this item meta.

remove_enchants

Removes all enchantments from this item meta.

Attributes

NameTypeDescription
damageint

Gets or sets the damage.

display_namestr

Gets or sets the display name.

enchantsdict[Enchantment, int]

Returns a copy the enchantments in this ItemMeta.

has_damagebool

Checks to see if this item has damage.

has_display_namebool

Checks for existence of a display name.

has_enchantsbool

Checks for the existence of any enchantments.

has_lorebool

Checks for existence of lore.

has_repair_costbool

Checks to see if this item has a repair penalty.

is_unbreakablebool

Gets or sets the unbreakable tag. An unbreakable item will not lose durability.

lorelist[str]

Gets or sets the lore for this item.

repair_costint

Gets or sets the repair penalty.

attrdamageproperty

damage: int

Gets or sets the damage.

attrdisplay_nameproperty

display_name: str

Gets or sets the display name.

attrenchantsproperty

enchants: dict[Enchantment, int]

Returns a copy the enchantments in this ItemMeta.

attrhas_damageproperty

has_damage: bool

Checks to see if this item has damage.

attrhas_display_nameproperty

has_display_name: bool

Checks for existence of a display name.

attrhas_enchantsproperty

has_enchants: bool

Checks for the existence of any enchantments.

attrhas_loreproperty

has_lore: bool

Checks for existence of lore.

attrhas_repair_costproperty

has_repair_cost: bool

Checks to see if this item has a repair penalty.

attris_unbreakableproperty

is_unbreakable: bool

Gets or sets the unbreakable tag. An unbreakable item will not lose durability.

attrloreproperty

lore: list[str]

Gets or sets the lore for this item.

attrrepair_costproperty

repair_cost: int

Gets or sets the repair penalty.

methadd_enchant

add_enchant(id: str, level: int, force: bool = False) -> bool

Adds the specified enchantment to this item meta.

methclone

clone() -> ItemMeta

Creates a clone of the current metadata.

methget_enchant_level

get_enchant_level(id: str) -> int

Checks for the level of the specified enchantment.

methhas_enchant

has_enchant(id: str) -> bool

Checks for existence of the specified enchantment.

methremove_enchant

remove_enchant(id: str) -> bool

Removes the specified enchantment from this item meta.

methremove_enchants

remove_enchants() -> None

Removes all enchantments from this item meta.

classItemStack

ItemStack(type: str, amount: int = 1, data: int = 0)

Represents a stack of items.

Methods

NameDescription
is_similar

Checks if the two stacks are equal, but does not consider stack size (amount).

set_item_meta

Set the ItemMeta of this ItemStack.

Attributes

NameTypeDescription
amountint

Gets or sets the amount of items in this stack.

dataint

Gets or sets the data for this stack of items.

item_metaItemMeta

Gets a copy of the ItemMeta of this ItemStack.

max_stack_sizeint

Get the maximum stack size for this item.

nbtCompoundTag

Gets or sets the NBT compound tag of this item stack.

translation_keystr

Get the translation key for this item.

typeItemType

Gets or sets the type of this item.

attramountproperty

amount: int

Gets or sets the amount of items in this stack.

attrdataproperty

data: int

Gets or sets the data for this stack of items.

attritem_metaproperty

item_meta: ItemMeta

Gets a copy of the ItemMeta of this ItemStack.

attrmax_stack_sizeproperty

max_stack_size: int

Get the maximum stack size for this item.

attrnbtproperty

Gets or sets the NBT compound tag of this item stack.

attrtranslation_keyproperty

translation_key: str

Get the translation key for this item.

attrtypeproperty

type: ItemType

Gets or sets the type of this item.

methis_similar

is_similar(other: ItemStack) -> bool

Checks if the two stacks are equal, but does not consider stack size (amount).

methset_item_meta

set_item_meta(meta: ItemMeta) -> bool

Set the ItemMeta of this ItemStack.

classItemType

ItemType()

Represents an item type.

Methods

NameDescription
create_item_stack

Constructs a new ItemStack with this item type.

get

Attempts to get the ItemType with the given name.

get_translation_key

Get the translation key, suitable for use in a translation component.

Attributes

NameTypeDescription
idstr

Return the identifier of this item type.

max_durabilityint

Gets the maximum durability of this item type

max_stack_sizeint

Gets the maximum amount of this item type that can be held in a stack.

translation_keystr

Get the translation key, suitable for use in a translation component.

attridproperty

id: str

Return the identifier of this item type.

attrmax_durabilityproperty

max_durability: int

Gets the maximum durability of this item type

attrmax_stack_sizeproperty

max_stack_size: int

Gets the maximum amount of this item type that can be held in a stack.

attrtranslation_keyproperty

translation_key: str

Get the translation key, suitable for use in a translation component.

methcreate_item_stack

create_item_stack(amount: int = 1) -> ItemStack

Constructs a new ItemStack with this item type.

methgetstaticmethod

get(name: str) -> ItemType

Attempts to get the ItemType with the given name.

methget_translation_key

get_translation_key(data: int = 0) -> str

Get the translation key, suitable for use in a translation component.

classMapMeta

Bases: ItemMeta

MapMeta()

Represents the metadata for a map item.

Attributes

NameTypeDescription
has_map_idbool

Checks for existence of a map ID number.

has_map_viewbool

Checks for existence of an associated map.

map_idint

Gets or sets the map ID. This is used to determine what map is displayed.

map_viewMapView

Gets or sets the map view that is associated with this map item.

attrhas_map_idproperty

has_map_id: bool

Checks for existence of a map ID number.

attrhas_map_viewproperty

has_map_view: bool

Checks for existence of an associated map.

attrmap_idproperty

map_id: int

Gets or sets the map ID. This is used to determine what map is displayed.

attrmap_viewproperty

map_view: MapView

Gets or sets the map view that is associated with this map item.

classPlayerInventory

Bases: Inventory

PlayerInventory()

Interface to the inventory of a Player, including the four armor slots and any extra slots.

Attributes

NameTypeDescription
bootsItemStack | None

Gets or sets the ItemStack in the boots slot

chestplateItemStack | None

Gets or sets the ItemStack in the chestplate slot

held_item_slotint

Gets or sets the slot number of the currently held item

helmetItemStack | None

Gets or sets the ItemStack in the helmet slot

item_in_main_handItemStack | None

Gets or sets the item the player is currently holding in their main hand.

item_in_off_handItemStack | None

Gets or sets the item the player is currently holding in their off hand.

leggingsItemStack | None

Gets or sets the ItemStack in the leg slot

attrbootsproperty

boots: ItemStack | None

Gets or sets the ItemStack in the boots slot

attrchestplateproperty

chestplate: ItemStack | None

Gets or sets the ItemStack in the chestplate slot

attrheld_item_slotproperty

held_item_slot: int

Gets or sets the slot number of the currently held item

attrhelmetproperty

helmet: ItemStack | None

Gets or sets the ItemStack in the helmet slot

attritem_in_main_handproperty

item_in_main_hand: ItemStack | None

Gets or sets the item the player is currently holding in their main hand.

attritem_in_off_handproperty

item_in_off_hand: ItemStack | None

Gets or sets the item the player is currently holding in their off hand.

attrleggingsproperty

leggings: ItemStack | None

Gets or sets the ItemStack in the leg slot

On this page