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

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

export function waterSpellEvent(location, dimension) {
  let block = world.getDimension(dimension.id).getBlock(location);
  if (block.getItemStack() == undefined) {
    block.setPermutation(BlockPermutation.resolve("minecraft:water"));
    let blockAbove = world.getDimension(dimension.id).getBlock(new Vector3(location.x, location.y + 1, location.z));
    if (blockAbove.getItemStack() == undefined) {
      blockAbove.setPermutation(BlockPermutation.resolve("minecraft:water"));
      blockAbove.setPermutation(BlockPermutation.resolve("minecraft:air"));
    }
  }
}