import { world } from "@minecraft/server";
import { Vector3 } from "../Vector3";
import { spawnParticleAtPlayer } from "../SpawnParticle";

//Function run when using the spell
export function weatherSpell(player) {
  //Send chat message
  player.sendMessage(`<${player.nameTag}> Weather spell!`);
  //Particles
  const yaw = player.getRotation().y;
  const radYaw = yaw * (Math.PI / 180);
  const particleLoc = new Vector3(player.location.x - Math.sin(radYaw), player.location.y, player.location.z + Math.cos(radYaw));
  spawnParticleAtPlayer(player, "blockception_magic:weather_trail_1", particleLoc);
  spawnParticleAtPlayer(player, "blockception_magic:weather_trail_2", particleLoc);
  spawnParticleAtPlayer(player, "blockception_magic:weather_trail_fog", particleLoc);
  spawnParticleAtPlayer(player, "blockception_magic:weather_hit", particleLoc);
  spawnParticleAtPlayer(player, "blockception_magic:weather_hit_fog", particleLoc);

  //Summon entity
  world.getDimension(player.dimension.id).spawnEntity('blockception_magic:weather_spell', player.location);
}