mojira.dev
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]

Attachments

Comments 2

Cannot reproduce in 1.20.51 using version 1.7.0 of the API (singleplayer)

I opted to use "console.warn" with the script provided instead of "console.log", as the latter didn't function properly for me. From what I've observed, by directly storing all the console's output logs in the log folder, not only is this inconvenient since the output isn't visible in-game, but also results with "???" being found in said log files (using versions 1.2.0 or older of the API doesn't fix this). 

Check the attached screenshot.

OP please can you see if you can reproduce this?

Kalendarz2

(Unassigned)

Unconfirmed

Multiple

Windows 11

Script-API

1.20.32 Hotfix

Retrieved