im trying to make an world edit addon and trying to making a wand that when u click on ground it will get that block location and set it into second lores of the item and when u break the block it will get the location of that block and set it into first lores of the item like this
#1:§rpos1: x y z
#2:§rpos2: x y z
and i got this script:
import * as mc from "@minecraft/server"
mc.world.beforeEvents.itemUseOn.subscribe((data) => {
mc.system.run(() => {
const player = data.source
if (data.itemStack?.typeId != "we:wand") return;
let lores = data.itemStack.getLore() ?? ["§rpos1: - - -", ""]
lores[1] = `§rpos2: ${data.block.location.x} ${data.block.location.y} ${data.block.location.z}`
const item = new mc.ItemStack("we:wand", 1)
item.setLore(lores)
player.getComponent("minecraft:inventory").container.setItem(player.selectedSlot, item)
})
})
the issue that when i click on the ground it crash my game PLS HELP :<