import { EquipmentSlot, world } from "@minecraft/server";
const natRegen = () => world.gameRules?.naturalRegeneration ?? true;

export const cobalt_armor = {

  id: "cobalt",
  intervaloTicks: 10,
  piezas: [
    "dungeon:cobalt_helmet",
    "dungeon:cobalt_chestplate",
    "dungeon:cobalt_leggings",
    "dungeon:cobalt_boots"
  ],
  verificar(equip) {
    if (!natRegen()) return;

    return this.piezas.every((id, i) => {
      const slot = [EquipmentSlot.Head, EquipmentSlot.Chest, EquipmentSlot.Legs, EquipmentSlot.Feet][i];
      const item = equip.getEquipment(slot);
      return item && item.typeId === id;
    });
  },
  accion(player, health) {
  if (!natRegen()) return;

  const current = health.currentValue;
  const max = health.effectiveMax;

  if (current > 0 && current < max) {
    player.runCommand("particle minecraft:heart_particle ~ ~2 ~");
    health.setCurrentValue(Math.min(current + 1, max));
  }
}};