Inventory
endstone.inventory
¶
Classes relating to player inventories and item interactions.
Classes:
| Name | Description |
|---|---|
BookMeta |
Represents the meta for a written book that can have a title, an author, and pages. |
BookMetaGeneration |
|
CrossbowMeta |
Represents the meta for a crossbow that can have a charged projectile. |
EquipmentSlot |
|
Inventory |
Interface to the various inventories. |
ItemFactory |
An interface to the methods used to create item metadata. |
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. |
WritableBookMeta |
Represents the meta for a writable book that can have pages. |
BookMeta
¶
Bases: WritableBookMeta
Represents the meta for a written book that can have a title, an author, and pages.
Attributes:
| Name | Type | Description |
|---|---|---|
author |
str
|
The author of the book. |
generation |
BookMetaGeneration | None
|
The generation of the book. |
has_author |
bool
|
Whether the book has an author. |
has_generation |
bool
|
Whether the book has a generation level. |
has_title |
bool
|
Whether the book has a title. |
title |
str
|
The title of the book. |
BookMetaGeneration
¶
CrossbowMeta
¶
Bases: ItemMeta
Represents the meta for a crossbow that can have a charged projectile.
Attributes:
| Name | Type | Description |
|---|---|---|
charged_projectile |
ItemStack | None
|
The charged projectile, or |
has_charged_projectile |
bool
|
Whether the crossbow has a charged projectile. |
EquipmentSlot
¶
Inventory
¶
Interface to the various inventories.
Methods:
| Name | Description |
|---|---|
add_item |
Stores the given |
all |
|
clear |
|
contains |
|
contains_at_least |
|
first |
|
get_item |
Returns the |
remove |
|
remove_item |
Removes the given |
set_item |
Stores the |
Attributes:
| Name | Type | Description |
|---|---|---|
contents |
list[ItemStack | None]
|
All |
first_empty |
int
|
The first empty Slot found, or -1 if no empty slots. |
is_empty |
bool
|
Whether this inventory is empty. |
max_stack_size |
int
|
The maximum stack size for an |
size |
int
|
The size of the inventory. |
contents
property
writable
¶
All ItemStack objects from the inventory. Empty slots are represented as None.
is_empty
property
¶
is_empty: bool
Whether this inventory is empty.
An inventory is considered to be empty if there are no ItemStack objects in any slot of this inventory.
max_stack_size
property
¶
max_stack_size: int
The maximum stack size for an ItemStack in this inventory.
add_item
¶
Stores the given ItemStack objects in the inventory.
Note
This will try to fill existing stacks and empty slots as well as it can.
Note
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.
Returns:
| Type | Description |
|---|---|
dict[int, ItemStack]
|
A map containing items that couldn't be added. |
get_item
¶
remove_item
¶
Removes the given ItemStack objects from the inventory.
Note
It will try to remove 'as much as possible' from the types and amounts you give as arguments.
Note
The returned map contains what it couldn't remove, where the key is the index, and the value is the
ItemStack. If all the given ItemStack objects are removed, it will return an empty dict.
Returns:
| Type | Description |
|---|---|
dict[int, ItemStack]
|
A map containing items that couldn't be removed. |
ItemFactory
¶
An interface to the methods used to create item metadata.
Methods:
| Name | Description |
|---|---|
as_meta_for |
Returns an appropriate item meta for the specified item type. |
equals |
This method is used to compare two |
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 |
as_meta_for
¶
Returns an appropriate item meta for the specified item type.
The item meta returned will always be a valid meta for a given ItemStack of the specified item type. It may be a
more or less specific meta, and could also be the same meta or meta type as the parameter. The item meta returned
will also always be the most appropriate meta.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
ItemMeta
|
The meta to convert. |
required |
type
|
Identifier[ItemType] | str
|
The item type to convert the meta for. |
required |
Returns:
| Type | Description |
|---|---|
ItemMeta
|
An appropriate item meta for the specified item type. |
equals
¶
This method is used to compare two ItemMeta objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta1
|
ItemMeta
|
First meta to compare; may be |
required |
meta2
|
ItemMeta
|
Second meta to compare; may be |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
get_item_meta
¶
is_applicable
¶
This method checks the item meta to confirm that it is applicable (no data lost if applied) to the specified ItemStack.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
meta
|
ItemMeta
|
Meta to check. |
required |
type
|
Identifier[ItemType] | str
|
The item type that meta will be applied to. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
ItemMeta
¶
Represents the metadata of a generic item.
Methods:
| Name | Description |
|---|---|
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:
| Name | Type | Description |
|---|---|---|
damage |
int
|
The damage. |
display_name |
str
|
The display name that is set. |
enchants |
dict[Enchantment, int]
|
Returns a copy of the enchantments in this |
has_damage |
bool
|
Whether this item has damage. |
has_display_name |
bool
|
Whether this has a display name. |
has_enchants |
bool
|
Whether an enchantment exists on this meta. |
has_lore |
bool
|
Whether this has lore. |
has_repair_cost |
bool
|
Whether this item has a repair penalty. |
is_unbreakable |
bool
|
The unbreakable tag. An unbreakable item will not lose durability. |
lore |
list[str]
|
The lore for this item. |
repair_cost |
int
|
The repair penalty. |
enchants
property
¶
enchants: dict[Enchantment, int]
Returns a copy of the enchantments in this ItemMeta.
Returns an empty map if none.
is_unbreakable
property
writable
¶
is_unbreakable: bool
The unbreakable tag. An unbreakable item will not lose durability.
add_enchant
¶
add_enchant(
id: Identifier[Enchantment] | str,
level: int,
force: bool = False,
) -> bool
Adds the specified enchantment to this item meta.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
Identifier[Enchantment] | str
|
Enchantment id to add. |
required |
level
|
int
|
Level for the enchantment. |
required |
force
|
bool
|
This indicates the enchantment should be applied, ignoring the level limit. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
|
clone
¶
clone() -> ItemMeta
Creates a clone of the current metadata.
Returns:
| Type | Description |
|---|---|
ItemMeta
|
A copy of the metadata containing the same state as the original. |
get_enchant_level
¶
get_enchant_level(id: Identifier[Enchantment] | str) -> int
Checks for the level of the specified enchantment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
Identifier[Enchantment] | str
|
Enchantment id to check. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The level that the specified enchantment has, or 0 if none. |
has_enchant
¶
has_enchant(id: Identifier[Enchantment] | str) -> bool
Checks for existence of the specified enchantment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
Identifier[Enchantment] | str
|
Enchantment id to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
remove_enchant
¶
remove_enchant(id: Identifier[Enchantment] | str) -> bool
Removes the specified enchantment from this item meta.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
Identifier[Enchantment] | str
|
Enchantment id to remove. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
ItemStack
¶
Represents a stack of items.
Methods:
| Name | Description |
|---|---|
is_similar |
Checks if the two stacks are equal, but does not consider stack size (amount). |
set_item_meta |
Set the |
Attributes:
| Name | Type | Description |
|---|---|---|
amount |
int
|
The amount of items in this stack. |
data |
int
|
The data for this stack of items. |
item_meta |
ItemMeta
|
A copy of the |
max_stack_size |
int
|
The maximum stack size for this item. |
nbt |
CompoundTag
|
The NBT compound tag of this item stack. |
translation_key |
str
|
The translation key for this item. |
type |
ItemType
|
The type of this item. |
is_similar
¶
ItemType
¶
Represents an item type.
Methods:
| Name | Description |
|---|---|
create_item_stack |
Constructs a new |
get |
Attempts to get the |
get_translation_key |
Get the translation key, suitable for use in a translation component. |
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Identifier[ItemType]
|
The identifier of this item type. |
max_durability |
int
|
The maximum durability of this item type. |
max_stack_size |
int
|
The maximum amount of this item type that can be held in a stack. |
translation_key |
str
|
The translation key, suitable for use in a translation component. |
max_stack_size
property
¶
max_stack_size: int
The maximum amount of this item type that can be held in a stack.
translation_key
property
¶
translation_key: str
The translation key, suitable for use in a translation component.
create_item_stack
¶
get
staticmethod
¶
Attempts to get the ItemType with the given name.
MapMeta
¶
Bases: ItemMeta
Represents the metadata for a map item.
Attributes:
| Name | Type | Description |
|---|---|---|
has_map_id |
bool
|
Whether this has a map ID number. |
has_map_view |
bool
|
Whether this item has an associated map. |
map_id |
int
|
The map ID. This is used to determine what map is displayed. |
map_view |
MapView
|
The map view associated with this map item. |
PlayerInventory
¶
Bases: Inventory
Interface to the inventory of a Player, including the four armor slots and any extra slots.
Attributes:
| Name | Type | Description |
|---|---|---|
boots |
ItemStack | None
|
The |
chestplate |
ItemStack | None
|
The |
held_item_slot |
int
|
The slot number of the currently held item. |
helmet |
ItemStack | None
|
The |
item_in_main_hand |
ItemStack | None
|
The item the player is currently holding in their main hand. |
item_in_off_hand |
ItemStack | None
|
The item the player is currently holding in their off hand. |
leggings |
ItemStack | None
|
The |
WritableBookMeta
¶
Bases: ItemMeta
Represents the meta for a writable book that can have pages.
Methods:
| Name | Description |
|---|---|
add_page |
Adds new pages to the end of the book. |
get_page |
Gets the specified page in the book. The given page must exist. |
set_page |
Sets the specified page in the book. Pages of the book must be contiguous. |
Attributes:
| Name | Type | Description |
|---|---|---|
has_pages |
bool
|
Whether the book has pages. |
page_count |
int
|
The number of pages in the book. |
pages |
list[str]
|
All the pages in the book. |
add_page
¶
add_page(*args: str) -> None
Adds new pages to the end of the book.
Note
Up to a maximum of 50 pages with 256 characters per page.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pages
|
A list of strings, each being a page. |
required |
get_page
¶
set_page
¶
Sets the specified page in the book. Pages of the book must be contiguous.
Note
The data can be up to 1024 characters in length, additional characters are truncated.
Pages are 1-indexed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
int
|
The page number to set, in range [1, |
required |
data
|
str
|
The data to set for that page. |
required |