import { GameMode } from "@minecraft/server";
export function DamageItem(player, slot, damage = 1) {
    const equip = player.equippable;
    const item = equip.getEquipment(slot);
    if (!item || player.getGameMode() === GameMode.creative)
        return;
    const durability = item.getComponent('durability');
    if (durability.damage + damage >= durability.maxDurability) {
        player.playSound('random.break');
        return equip.setEquipment(slot);
    }
    const enchantable = item.getComponent('enchantable');
    const unbreaking = enchantable?.getEnchantment('unbreaking')?.level ?? 0;
    if (Math.random() * 100 <= (100 / (unbreaking + 1)))
        durability.damage += damage;
    equip.setEquipment(slot, item);
}
