Mojira Archive
MCPE-175975

Scripting API: ItemStack.amount no longer exists in recent stable releases

Since the release of version 1.3.0 of the scripting API, the "amount" field has disappeared from the ItemStack class. There is currently no other way to check the amount of an item. In the beta version, this field is still available, but is not present in 1.3.0, 1.4.0 and 1.5.0. The ItemStack class structure copied from official npm repository:
 

export class ItemStack {
    readonly isStackable: boolean;
    readonly maxAmount: number;
    readonly 'type': ItemType;
    readonly typeId: string;
    constructor(itemType: ItemType | string, amount?: number);
    getComponent(componentId: string): ItemComponent | undefined;
    getComponents(): ItemComponent[];
    getLore(): string[];
    hasComponent(componentId: string): boolean;
    isStackableWith(itemStack: ItemStack): boolean;
    setLore(loreList?: string[]): void;
}

How to reproduce:
1. Create a behavior pack and enable scripting
2. Paste the following code into main.js:

import { ItemStack } from "@minecraft/server";
const item = new ItemStack("minecraft:dirt", 32);
console.log(item.amount);

3. Run the server/world

 

Expected console response (1.2.0):

[2023-10-13 11:10:24:756 INFO] [Scripting] 32 

Actual console response (1.3.0, 1.4.0, 1.5.0):

[2023-10-13 11:12:20:362 ERROR] [Scripting] Plugin [pack.name - 1.0.0] - [main.js] ran with error: [Error: null] 

Awaiting Response

Kalendarz2

2023-10-13, 12:37 PM

2024-01-03, 10:58 PM

2024-01-03, 10:58 PM

0

2

Unconfirmed

Script-API

1.20.32 Hotfix

-