#Unclear documentation

1 messages · Page 1 of 1 (latest)

tribal wolf
#

i have this:

        const holdingItem = player.getComponent("minecraft:equippable").getEquipment("Mainhand");
        const sneaking = player.isSneaking;


        world.sendMessage(" ");

        world.sendMessage(`typeof: ${typeof holdingItem}`);

        world.sendMessage(`constructor.name: ${holdingItem.constructor?.name}`);

        world.sendMessage(`${holdingItem.nameTag}`);

the first sendMessage (after the empty one) returns the type, which (when holding an item) is object
the second one returns the name of the class that its in, in this case its ItemStack, to which i go and see the class:
https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/itemstack?view=minecraft-bedrock-stable

and based on the documentation, i should be able to get the name using .nameTag but when i do, it returns undefined even though im holding a grass block. Why?

Contents of the @minecraft/server.ItemStack class.

mental flare
#

Could this just be the name of an item which has had a "minecraft:name_tag" applied to it? (Which only applies to entities.) Edit: name of the name tag applied to this stack of items

#

The property .typeId should return the item stack's collective identifier, like "minecraft:grass", if that's what you're looking for

tribal wolf
#

Ohhhhhh ok

#

Lemme see

#

I'm kinda dumb, ofc that's what it means
I didn't scroll lower down to see the typeId

tribal wolf
#

I replaced it with .itemId and it still returns undefined

#

nvm i didnt save

mental flare
tribal wolf
#

yeah

#

its alot of text and its not clear exactly

sour fable
#

nameTag is undefined if you don't rename the item

exotic mango