import * as mc from "@minecraft/server";
import { Vector3, clamp } from "./utils/index";
export function knockBackEntity(entity, direction, horizontalStrengthFactor, verticalStrengthFactor) {
    const isBeingKnockedBack = entity.getDynamicProperty("ldz:is_being_knocked_back");
    if (isBeingKnockedBack)
        return false;
    entity.setDynamicProperty("ldz:is_being_knocked_back", true);
    mc.system.runTimeout(() => entity.isValid() && entity.setDynamicProperty("ldz:is_being_knocked_back", undefined), 1);
    const directionX = direction.x;
    const directionZ = direction.z;
    const horizontalStrength = direction.multiply({ x: 1, y: 0, z: 1 }).distance(new Vector3(0)) * horizontalStrengthFactor;
    const verticalStrength = (clamp(direction.y, 0, 100) + 0.4) * verticalStrengthFactor;
    entity.applyKnockback(directionX, directionZ, horizontalStrength, verticalStrength);
    return true;
}
