RotateUtil | Exp 3.1 and more...

Начинающий
Статус
Оффлайн
Регистрация
6 Окт 2024
Сообщения
18
Реакции[?]
0
Поинты[?]
0
Credits: tg: @CacheSystem

Sel$codd:
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.entity.Entity;
import net.minecraft.client.Minecraft;

/**
 * [USER=35246]@Author[/USER] cachesystem
 * [USER=30931]@since[/USER] 09.11.2024
 */
public class RotateUtils {

    // no pasta its sel$$$$$$$$$codeeeeeede
    public static Vector2f calculateAngle(Entity target) {
        Vector3d playerPos = Minecraft.getInstance().player.getEyePosition(1.0F);
        Vector3d targetPos = target.getPositionVec().add(0, target.getEyeHeight() / 2.0, 0);

        Vector3d diff = targetPos.subtract(playerPos);
        double dist = diff.length();
      
        float yaw = (float) MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(diff.z, diff.x)) - 90.0);
        float pitch = (float) -Math.toDegrees(Math.atan2(diff.y, dist));
      
        return new Vector2f(yaw, pitch);
    }

    public static Vector2f smoothRotate(float currentYaw, float currentPitch, float targetYaw, float targetPitch, float yawSpeed, float pitchSpeed, float yawThreshold, float pitchThreshold) {
        float yawDelta = MathHelper.wrapDegrees(targetYaw - currentYaw);
        float pitchDelta = MathHelper.wrapDegrees(targetPitch - currentPitch);
        if (Math.abs(yawDelta) < yawThreshold && Math.abs(pitchDelta) < pitchThreshold) {
            return new Vector2f(currentYaw, currentPitch);
        }

        float clampedYaw = MathHelper.clamp(yawDelta, -yawSpeed, yawSpeed);
        float clampedPitch = MathHelper.clamp(pitchDelta, -pitchSpeed, pitchSpeed);

        float newYaw = currentYaw + clampedYaw;
        float newPitch = MathHelper.clamp(currentPitch + clampedPitch, -90, 90);

        return new Vector2f(newYaw, newPitch);
    }

    public static boolean isLookingAt(Entity target, float threshold) {
        Vector2f angles = calculateAngle(target);
        return isAngleWithinThreshold(angles.x, Minecraft.getInstance().player.rotationYaw, angles.y, Minecraft.getInstance().player.rotationPitch, threshold);
    }

    // privet
    private static boolean isAngleWithinThreshold(float targetYaw, float currentYaw, float targetPitch, float currentPitch, float threshold) {
        float yawDifference = MathHelper.wrapDegrees(targetYaw - currentYaw);
        float pitchDifference = MathHelper.wrapDegrees(targetPitch - currentPitch);
        return Math.abs(yawDifference) < threshold && Math.abs(pitchDifference) < threshold;
    }
}
 
Последнее редактирование:
Начинающий
Статус
Оффлайн
Регистрация
8 Авг 2024
Сообщения
780
Реакции[?]
5
Поинты[?]
5K
чо это делает ваще
UPD: короч я понял че это оно короче наводится на игрока просто и всё, ну и как обычно дергается
 
Последнее редактирование:
Забаненный
Статус
Оффлайн
Регистрация
26 Окт 2024
Сообщения
122
Реакции[?]
0
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Credits: tg: @CacheSystem

Sel$codd:
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.entity.Entity;
import net.minecraft.client.Minecraft;

/**
[LIST]
[*][USER=35246]@Author[/USER] cachesystem
[*][USER=30931]@since[/USER] 09.11.2024
[/LIST]
*/
public class RotateUtils {

    // no pasta its sel$$$$$$$$$codeeeeeede
    public static Vector2f calculateAngle(Entity target) {
        Vector3d playerPos = Minecraft.getInstance().player.getEyePosition(1.0F);
        Vector3d targetPos = target.getPositionVec().add(0, target.getEyeHeight() / 2.0, 0);

        Vector3d diff = targetPos.subtract(playerPos);
        double dist = diff.length();
     
        float yaw = (float) MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(diff.z, diff.x)) - 90.0);
        float pitch = (float) -Math.toDegrees(Math.atan2(diff.y, dist));
     
        return new Vector2f(yaw, pitch);
    }

    public static Vector2f smoothRotate(float currentYaw, float currentPitch, float targetYaw, float targetPitch, float yawSpeed, float pitchSpeed, float yawThreshold, float pitchThreshold) {
        float yawDelta = MathHelper.wrapDegrees(targetYaw - currentYaw);
        float pitchDelta = MathHelper.wrapDegrees(targetPitch - currentPitch);
        if (Math.abs(yawDelta) < yawThreshold && Math.abs(pitchDelta) < pitchThreshold) {
            return new Vector2f(currentYaw, currentPitch);
        }

        float clampedYaw = MathHelper.clamp(yawDelta, -yawSpeed, yawSpeed);
        float clampedPitch = MathHelper.clamp(pitchDelta, -pitchSpeed, pitchSpeed);

        float newYaw = currentYaw + clampedYaw;
        float newPitch = MathHelper.clamp(currentPitch + clampedPitch, -90, 90);

        return new Vector2f(newYaw, newPitch);
    }

    public static boolean isLookingAt(Entity target, float threshold) {
        Vector2f angles = calculateAngle(target);
        return isAngleWithinThreshold(angles.x, Minecraft.getInstance().player.rotationYaw, angles.y, Minecraft.getInstance().player.rotationPitch, threshold);
    }

    // privet
    private static boolean isAngleWithinThreshold(float targetYaw, float currentYaw, float targetPitch, float currentPitch, float threshold) {
        float yawDifference = MathHelper.wrapDegrees(targetYaw - currentYaw);
        float pitchDifference = MathHelper.wrapDegrees(targetPitch - currentPitch);
        return Math.abs(yawDifference) < threshold && Math.abs(pitchDifference) < threshold;
    }
}
/del
 
Начинающий
Статус
Оффлайн
Регистрация
6 Авг 2024
Сообщения
55
Реакции[?]
0
Поинты[?]
0
чо это делает ваще
UPD: короч я понял че это оно короче наводится на игрока просто и всё, ну и как обычно дергается
ты не понимаешь там появляется человек яйца
 
Сверху Снизу