import * as mc from "@minecraft/server";
import * as utils from "../utils/index";
import { ignoreEntities } from "../shared/constants";
const duration = 6;
export async function pistonAbility(player) {
    utils.mclog(`piston`);
    mc.world.playSound('random.pop2', player.location);
    const piston = player.dimension.spawnEntity('ldz:piston_ability', player.location);
    const endTime = mc.system.currentTick + duration;
    await utils.waitForLoopEvent(0, () => {
        piston.teleport(player.location);
        return mc.system.currentTick >= endTime;
    });
    mc.world.playSound('tile.piston.out', player.location);
    const origin = new utils.Vector3(player.location);
    player.dimension.getEntities({ location: player.location, maxDistance: 10, excludeTypes: ignoreEntities, excludeNames: [player.nameTag], excludeTags: ['friendlyFireOff'] }).forEach(victim => {
        const direction = new utils.Vector3(victim.location).subtract(origin).normalize();
        victim.applyKnockback(direction.x, direction.z, 8, 1.5);
    });
}
