#how to run a command if an item is eaten
1 messages · Page 1 of 1 (latest)
anybody
Item:
"format_version": "1.21.60",
"minecraft:item": {
"description": {
"identifier": "realm:adminkey",
"menu_category": {
"category": "items"
}
},
"components": {
"minecraft:max_stack_size": 1,
"minecraft:icon": {
"textures": {
"default": "realm:adminkey"
}
}
}
}
}
main.js
world.afterEvents.itemUse.subscribe((event) => {
const player = event.source;
const item = event.itemStack;
if (!player || !item) return;
if (item.typeId === "realm:adminkey") {
const overworld = world.getDimension("overworld");
player.runCommand("tp @s -1 39 5013 facing ~ ~0 ~-180");
}
});
Instead of itemUse u should use itemCompleteUse
maybe they mean after the item is eaten, like food item