#Difference between onUse Methods
1 messages · Page 1 of 1 (latest)
M1:
import { world } from "@minecraft/server"
const onUseComp = {
onUse({ source, itemStack }) {
world.sendMessage('Item used: ' + itemStack.typeId);
}
}
world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
itemComponentRegistry.registerCustomComponent('mc:on_use_component', onUseComp);
});
M2:
world.afterEvents.itemUse.subscribe(({itemStack, source: player}) => {
if (itemStack?.typeId == "mvm:flare_thrown") {
world.getDimension("overworld").playSound("firework.launch", player.location)
}
})```
I've seen both sent around here and I'm curious about whether there is or isn't any practical difference between them
One doesnt need a guard clause since its registered on the item.
Uhhhhh I don't know like anything deep about script so can you translate that 😭
Custom components dont need
If(item id != your item) return;