reimplement rotationutil
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m26s
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m26s
This commit is contained in:
parent
3b6ce0db8a
commit
b67eb4a127
3 changed files with 17 additions and 109 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue