//item.js
import * as mc from "@minecraft/server";
export const Item = {
    durability: function (player, itemPart, equipmentSlot) {
        try {

            let durability = itemPart?.getComponent("durability");
            let currentDurability = durability?.maxDurability - durability?.damage
            const equipment = player.getComponent("minecraft:equippable")

    
    
            if (currentDurability > 1) {
                durability.damage = durability.damage + 1
                
                equipment.setEquipment(equipmentSlot, itemPart)
                
            } else {
                equipment.setEquipment(equipmentSlot, undefined);
                //player.playSound('random.break', player.location)
            }
        } catch (e) {
    
            mc.world.sendMessage(e);
        }
    }
};
