diff --git a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java index b5fc3a0b..7678d4d0 100644 --- a/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/bot/behavior/impl/PathingBehavior.java @@ -108,20 +108,13 @@ public class PathingBehavior extends Behavior { return; } if (msg.toLowerCase().startsWith("thisway")) { - goal = fromAngleAndDirection(Double.parseDouble(msg.substring(7).trim())); + goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim())); displayChatMessageRaw("Goal: " + goal); event.cancel(); return; } } - public GoalXZ fromAngleAndDirection(double distance) { - double theta = ((double) player().rotationYaw) * Math.PI / 180D; - double x = player().posX - Math.sin(theta) * distance; - double z = player().posZ + Math.cos(theta) * distance; - return new GoalXZ((int) x, (int) z); - } - /** * In a new thread, pathfind to target blockpos * diff --git a/src/main/java/baritone/bot/pathing/goals/GoalXZ.java b/src/main/java/baritone/bot/pathing/goals/GoalXZ.java index 324b2371..8b3ad4c6 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalXZ.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalXZ.java @@ -17,7 +17,9 @@ package baritone.bot.pathing.goals; +import baritone.bot.utils.Utils; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; /** * Useful for long-range goals that don't have a specific Y level. @@ -54,6 +56,11 @@ public class GoalXZ implements Goal { return calculate(xDiff, zDiff); } + @Override + public String toString() { + return "Goal{x=" + x + ",z=" + z + "}"; + } + public static double calculate(double xDiff, double zDiff) { return calculate(xDiff, zDiff, 0); } @@ -93,8 +100,10 @@ public class GoalXZ implements Goal { return (diagonal + straight) * WALK_ONE_BLOCK_COST; } - @Override - public String toString() { - return "Goal{x=" + x + ",z=" + z + "}"; + public static GoalXZ fromDirection(Vec3d origin, float yaw, double distance) { + double theta = Utils.degToRad(yaw); + double x = origin.x - Math.sin(theta) * distance; + double z = origin.z + Math.cos(theta) * distance; + return new GoalXZ((int) x, (int) z); } } diff --git a/src/main/java/baritone/bot/utils/Helper.java b/src/main/java/baritone/bot/utils/Helper.java index 677528fa..46853203 100755 --- a/src/main/java/baritone/bot/utils/Helper.java +++ b/src/main/java/baritone/bot/utils/Helper.java @@ -50,6 +50,10 @@ public interface Helper { return new BlockPos(player().posX, player().posY, player().posZ); } + default Vec3d playerFeetAsVec() { + return new Vec3d(player().posX, player().posY, player().posZ); + } + default Vec3d playerHead() { return new Vec3d(player().posX, player().posY + player().getEyeHeight(), player().posZ); }