Inventory
endstone.inventory
¶
Classes relating to player inventories and item interactions.
Classes:
| Name | Description |
|---|---|
BlastingRecipe |
Represents a blasting recipe. |
BookMeta |
Represents the meta for a written book that can have a title, an author, and pages. |
BookMetaGeneration |
|
CampfireRecipe |
Represents a campfire recipe. |
ComplexAliasIngredient |
Represents an ingredient that matches any item an id stands for. |
ComplexRecipe |
Represents a complex recipe which has imperative server-defined behavior, eg armor dyeing. |
CookingRecipe |
Represents a cooking recipe. |
CrossbowMeta |
Represents the meta for a crossbow that can have a charged projectile. |
EquipmentSlot |
|
ExactIngredient |
Represents an ingredient that matches one item with one exact data value. |
FurnaceRecipe |
Represents a furnace recipe. |
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. |
ItemTagIngredient |
Represents an ingredient that matches any item carrying a tag. |
ItemType |
Represents an item type. |
ItemTypeIngredient |
Represents an ingredient that matches an item type, whatever its data value. |
MapMeta |
Represents the metadata for a map item. |
MolangIngredient |
Represents an ingredient that matches the items a Molang expression selects. |
PlayerInventory |
Interface to the inventory of a Player, including the four armor slots and any extra slots. |
PotionMeta |
Represents the metadata for a potion item. |
Recipe |
Represents some type of crafting recipe. |
RecipeIngredient |
Represents a potential item match within a recipe. All choices within a recipe must be satisfied for it to be |
ShapedRecipe |
Represents a shaped (ie normal) crafting recipe. |
ShapelessRecipe |
Represents a shapeless recipe, where the arrangement of the ingredients on the crafting grid does not matter. |
SmithingRecipe |
Represents a smithing recipe. |
SmithingTransformRecipe |
Represents a smithing transform recipe. |
SmithingTrimRecipe |
Represents a smithing trim recipe. |
SmokingRecipe |
Represents a smoking recipe. |
WritableBookMeta |
Represents the meta for a writable book that can have pages. |
BlastingRecipe
¶
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
¶
CampfireRecipe
¶
ComplexAliasIngredient
¶
Bases: RecipeIngredient
Represents an ingredient that matches any item an id stands for.
Attributes:
| Name | Type | Description |
|---|---|---|
alias |
str
|
The alias that this ingredient will match. |
ComplexRecipe
¶
Bases: Recipe
Represents a complex recipe which has imperative server-defined behavior, eg armor dyeing.
CookingRecipe
¶
Bases: Recipe
Represents a cooking recipe.
Bedrock records neither an experience reward nor a cooking time on the recipe itself, so neither is reported here. The experience a smelt awards belongs to the input item, and the time a cook takes to the station.
Attributes:
| Name | Type | Description |
|---|---|---|
input_choice |
RecipeIngredient | None
|
The input choice. |
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
¶
ExactIngredient
¶
Bases: RecipeIngredient
Represents an ingredient that matches one item with one exact data value.
Attributes:
| Name | Type | Description |
|---|---|---|
item_stack |
ItemStack
|
|
FurnaceRecipe
¶
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 | None
|
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
¶
This creates a new item meta for the item type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
Identifier[ItemType] | str
|
The item type to consider as base for the meta. |
required |
Returns:
| Type | Description |
|---|---|
ItemMeta | None
|
A new |
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 | None
|
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. |
ItemTagIngredient
¶
Bases: RecipeIngredient
Represents an ingredient that matches any item carrying a tag.
Attributes:
| Name | Type | Description |
|---|---|---|
item_tag |
str
|
The item tag that this ingredient will match. |
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 |
|---|---|---|
AIR |
Identifier[ItemType]
|
|
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.
ItemTypeIngredient
¶
Bases: RecipeIngredient
Represents an ingredient that matches an item type, whatever its data value.
Attributes:
| Name | Type | Description |
|---|---|---|
item_type |
ItemType
|
The item type that this ingredient will match. |
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. |
MolangIngredient
¶
Bases: RecipeIngredient
Represents an ingredient that matches the items a Molang expression selects.
Attributes:
| Name | Type | Description |
|---|---|---|
expression |
str
|
The Molang expression that this ingredient will match. |
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 |
PotionMeta
¶
Bases: ItemMeta
Represents the metadata for a potion item.
A potion carries a single base potion type, which determines both the effects it applies and the colour it is rendered with.
Attributes:
| Name | Type | Description |
|---|---|---|
base_potion_type |
Identifier[PotionType] | None
|
The base potion type of this potion, or |
has_base_potion_type |
bool
|
Whether this has a base potion type. |
base_potion_type
property
writable
¶
base_potion_type: Identifier[PotionType] | None
The base potion type of this potion, or None if none is set.
Recipe
¶
Represents some type of crafting recipe.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
The identifier of this recipe, such as |
ingredients |
list[RecipeIngredient | None]
|
The ingredients consumed by this recipe. |
result |
ItemStack
|
The result of this recipe. |
tag |
str
|
The station this recipe belongs to, such as |
ingredients
property
¶
ingredients: list[RecipeIngredient | None]
The ingredients consumed by this recipe.
A value is None when the corresponding slot does not require an ingredient.
RecipeIngredient
¶
ShapedRecipe
¶
ShapelessRecipe
¶
Bases: Recipe
Represents a shapeless recipe, where the arrangement of the ingredients on the crafting grid does not matter.
SmithingRecipe
¶
Bases: Recipe
Represents a smithing recipe.
Attributes:
| Name | Type | Description |
|---|---|---|
addition |
RecipeIngredient | None
|
The addition recipe item. |
base |
RecipeIngredient | None
|
The base recipe item. |
SmithingTransformRecipe
¶
Bases: SmithingRecipe
Represents a smithing transform recipe.
Attributes:
| Name | Type | Description |
|---|---|---|
template |
RecipeIngredient | None
|
The template recipe item. |
SmithingTrimRecipe
¶
Bases: SmithingRecipe
Represents a smithing trim recipe.
Attributes:
| Name | Type | Description |
|---|---|---|
template |
RecipeIngredient | None
|
The template recipe item. |
SmokingRecipe
¶
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 256 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 |