I'm super new to scripting, and I was following the tutorial on wiki.bedrock.dev for Custom Spear. I was successfully able to replicate it, and it worked perfectly fine on 1.19.63. However, since the update I haven't been able to fix it, and the spear can't be picked up. This is my code, and I'm sure I messed something up.
import { world, ItemStack, ItemTypes } from "@minecraft/server"
import { system } from "@minecraft/server";
system.events.beforeWatchdogTerminate.subscribe(data => {
data.cancel = true;
});
world.events.itemReleaseCharge.subscribe(ev => {
for (const player of world.getPlayers()) {
let inv = player.getComponent('inventory').container
const itemStack = inv.getItem(player.selectedSlot);
if (itemStack?.typeId === 'tlc:iron_spear') {
var container = player.getComponent('inventory').container
var newItem = new ItemStack(ItemTypes?.get("tlc:iron_spear"));
var oldItem = container?.getItem(player.selectedSlot)
player.removeTag("iron_spear")
}
let e = system.runInterval(() => {
if (player.hasTag("iron_spear") && itemStack?.typeId === 'tlc:iron_spear' && itemStack?.getComponent("durability").damage <= 125) {
player.removeTag("iron_spear")
newItem.getComponent("durability").damage = oldItem.getComponent("durability").damage + 1;
container.setItem(player.selectedSlot, newItem);
if (!player.hasTag("iron_spear")) {
system.runTimeout(() =>
}
}
})
}
})