Skip to content

Inventory

endstone.inventory

Classes relating to player inventories and item interactions.

Classes:

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

EquipmentSlot

Bases: Enum

Attributes:

Name Type Description
BODY

Only for certain entities such as horses and wolves.

CHEST
FEET
HAND
HEAD
LEGS
OFF_HAND

BODY class-attribute instance-attribute

 BODY = 6

Only for certain entities such as horses and wolves.

CHEST class-attribute instance-attribute

 CHEST = 4

FEET class-attribute instance-attribute

 FEET = 2

HAND class-attribute instance-attribute

 HAND = 0

HEAD class-attribute instance-attribute

 HEAD = 5

LEGS class-attribute instance-attribute

 LEGS = 3

OFF_HAND class-attribute instance-attribute

 OFF_HAND = 1

Inventory

Interface to the various inventories.

Methods:

Name Description
add_item

Stores the given ItemStacks in the inventory.

all
clear
contains
contains_at_least
first
get_item

Returns the ItemStack found in the slot at the given index

remove
remove_item

Removes the given ItemStacks from the inventory.

set_item

Stores the ItemStack at the given index of the inventory.

Attributes:

Name Type Description
contents list[ItemStack]

Returns all ItemStacks from the inventory

first_empty int

Returns the first empty Slot.

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.

max_stack_size int

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

size int

Returns the size of the inventory

contents property writable

 contents: list [ItemStack ]

Returns all ItemStacks from the inventory

first_empty property

 first_empty: int 

Returns the first empty Slot.

is_empty property

 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.

max_stack_size property

 max_stack_size: int 

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

size property

 size: int 

Returns the size of the inventory

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

all

 all(item: ItemStack ) -> dict [int , ItemStack ]

Finds all slots in the inventory containing any ItemStacks with the given ItemStack. This will only match slots if both the type and the amount of the stack match The returned map contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack is found, an empty dict is returned.

 all(type: str ) -> dict [int , ItemStack ]

Finds all slots in the inventory containing any ItemStacks with the given ItemType. The returned map contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack is found, an empty dict is returned.

clear

 clear(index: int ) -> None

Clears out a particular slot in the index.

 clear() -> None

Clears out the whole Inventory.

contains

 contains(item: ItemStack , amount: int ) -> bool 

Checks if the inventory contains at least the minimum amount specified of exactly matching ItemStacks. An ItemStack only counts if both the type and the amount of the stack match.

 contains(item: ItemStack ) -> bool 

Checks if the inventory contains any ItemStacks with the given ItemStack. This will only return true if both the type and the amount of the stack match.

 contains(type: str ) -> bool 

Checks if the inventory contains any ItemStacks with the given ItemType.

contains_at_least

 contains_at_least(item: ItemStack , amount: int ) -> bool 

Checks if the inventory contains ItemStacks matching the given ItemStack whose amounts sum to at least the minimum amount specified.

 contains_at_least(type: str , amount: int ) -> bool 

Checks if the inventory contains any ItemStacks with the given ItemType, adding to at least the minimum amount specified.

first

 first(item: ItemStack ) -> int 

Returns the first slot in the inventory containing an ItemStack with the given stack. This will only match slots if both the type and the amount of the stack match The returned map contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack is found, an empty dict is returned.

 first(type: str ) -> int 

Finds the first slot in the inventory containing an ItemStack with the given ItemType. The returned map contains entries where, the key is the slot index, and the value is the ItemStack in that slot. If no matching ItemStack is found, an empty dict is returned.

get_item

 get_item(index: int ) -> ItemStack 

Returns the ItemStack found in the slot at the given index

remove

 remove(item: ItemStack ) -> None

Removes all stacks in the inventory matching the given stack. This will only match a slot if both the type and the amount of the stack match

 remove(type: str ) -> None

Removes all stacks in the inventory matching the given ItemType.

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

set_item

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

Stores the ItemStack at the given index of the inventory.

ItemFactory

Methods:

Name Description
as_meta_for

Returns an appropriate item meta for the specified item type.

create_item_stack

Create a new ItemStack given the NBT.

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

as_meta_for

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

Returns an appropriate item meta for the specified item type.

create_item_stack

 create_item_stack(tag: CompoundTag ) -> ItemStack 

Create a new ItemStack given the NBT.

equals

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

This method is used to compare two ItemMeta objects.

get_item_meta

 get_item_meta(type: str ) -> ItemMeta 

This creates a new item meta for the item type.

is_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

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

Gets or sets the damage.

display_name str

Gets or sets the display name.

enchants dict[Enchantment, int]

Returns a copy the enchantments in this ItemMeta.

has_damage bool

Checks to see if this item has damage.

has_display_name bool

Checks for existence of a display name.

has_enchants bool

Checks for the existence of any enchantments.

has_lore bool

Checks for existence of lore.

has_repair_cost bool

Checks to see if this item has a repair penalty.

is_unbreakable bool

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

lore list[str]

Gets or sets the lore for this item.

repair_cost int

Gets or sets the repair penalty.

damage property writable

 damage: int 

Gets or sets the damage.

display_name property writable

 display_name: str 

Gets or sets the display name.

enchants property

 enchants: dict [Enchantment , int ]

Returns a copy the enchantments in this ItemMeta.

has_damage property

 has_damage: bool 

Checks to see if this item has damage.

has_display_name property

 has_display_name: bool 

Checks for existence of a display name.

has_enchants property

 has_enchants: bool 

Checks for the existence of any enchantments.

has_lore property

 has_lore: bool 

Checks for existence of lore.

has_repair_cost property

 has_repair_cost: bool 

Checks to see if this item has a repair penalty.

is_unbreakable property writable

 is_unbreakable: bool 

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

lore property writable

 lore: list [str ]

Gets or sets the lore for this item.

repair_cost property writable

 repair_cost: int 

Gets or sets the repair penalty.

add_enchant

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

Adds the specified enchantment to this item meta.

clone

 clone() -> ItemMeta 

Creates a clone of the current metadata.

get_enchant_level

 get_enchant_level(id: str ) -> int 

Checks for the level of the specified enchantment.

has_enchant

 has_enchant(id: str ) -> bool 

Checks for existence of the specified enchantment.

remove_enchant

 remove_enchant(id: str ) -> bool 

Removes the specified enchantment from this item meta.

remove_enchants

 remove_enchants() -> None

Removes all enchantments from this item meta.

ItemStack

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

Represents a stack of items.

Methods:

Name Description
from_nbt

Deserializes an ItemStack from a Named Binary Tag (NBT).

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.

to_nbt

Serializes this ItemStack into a Named Binary Tag (NBT).

Attributes:

Name Type Description
amount int

Gets or sets the amount of items in this stack.

data int

Gets or sets the data for this stack of items.

item_meta ItemMeta

Gets a copy of the ItemMeta of this ItemStack.

max_stack_size int

Get the maximum stack size for this item.

translation_key str

Get the translation key for this item.

type ItemType

Gets or sets the type of this item.

amount property writable

 amount: int 

Gets or sets the amount of items in this stack.

data property writable

 data: int 

Gets or sets the data for this stack of items.

item_meta property

 item_meta: ItemMeta 

Gets a copy of the ItemMeta of this ItemStack.

max_stack_size property

 max_stack_size: int 

Get the maximum stack size for this item.

translation_key property

 translation_key: str 

Get the translation key for this item.

type property writable

 type: ItemType 

Gets or sets the type of this item.

from_nbt staticmethod

 from_nbt(arg0: CompoundTag ) -> ItemStack 

Deserializes an ItemStack from a Named Binary Tag (NBT).

is_similar

 is_similar(other: ItemStack ) -> bool 

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

set_item_meta

 set_item_meta(meta: ItemMeta ) -> bool 

Set the ItemMeta of this ItemStack.

to_nbt

 to_nbt() -> CompoundTag 

Serializes this ItemStack into a Named Binary Tag (NBT).

ItemType

Represents an item type.

Methods:

Name Description
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:

Name Type Description
id str

Return the identifier of this item type.

max_durability int

Gets the maximum durability of this item type

max_stack_size int

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

translation_key str

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

id property

 id: str 

Return the identifier of this item type.

max_durability property

 max_durability: int 

Gets the maximum durability of this item type

max_stack_size property

 max_stack_size: int 

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

translation_key property

 translation_key: str 

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

get staticmethod

 get(name: str ) -> ItemType 

Attempts to get the ItemType with the given name.

get_translation_key

 get_translation_key(data: int  = 0) -> str 

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

MapMeta

Bases: ItemMeta

Represents the metadata for a map item.

Attributes:

Name Type Description
has_map_id bool

Checks for existence of a map ID number.

has_map_view bool

Checks for existence of an associated map.

map_id int

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

map_view MapView

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

has_map_id property

 has_map_id: bool 

Checks for existence of a map ID number.

has_map_view property

 has_map_view: bool 

Checks for existence of an associated map.

map_id property writable

 map_id: int 

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

map_view property writable

 map_view: MapView 

Gets or sets the map view that is 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

Gets or sets the ItemStack in the boots slot

chestplate ItemStack

Gets or sets the ItemStack in the chestplate slot

held_item_slot int

Gets or sets the slot number of the currently held item

helmet ItemStack

Gets or sets the ItemStack in the helmet slot

item_in_main_hand ItemStack

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

item_in_off_hand ItemStack

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

leggings ItemStack

Gets or sets the ItemStack in the leg slot

boots property writable

 boots: ItemStack 

Gets or sets the ItemStack in the boots slot

chestplate property writable

 chestplate: ItemStack 

Gets or sets the ItemStack in the chestplate slot

held_item_slot property writable

 held_item_slot: int 

Gets or sets the slot number of the currently held item

helmet property writable

 helmet: ItemStack 

Gets or sets the ItemStack in the helmet slot

item_in_main_hand property writable

 item_in_main_hand: ItemStack 

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

item_in_off_hand property writable

 item_in_off_hand: ItemStack 

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

leggings property writable

 leggings: ItemStack 

Gets or sets the ItemStack in the leg slot

AltStyle によって変換されたページ (->オリジナル) /