Подведи собственные итоги года совместно с YOUGAME и забери ценные призы! Перейти

RotateUtil | Exp 3.1 and more...

  • Автор темы Автор темы CrashMe
  • Дата начала Дата начала
Начинающий
Начинающий
Статус
Оффлайн
Регистрация
6 Окт 2024
Сообщения
18
Реакции
0
Credits: tg: @CacheSystem

Sel$codd:
Expand Collapse Copy
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;
    }
}
 
Последнее редактирование:
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
чо это делает ваще
UPD: короч я понял че это оно короче наводится на игрока просто и всё, ну и как обычно дергается
 
Последнее редактирование:
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Credits: tg: @CacheSystem

Sel$codd:
Expand Collapse Copy
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
 
чо это делает ваще
UPD: короч я понял че это оно короче наводится на игрока просто и всё, ну и как обычно дергается
ты не понимаешь там появляется человек яйца
 
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Назад
Сверху Снизу