Skip to content

@minecraft/server


@minecraft/server / ContainerSlot

Class: ContainerSlot ​

Defined in: @minecraft/server/index.d.ts:6656

Represents a slot within a broader container (e.g., entity inventory.)

Properties ​

amount ​

amount: number

Defined in: @minecraft/server/index.d.ts:6670

Remarks ​

Number of the items in the stack. Valid values range between 1-255. The provided value will be clamped to the item's maximum stack size.

This property can't be edited in restricted-execution mode.

Bounds: [1, 255]

Throws ​

Throws if the value is outside the range of 1-255.


isStackable ​

readonly isStackable: boolean

Defined in: @minecraft/server/index.d.ts:6682

Remarks ​

Returns whether the item is stackable. An item is considered stackable if the item's maximum stack size is greater than 1 and the item does not contain any custom data or properties.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


isValid ​

readonly isValid: boolean

Defined in: @minecraft/server/index.d.ts:6690

Remarks ​

Returns whether the ContainerSlot is valid. The container slot is valid if the container exists and is loaded, and the slot index is valid.


keepOnDeath ​

keepOnDeath: boolean

Defined in: @minecraft/server/index.d.ts:6700

Remarks ​

Gets or sets whether the item is kept on death.

This property can't be edited in restricted-execution mode.

Throws ​

Throws if the slot's container is invalid.


lockMode ​

lockMode: ItemLockMode

Defined in: @minecraft/server/index.d.ts:6711

Remarks ​

Gets or sets the item's lock mode. The default value is ItemLockMode.none.

This property can't be edited in restricted-execution mode.

Throws ​

Throws if the slot's container is invalid.


maxAmount ​

readonly maxAmount: number

Defined in: @minecraft/server/index.d.ts:6723

Remarks ​

The maximum stack size. This value varies depending on the type of item. For example, torches have a maximum stack size of 64, while eggs have a maximum stack size of 16.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


nameTag? ​

optional nameTag?: string

Defined in: @minecraft/server/index.d.ts:6736

Remarks ​

Given name of this stack of items. The name tag is displayed when hovering over the item. Setting the name tag to an empty string or undefined will remove the name tag.

This property can't be edited in restricted-execution mode.

Throws ​

Throws if the slot's container is invalid. Also throws if the length exceeds 255 characters.


type ​

readonly type: ItemType

Defined in: @minecraft/server/index.d.ts:6748

Remarks ​

The type of the item.

Throws ​

Throws if the slot's container is invalid.

minecraftcommon.EngineError

InvalidContainerSlotError


typeId ​

readonly typeId: string

Defined in: @minecraft/server/index.d.ts:6760

Remarks ​

Identifier of the type of items for the stack. If a namespace is not specified, 'minecraft:' is assumed. Examples include 'wheat' or 'apple'.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError

Methods ​

clearDynamicProperties() ​

clearDynamicProperties(): void

Defined in: @minecraft/server/index.d.ts:6771

Returns ​

void

Remarks ​

Clears all dynamic properties that have been set on this item stack.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


getCanDestroy() ​

getCanDestroy(): string[]

Defined in: @minecraft/server/index.d.ts:6781

Returns ​

string[]

Remarks ​

Returns whether the item within this container slot can be destroyed.

Throws ​

This function can throw errors.

InvalidContainerSlotError


getCanPlaceOn() ​

getCanPlaceOn(): string[]

Defined in: @minecraft/server/index.d.ts:6790

Returns ​

string[]

Remarks ​

Returns if the item in this container slot can be placed on.

Throws ​

This function can throw errors.

InvalidContainerSlotError


getDynamicProperty() ​

getDynamicProperty(identifier): string | number | boolean | Vector3 | undefined

Defined in: @minecraft/server/index.d.ts:6805

Parameters ​

identifier ​

string

The property identifier.

Returns ​

string | number | boolean | Vector3 | undefined

Returns the value for the property, or undefined if the property has not been set.

Remarks ​

Returns a property value.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


getDynamicPropertyIds() ​

getDynamicPropertyIds(): string[]

Defined in: @minecraft/server/index.d.ts:6818

Returns ​

string[]

A string array of the dynamic properties set on this entity.

Remarks ​

Returns the available set of dynamic property identifiers that have been used on this item stack.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


getDynamicPropertyTotalByteCount() ​

getDynamicPropertyTotalByteCount(): number

Defined in: @minecraft/server/index.d.ts:6833

Returns ​

number

Remarks ​

Returns the total size, in bytes, of all the dynamic properties that are currently stored for this entity. This includes the size of both the key and the value. This can be useful for diagnosing performance warning signs - if, for example, an entity has many megabytes of associated dynamic properties, it may be slow to load on various devices.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


getItem() ​

getItem(): ItemStack | undefined

Defined in: @minecraft/server/index.d.ts:6847

Returns ​

ItemStack | undefined

Returns a copy of the item in the slot. Returns undefined if the slot is empty.

Remarks ​

Creates an exact copy of the item stack, including any custom data or properties.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


getLore() ​

getLore(): string[]

Defined in: @minecraft/server/index.d.ts:6861

Returns ​

string[]

An array of lore strings. If the item does not have lore, returns an empty array.

Remarks ​

Returns the lore value - a secondary display string - for an ItemStack.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


getRawLore() ​

getRawLore(): RawMessage[]

Defined in: @minecraft/server/index.d.ts:6875

Returns ​

RawMessage[]

An array of lore lines. If the item does not have lore, returns an empty array.

Remarks ​

Returns the lore value - a secondary display string - for an ItemStack. String lore lines will be converted to a RawMessage and put under RawMessage.text.

Throws ​

This function can throw errors.

InvalidContainerSlotError


getTags() ​

getTags(): string[]

Defined in: @minecraft/server/index.d.ts:6888

Returns ​

string[]

Returns all tags for the item in the slot. Return an empty array if the the slot is empty.

Remarks ​

Returns all tags for the item in the slot.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


hasItem() ​

hasItem(): boolean

Defined in: @minecraft/server/index.d.ts:6897

Returns ​

boolean

Remarks ​

Returns true if this slot has an item.

Throws ​

This function can throw errors.

InvalidContainerSlotError


hasTag() ​

hasTag(tag): boolean

Defined in: @minecraft/server/index.d.ts:6912

Parameters ​

tag ​

string

The item tag.

Returns ​

boolean

Returns false when the slot is empty or the item in the slot does not have the given tag.

Remarks ​

Returns whether the item in the slot slot has the given tag.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


isStackableWith() ​

isStackableWith(itemStack): boolean

Defined in: @minecraft/server/index.d.ts:6931

Parameters ​

itemStack ​

ItemStack

The ItemStack that is being compared.

Returns ​

boolean

Returns whether this item stack can be stacked with the given itemStack.

Remarks ​

Returns whether this item stack can be stacked with the given itemStack. This is determined by comparing the item type and any custom data and properties associated with the item stacks. The amount of each item stack is not taken into consideration.

Throws ​

Throws if the slot's container is invalid.

InvalidContainerSlotError


setCanDestroy() ​

setCanDestroy(blockIdentifiers?): void

Defined in: @minecraft/server/index.d.ts:6950

Parameters ​

blockIdentifiers? ​

string[]

The list of blocks, given by their identifiers.

Returns ​

void

Remarks ​

The list of block types this item can break in Adventure mode. The block names are displayed in the item's tooltip. Setting the value to undefined will clear the list.

This function can't be called in restricted-execution mode.

Throws ​

Throws if the slot's container is invalid. Also throws if any of the provided block identifiers are invalid.

Error

InvalidContainerSlotError


setCanPlaceOn() ​

setCanPlaceOn(blockIdentifiers?): void

Defined in: @minecraft/server/index.d.ts:6970

Parameters ​

blockIdentifiers? ​

string[]

The list of blocks, given by their identifiers.

Returns ​

void

Remarks ​

The list of block types this item can be placed on in Adventure mode. This is only applicable to block items. The block names are displayed in the item's tooltip. Setting the value to undefined will clear the list.

This function can't be called in restricted-execution mode.

Throws ​

Throws if the slot's container is invalid. Also throws if any of the provided block identifiers are invalid.

Error

InvalidContainerSlotError


setDynamicProperties() ​

setDynamicProperties(values): void

Defined in: @minecraft/server/index.d.ts:6987

Parameters ​

values ​

Record<string, boolean | number | string | Vector3 | undefined>

A Record of key value pairs of the dynamic properties to set. If the data value is null, it will remove that property instead.

Returns ​

void

Remarks ​

Sets multiple dynamic properties with specific values.

Throws ​

This function can throw errors.

minecraftcommon.ArgumentOutOfBoundsError

InvalidContainerSlotError

minecraftcommon.UnsupportedFunctionalityError


setDynamicProperty() ​

setDynamicProperty(identifier, value?): void

Defined in: @minecraft/server/index.d.ts:7006

Parameters ​

identifier ​

string

The property identifier.

value? ​

string | number | boolean | Vector3

Data value of the property to set. If the value is null, it will remove the property instead.

Returns ​

void

Remarks ​

Sets a specified property to a value.

Throws ​

Throws if the slot's container is invalid.

minecraftcommon.ArgumentOutOfBoundsError

InvalidContainerSlotError

minecraftcommon.UnsupportedFunctionalityError


setItem() ​

setItem(itemStack?): void

Defined in: @minecraft/server/index.d.ts:7023

Parameters ​

itemStack? ​

ItemStack

The ItemStack to be placed in the slot.

Returns ​

void

Remarks ​

Sets the given ItemStack in the slot, replacing any existing item.

This function can't be called in restricted-execution mode.

Throws ​

Throws if the slot's container is invalid.

ContainerRulesError

InvalidContainerSlotError


setLore() ​

setLore(loreList?): void

Defined in: @minecraft/server/index.d.ts:7043

Parameters ​

loreList? ​

(string | RawMessage)[]

A list of lore strings. Setting this argument to undefined will clear the lore.

Returns ​

void

Remarks ​

Sets the lore value - a secondary display string - for an ItemStack.

This function can't be called in restricted-execution mode.

Throws ​

Throws if the slot's container is invalid.

minecraftcommon.ArgumentOutOfBoundsError

Error

InvalidContainerSlotError