import { world, EffectTypes } from "@minecraft/server";
import { mobList } from "./MobList";
import { Vector3 } from "../Vector3";
import { spawnParticleAtPlayer } from "../SpawnParticle";

//Function run when using the spell
export function revealingSpell(player) {
  player.sendMessage(`<${player.nameTag}> Revealing spell!`);
  player.addEffect(EffectTypes.get('night_vision'), 100, {amplifier: 1, showParticles: false});
  const particleLoc = new Vector3(player.location.x, player.location.y, player.location.z);
  spawnParticleAtPlayer(player, "blockception_magic:reveal_spell", particleLoc);
  spawnParticleAtPlayer(player, "blockception_magic:reveal_spell_fog", particleLoc);
  const entities = world.getDimension(player.dimension.id).getEntities({
    location: player.location,
    maxDistance: 48,
  })
  entities.forEach(entity => {
    //Make sure the entity is a monster/animal etc
    if (!(entity.typeId in mobList)) {
      return;
    }
    let location = new Vector3(entity.location.x, entity.location.y + 2.5, entity.location.z);
    let marker = entity.dimension.spawnEntity('blockception_magic:reveal_marker', location);
    marker.triggerEvent(`icon:${mobList[entity.typeId].family}`);
  })
}