import { EntityComponentTypes, system } from "@minecraft/server";
import { serpentDragonArmorConfig } from "../DATA/ArmorConfig";
export function reflectProjectiles(log, player) {
    const entities = player.dimension.getEntities({
        maxDistance: serpentDragonArmorConfig.effectRange,
        location: player.location,
        excludeTypes: ["player"],
    });
    for (const entity of entities) {
        const projectileComponent = entity.getComponent(EntityComponentTypes.Projectile);
        if (projectileComponent && projectileComponent.isValid()) {
            const owner = projectileComponent.owner;
            if (owner && owner.isValid() && owner !== player) {
                entity.clearVelocity();
                const { pX, pY, pZ } = {
                    pX: owner.location.x - entity.location.x,
                    pY: owner.location.y + serpentDragonArmorConfig.targetYOffset - entity.location.y,
                    pZ: owner.location.z - entity.location.z,
                };
                const multiplier = Math.sqrt(pX * pX + pY * pY + pZ * pZ) * serpentDragonArmorConfig.velocityMultiplier;
                const velocity = {
                    x: pX / multiplier,
                    y: pY / multiplier,
                    z: pZ / multiplier,
                };
                player.dimension.runCommandAsync(`summon ${entity.typeId} ${entity.location.x} ${entity.location.y} ${entity.location.z} ${entity.getRotation().y - 180} ${entity.getRotation().x}`);
                const entityLocation = entity.location;
                const entityTypeId = entity.typeId;
                entity.remove();
                system.runTimeout(() => {
                    const returnProjectile = player.dimension.getEntities({
                        location: entityLocation,
                        closest: 1,
                        type: entityTypeId,
                    })[0];
                    const returnProjectileComponent = returnProjectile.getComponent(EntityComponentTypes.Projectile);
                    returnProjectileComponent.shoot(velocity);
                }, 1);
            }
        }
    }
}

//# sourceMappingURL=../../../../../_KiCuMountsBPDebug/kicu/mmad/A/SerpentDragonArmor.js.map
