Class in @minecraft/server
A player’s 36 inventory slots, the hotbar first, or the slots inside an item.
import { Container } from '@minecraft/server';Properties
Section titled “Properties”read-only
readonly size: number;isValid
Section titled “isValid”read-only
readonly isValid: boolean;emptySlotsCount
Section titled “emptySlotsCount”read-only
readonly emptySlotsCount: number;weight
Section titled “weight”read-only
readonly weight: number;The combined bundle weight of the contents.
containerRules
Section titled “containerRules”read-only optional
readonly containerRules?: ContainerRules;The rules on what the container accepts, if any.
Methods
Section titled “Methods”getItem
Section titled “getItem”getItem(slot: number): ItemStack | undefined;slotnumber
ItemStack | undefinedsetItem
Section titled “setItem”setItem(slot: number, itemStack?: ItemStack): void;Puts an item in a slot, or empties it with undefined.
slotnumberitemStackoptionalItemStack
addItem
Section titled “addItem”addItem(itemStack: ItemStack): ItemStack | undefined;Gives the item, dropping what doesn’t fit. Basalt doesn’t say what was left.
itemStackItemStack
ItemStack | undefinedclearAll
Section titled “clearAll”clearAll(): void;contains
Section titled “contains”contains(itemStack: ItemStack): boolean;Whether a slot holds this item, whatever the amount.
itemStackItemStack
booleanfind(itemStack: ItemStack): number | undefined;The first slot holding this item, whatever the amount.
itemStackItemStack
number | undefinedfindLast
Section titled “findLast”findLast(itemStack: ItemStack): number | undefined;The last slot holding this item.
itemStackItemStack
number | undefinedfirstEmptySlot
Section titled “firstEmptySlot”firstEmptySlot(): number | undefined;The first empty slot, or undefined if it’s full.
number | undefinedfirstItem
Section titled “firstItem”firstItem(): number | undefined;The first slot holding anything.
number | undefinedswapItems
Section titled “swapItems”swapItems(slot: number, otherSlot: number, otherContainer: Container): void;Swaps a slot of this container with one of another, or of this one again.
slotnumberotherSlotnumberotherContainerContainer
getSlot
Section titled “getSlot”getSlot(slot: number): ContainerSlot;A live handle on a slot.
slotnumber
ContainerSlotmoveItem
Section titled “moveItem”moveItem(fromSlot: number, toSlot: number, toContainer: Container): void;Moves an item to another slot of a container.
fromSlotnumbertoSlotnumbertoContainerContainer
transferItem
Section titled “transferItem”transferItem(fromSlot: number, toContainer: Container): ItemStack | undefined;Transfers an item into the first fitting slot of a container.
fromSlotnumbertoContainerContainer
ItemStack | undefinedUsed by
Section titled “Used by”ItemInventoryComponent.container, EntityInventoryComponent.container, BlockInventoryComponent.container, EntityEnderInventoryComponent.container