From 38afa1b63c07d01eb0e7129e54495af26a007cc0 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 8 Aug 2018 15:31:41 -0700 Subject: [PATCH] helper for 0.5 center --- .../java/baritone/bot/pathing/movement/MovementHelper.java | 3 +-- .../bot/pathing/movement/movements/MovementFall.java | 2 +- src/main/java/baritone/bot/utils/Utils.java | 6 +++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java index 29a42efb..87db426c 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementHelper.java @@ -35,7 +35,6 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.RayTraceResult; -import net.minecraft.util.math.Vec3d; import java.util.Arrays; import java.util.List; @@ -204,7 +203,7 @@ public interface MovementHelper extends ActionCosts, Helper { static MovementState moveTowards(MovementState state, BlockPos pos) { return state.setTarget(new MovementTarget(new Rotation(Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), - new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), + Utils.getBlockPosCenter(pos), new Rotation(mc.player.rotationYaw, mc.player.rotationPitch)).getFirst(), mc.player.rotationPitch)) ).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); } diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java index 3aa1a33f..aedab851 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementFall.java @@ -89,7 +89,7 @@ public class MovementFall extends Movement { } return state.setStatus(MovementStatus.SUCCESS); } - Vec3d destCenter = Utils.calcCenterFromCoords(dest, world()); + Vec3d destCenter = Utils.getBlockPosCenter(dest); // we are moving to the 0.5 center not the edge (like if we were falling on a ladder) if (Math.abs(player().posX - destCenter.x) > 0.2 || Math.abs(player().posZ - destCenter.z) > 0.2) { state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); } diff --git a/src/main/java/baritone/bot/utils/Utils.java b/src/main/java/baritone/bot/utils/Utils.java index 2dafcdf2..151f3ddb 100755 --- a/src/main/java/baritone/bot/utils/Utils.java +++ b/src/main/java/baritone/bot/utils/Utils.java @@ -42,7 +42,7 @@ public final class Utils { * @return Rotation {@link Rotation} */ public static Rotation calcRotationFromVec3d(Vec3d orig, Vec3d dest) { - double[] delta = { orig.x - dest.x, orig.y - dest.y, orig.z - dest.z }; + double[] delta = {orig.x - dest.x, orig.y - dest.y, orig.z - dest.z}; double yaw = Math.atan2(delta[0], -delta[2]); double dist = Math.sqrt(delta[0] * delta[0] + delta[2] * delta[2]); double pitch = Math.atan2(delta[1], dist); @@ -74,6 +74,10 @@ public final class Utils { orig.getZ() + zDiff); } + public static Vec3d getBlockPosCenter(BlockPos pos) { + return new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); + } + public static Rotation wrapAnglesToRelative(Rotation current, Rotation target) { return new Rotation( MathHelper.wrapDegrees(target.getFirst() - current.getFirst()) + current.getFirst(),