#Can't seem to obtain item components?

1 messages · Page 1 of 1 (latest)

livid pumice
#

[@minecraft/server ver: 2.1.0, client ver: 26.21]
I want to access components (only read) on an item entity. I can get the 'minecraft:item' component for it, but any attempt to get actual item components fail, always returning undefined. I also used found that the output of ItemStack.getComponents() seems to just return an empty array?

I then had the idea to take the ItemStack.typeId, which was accessible, to create a fresh ItemStack that I could hopefully access more properly. Unfortunately, I found only the same thing.

Here was my code to do that:

world.afterEvents.entitySpawn.subscribe((event) => {
    const {entity} = event
    if (entity.hasComponent('minecraft:item')) {
        let item = entity.getComponent('minecraft:item').itemStack
        let itemType = new ItemStack(item.typeId)
        debugLog(itemType.getComponents(), 'itemComps')
        let foodData = itemType.getComponent('minecraft:food')
        debugLog(foodData)
    }
})

Both using item.getComponent(...) and itemType.getComponent(...) yeild the same result.

debugLog(text, tag) is a simple function a made, consider it equivalent to console.log() or world.sendMessage()

#

Specifically, I want to access the usingConvertsTo property of the minecraft:food component.

brisk leaf
livid pumice
#

I wasn't sure if using JSON.stringify() on the return of getComponents() actually worked properly which might explain why that didnt work

spark zealot