import { world, system } from "@minecraft/server";

// Wither Armour

world.afterEvents.entityDie.subscribe((event) => {
    const deadEntity = event.deadEntity;
    const damageSource = event.damageSource.damagingEntity;
    if (!damageSource) { return; }
    if (damageSource.typeId === "minecraft:player" && damageSource.hasTag('wither_armour') && (deadEntity.matches({families: ['monster'] }) || deadEntity.matches({families: ['mob'] }) )) {
            damageSource.runCommandAsync('particle dungeons:lifesteal ~~~')
            let hp = damageSource.getComponent('minecraft:health')
            hp.setCurrentValue( hp.currentValue + 1)
    }
});

// Fox Armour

system.runInterval(() => {
  for (const player of world.getPlayers()) {
    if (player.isSprinting && player.hasTag("fox_armour")) {
      player.addEffect("speed", 3, {amplifier: 0, showParticles: false});
    }
  }
});

// Frost Armour

system.runInterval(() => {
  for (const player of world.getPlayers()) {
    if (player.hasTag("frost_armour")) {
      const nearbyMobs = player.dimension.getEntities({location: player.location, maxDistance: 8, families: ['monster']});

      for(const mob of nearbyMobs) {
        mob.runCommandAsync('particle dungeons:element_freeze ~~1~')
        mob.addEffect("slowness", 30, {amplifier: 0, showParticles: false});
      }
    }
  }
}, 30);



