import { world, BlockPermutation } from "@minecraft/server";
import { castSpellProjectile } from "./Spells";
import { Vector3 } from "../Vector3";

//Function run when using the spell
export function fireSpell(player) {
  player.sendMessage(`<${player.nameTag}> Fire spell!`);
  castSpellProjectile(player, "blockception_magic:fire_spell", 2);
}

export function fireSpellEvent(location, dimension) {
  const radius = 2.5;
  const centreX = Math.floor(location.x) + 0.5;
  const centreZ = Math.floor(location.z) + 0.5;
  const centreY = location.y;

  for (let angle = 0; angle < 360; angle += 20) {
    for (let distance = 0; distance <= radius; distance++) {
      const radAngle = angle * (Math.PI / 180);
      let fireX = centreX + distance * Math.cos(radAngle);
      let fireZ = centreZ + distance * Math.sin(radAngle);
      let fireLocation = new Vector3(fireX, centreY, fireZ);
      const fireBlock = world.getDimension(dimension.id).getBlock(fireLocation);
      if (fireBlock.getItemStack() == undefined) {
        fireBlock.setPermutation(BlockPermutation.resolve("minecraft:fire"));
      }
    }
  }
}