import { world, EntityComponentTypes, ItemComponentTypes, EquipmentSlot, Player, GameMode } from "@minecraft/server";
/**
 * @param {Player} player
 * @param {EquipmentSlot} slot
 * @param {number} amount 
 */
export function damageItem(player, slot, amount) {
  try {
    if (player.getGameMode() === GameMode.Creative) return;
    const equippable = player.getComponent(EntityComponentTypes.Equippable);

    const item = equippable.getEquipment(slot);

    if (!item) return; 

    const durability = item.getComponent(ItemComponentTypes.Durability);
    durability.damage = durability.damage + amount

    equippable.setEquipment(slot, item);
  } catch (e) {
    return;
  }
}