Skip to content
BasaltSoftware
Bedrock 1.26.60

Site colour

Discord
Esc

    ↑↓ moveEnter openEsc close

    Keyboard shortcuts
    Ctrl K
    Search the whole site, from any page
    /
    Jump to the sidebar search, or search the whole site where there isn't one
    Enter
    Open the top search result
    Esc
    Clear the search, or close this panel
    ?
    Show these shortcuts

    Class in @minecraft/server

    A stack of items, held by the script. Changes to it change only it, until it’s given to a player or put in a slot; lore, enchantments and the rest travel with it, and a stack read back from a player has everything it was given.

    import { ItemStack } from '@minecraft/server';
    import { ItemStack, world } from '@minecraft/server';
    const sword = new ItemStack('minecraft:diamond_sword', 1);
    sword.nameTag = 'Basalt Blade';
    sword.setLore(['Forged in the nether']);
    // Hand one to every player.
    for (const player of world.getAllPlayers()) {
    player.getComponent('minecraft:inventory')?.container?.addItem(sword);
    }
    import { ItemStack, world } from '@minecraft/server';
    const sword = new ItemStack('minecraft:diamond_sword', 1);
    sword.nameTag = 'Basalt Blade';
    sword.setLore(['Forged in the nether']);
    // Hand one to every player.
    for (const player of world.getAllPlayers()) {
    player.getComponent('minecraft:inventory')?.container?.addItem(sword);
    }
    constructor(itemType: string | { id: string }, amount?: number);
    Parameters
    itemType
    string | { id: string }The item’s id, as minecraft:diamond (or diamond).
    amountoptional
    numberFrom 1 to 255, kept to the item’s maxAmount.
    Throws
    • TypeError for an item that doesn’t exist; RangeError for an amount out of range.

    read-only

    readonly typeId: string;

    The item, as minecraft:diamond_sword.

    read-only

    readonly type: { readonly id: string };

    The item’s type, whose id is typeId.

    amount: number;

    How many, from 1 to 255, kept to maxAmount.

    Throws
    • RangeError outside 1 to 255.

    optional

    nameTag?: string;

    The item’s custom name, or undefined for none.

    read-only

    readonly maxAmount: number;

    How many of the item stack in one slot.

    read-only

    readonly isStackable: boolean;

    Whether maxAmount is above 1.

    read-only

    readonly localizationKey: string;

    The item’s name key in the language files, as item.diamond_sword.name or tile.stone.name.

    read-only

    readonly weight: number;

    What the stack weighs in a bundle: 64 over maxAmount for each item.

    keepOnDeath: boolean;

    Whether the item stays with a player who dies.

    lockMode: ItemLockMode;

    How the item is held in place in an inventory.

    getLore(): string[];

    The lines shown under the item’s name.

    Returns
    string[]
    getRawLore(): RawMessage[];

    The same as raw messages.

    Returns
    RawMessage[]
    setLore(loreList?: (RawMessage | string)[]): void;

    Sets the lines shown under the item’s name; none takes them away.

    Parameters
    loreListoptional
    (RawMessage | string)[]
    getCanDestroy(): string[];

    The blocks an adventure-mode player may break with the item.

    Returns
    string[]
    setCanDestroy(blockIdentifiers?: string[]): void;
    Parameters
    blockIdentifiersoptional
    string[]
    Throws
    • Error if one isn’t a block.
    getCanPlaceOn(): string[];

    The blocks an adventure-mode player may place the item on.

    Returns
    string[]
    setCanPlaceOn(blockIdentifiers?: string[]): void;
    Parameters
    blockIdentifiersoptional
    string[]
    Throws
    • Error if one isn’t a block.
    getTags(): string[];

    The item type’s tags, as minecraft:is_sword.

    Returns
    string[]
    hasTag(tag: string): boolean;

    Whether the item has this item tag, as minecraft:is_sword.

    Parameters
    tag
    string
    Returns
    boolean
    matches(itemName: string, states?: Record<string, boolean | number | string>): boolean;

    Whether the stack is of this item; states aren’t compared.

    Parameters
    itemName
    string
    statesoptional
    Record<string, boolean | number | string>
    Returns
    boolean
    isStackableWith(itemStack: ItemStack): boolean;

    Whether the two could share a slot: the same item, name, lore, enchantments and so on.

    Parameters
    itemStack
    ItemStack
    Returns
    boolean
    getComponent<T extends keyof ItemComponentTypeMap>(componentId: T): ItemComponentTypeMap[T] | undefined;
    getComponent(componentId: string): ItemComponent | undefined;

    minecraft:durability for items that wear, minecraft:enchantable for those that take enchantments, minecraft:cooldown for those with a cooldown, minecraft:food for food, minecraft:dyeable for leather, minecraft:potion for potions and minecraft:inventory for shulker boxes.

    getComponents(): ItemComponent[];

    Every component the item has.

    Returns
    ItemComponent[]
    hasComponent(componentId: string): boolean;

    Whether the item has the component.

    Parameters
    componentId
    string
    Returns
    boolean
    getDynamicProperty(identifier: string): boolean | number | string | Vector3 | undefined;

    One of this plugin’s dynamic properties on the stack.

    Parameters
    identifier
    string
    Returns
    boolean | number | string | Vector3 | undefined
    Types
    getDynamicPropertyIds(): string[];

    The identifiers of every property this plugin set on the stack.

    Returns
    string[]
    getDynamicPropertyTotalByteCount(): number;

    The bytes this plugin’s properties on the stack take.

    Returns
    number
    setDynamicProperty(identifier: string, value?: boolean | number | string | Vector3): void;

    Sets one of this plugin’s dynamic properties, or with undefined takes it away. They’re kept in the item’s data, so they go wherever it goes.

    Parameters
    identifier
    string
    valueoptional
    boolean | number | string | Vector3
    Throws
    • Error for an item that stacks.
    Types
    setDynamicProperties(values: Record<string, boolean | number | string | Vector3>): void;

    Sets several of this plugin’s properties on the stack at once; undefined values take them away.

    Parameters
    values
    Record<string, boolean | number | string | Vector3>
    Types
    clearDynamicProperties(): void;

    Takes away every property this plugin set on the stack.

    clone(): ItemStack;

    A copy of the stack, everything on it included.

    Returns
    ItemStack

    BlockPermutation.getItemStack, Block.getItemStack, Container.getItem, Container.setItem, Container.addItem, Container.contains, Container.find, Container.findLast, Container.transferItem, EntityItemComponent.itemStack, EntityEquippableComponent.getEquipment, EntityEquippableComponent.setEquipment, ContainerSlot.getItem, ContainerSlot.setItem, ContainerSlot.isStackableWith, Entity.addItem, ItemEntity.itemStack, Player.eatItem, Dimension.spawnItem, ItemSpawnAfterEvent.itemStack, PlayerInteractWithBlockAfterEvent.itemStack, PlayerInteractWithEntityAfterEvent.itemStack, ItemUseAfterEvent.itemStack, PlayerPickupItemAfterEvent.itemStack and 35 more