From b67eb4a1272bed2f147a91c390d4e79652dec884 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Mon, 17 Jun 2024 17:31:43 +0200 Subject: [PATCH] reimplement rotationutil --- .../feature/modules/ingame/AutoMount.java | 4 +- .../client/util/interact/BlockUtils.java | 15 +++ .../client/util/interact/RotationUtil.java | 107 ------------------ 3 files changed, 17 insertions(+), 109 deletions(-) delete mode 100644 Client/src/main/java/de/com/baseband/client/util/interact/RotationUtil.java diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/ingame/AutoMount.java b/Client/src/main/java/de/com/baseband/client/feature/modules/ingame/AutoMount.java index 632ad03..12b8f67 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/ingame/AutoMount.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/ingame/AutoMount.java @@ -3,7 +3,7 @@ package de.com.baseband.client.feature.modules.ingame; import de.com.baseband.client.event.events.MotionUpdateEvent; import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.category.Ingame; -import de.com.baseband.client.util.interact.RotationUtil; +import de.com.baseband.client.util.interact.BlockUtils; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityBoat; import net.minecraft.entity.passive.*; @@ -21,7 +21,7 @@ public class AutoMount extends Feature { public void preMotion(MotionUpdateEvent.Pre event) { if(entity != null && mc.player.getRidingEntity() == null) { - Vec2f rot = RotationUtil.getRotationTo(entity.getPositionVector()); + Vec2f rot = BlockUtils.lookTo(mc.player.getPositionEyes(1), entity.getPositionVector()); event.pitch = rot.y; event.yaw = rot.x; } diff --git a/Client/src/main/java/de/com/baseband/client/util/interact/BlockUtils.java b/Client/src/main/java/de/com/baseband/client/util/interact/BlockUtils.java index 7130f9f..484745e 100644 --- a/Client/src/main/java/de/com/baseband/client/util/interact/BlockUtils.java +++ b/Client/src/main/java/de/com/baseband/client/util/interact/BlockUtils.java @@ -2,6 +2,8 @@ package de.com.baseband.client.util.interact; import de.com.baseband.client.util.type.Selection; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec2f; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; public class BlockUtils { @@ -25,4 +27,17 @@ public class BlockUtils { } return selections; } + + public static Vec2f lookTo(Vec3d source, Vec3d destination) { + Vec3d lookVec = source.subtract(destination); + Vec3d lookVecTop = new Vec3d(lookVec.x, 0, lookVec.z).normalize(); + Vec3d lookVecSide = lookVec.normalize(); + + double yaw = Math.acos(lookVecTop.x) - Math.PI / 2; + if(lookVec.z < 0) + yaw = Math.PI - yaw; + double pitch = Math.asin(lookVecSide.y); + + return new Vec2f((float) ((yaw + Math.PI) % (Math.PI * 2) - Math.PI), (float) (pitch)); + } } diff --git a/Client/src/main/java/de/com/baseband/client/util/interact/RotationUtil.java b/Client/src/main/java/de/com/baseband/client/util/interact/RotationUtil.java deleted file mode 100644 index 2b1c43d..0000000 --- a/Client/src/main/java/de/com/baseband/client/util/interact/RotationUtil.java +++ /dev/null @@ -1,107 +0,0 @@ -package de.com.baseband.client.util.interact; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.math.*; - -//TODO: rewrite -// Sponsored by KAMI Blue -// https://github.com/kami-blue/client/blob/master/src/main/kotlin/org/kamiblue/client/util/math/RotationUtils.kt -public class RotationUtil { - - private static final Minecraft mc = Minecraft.getMinecraft(); - - - public static float[] getRotationToPos(BlockPos pos) { - double lengthXZ = Math.hypot(pos.getX(), pos.getZ()); - double yaw = normalizeAngle(Math.toDegrees(Math.atan2(pos.getZ(), pos.getX())) - 90.0); - double pitch = normalizeAngle(Math.toDegrees(-Math.atan2(pos.getY(), lengthXZ))); - return new float[] {(float) yaw, (float) pitch}; - } - - - public static Vec2f getRotationTo(AxisAlignedBB box) { - EntityPlayerSP player = mc.player; - if (player == null) { - return Vec2f.ZERO; - } - - Vec3d eyePos = player.getPositionEyes(1.0f); - - if (player.getEntityBoundingBox().intersects(box)) { - return getRotationTo(eyePos, box.getCenter()); - } - - double x = MathHelper.clamp(eyePos.x, box.minX, box.maxX); - double y = MathHelper.clamp(eyePos.y, box.minY, box.maxY); - double z = MathHelper.clamp(eyePos.z, box.minZ, box.maxZ); - - return getRotationTo(eyePos, new Vec3d(x, y, z)); - } - - /** - * Get rotation from player position to another position vector - * - * @param posTo Calculate rotation to this position vector - */ - public static Vec2f getRotationTo(Vec3d posTo) { - EntityPlayerSP player = mc.player; - return player != null ? getRotationTo(player.getPositionEyes(1.0f), posTo) : Vec2f.ZERO; - } - - public static Vec2f getRotationTo(Vec3d posTo, EntityPlayer player) { - return player != null ? getRotationTo(player.getPositionEyes(1.0f), posTo) : Vec2f.ZERO; - } - - /** - * Get rotation from a position vector to another position vector - * - * @param posFrom Calculate rotation from this position vector - * @param posTo Calculate rotation to this position vector - */ - public static Vec2f getRotationTo(Vec3d posFrom, Vec3d posTo) { - return getRotationFromVec(posTo.subtract(posFrom)); - } - - /** - * Get rotation from a vector - * - * @param vec Calculate rotation from this vector - */ - public static Vec2f getRotationFromVec(Vec3d vec) { - double lengthXZ = Math.hypot(vec.x, vec.z); - double yaw = normalizeAngle(Math.toDegrees(Math.atan2(vec.z, vec.x)) - 90.0); - double pitch = normalizeAngle(Math.toDegrees(- Math.atan2(vec.y, lengthXZ))); - - return new Vec2f((float) yaw, (float) pitch); - } - - public static double normalizeAngle(double angle) { - angle %= 360.0; - - if (angle >= 180.0) { - angle -= 360.0; - } - - if (angle < - 180.0) { - angle += 360.0; - } - - return angle; - } - - public static float normalizeAngle(float angle) { - angle %= 360.0f; - - if (angle >= 180.0f) { - angle -= 360.0f; - } - - if (angle < - 180.0f) { - angle += 360.0f; - } - - return angle; - } -} \ No newline at end of file