import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
const down = { x: 0, y: -1, z: 0 };
export async function villageAbility(player) {
    utils.mclog(`village`);
    mc.world.playSound('mob.villager.yes', player.location);
    for (let index = 0; index < 360; index += 45) {
        const direction = new utils.Vector3({ x: 0, y: 0, z: 1 }).rotateByAngle(index);
        utils.mclog(direction.toString());
        const origin = new utils.Vector3(player.getHeadLocation()).add(direction.multiply(3));
        const block = player.dimension.getBlockFromRay(origin, down, { includeLiquidBlocks: false, includePassableBlocks: false, maxDistance: 5 });
        let target = new utils.Vector3(player.location).add(direction.multiply(3));
        if (block) {
            target = new utils.Vector3(block.block.location).add(new utils.Vector3(block.faceLocation));
        }
        mc.world.playSound('resonate.amethyst_block', target);
        utils.runCommand(`particle ldz:village_ability ${target.toCommandString()}`);
        for (let index = 0; index < utils.getRandomInteger(1, 5); index++) {
            const stack = player.dimension.spawnItem(new mc.ItemStack('minecraft:emerald', 1), target);
            const impulse = new utils.Vector3({ x: 0, y: 0, z: 1 }).rotateByAngle(utils.getRandomInteger(-180, 180)).normalize().multiply(0.05);
            stack.applyImpulse(impulse);
            await utils.waitForEvent(2, () => { });
        }
    }
}
