Move fromAngleAndDirection to GoalXZ

This commit is contained in:
Brady 2018-08-09 16:35:42 -05:00
parent 4d32ba131a
commit 2b6d86dcdd
No known key found for this signature in database
GPG Key ID: 73A788379A197567
3 changed files with 17 additions and 11 deletions

View File

@ -108,20 +108,13 @@ public class PathingBehavior extends Behavior {
return; return;
} }
if (msg.toLowerCase().startsWith("thisway")) { 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); displayChatMessageRaw("Goal: " + goal);
event.cancel(); event.cancel();
return; 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 * In a new thread, pathfind to target blockpos
* *

View File

@ -17,7 +17,9 @@
package baritone.bot.pathing.goals; package baritone.bot.pathing.goals;
import baritone.bot.utils.Utils;
import net.minecraft.util.math.BlockPos; 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. * 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); return calculate(xDiff, zDiff);
} }
@Override
public String toString() {
return "Goal{x=" + x + ",z=" + z + "}";
}
public static double calculate(double xDiff, double zDiff) { public static double calculate(double xDiff, double zDiff) {
return calculate(xDiff, zDiff, 0); return calculate(xDiff, zDiff, 0);
} }
@ -93,8 +100,10 @@ public class GoalXZ implements Goal {
return (diagonal + straight) * WALK_ONE_BLOCK_COST; return (diagonal + straight) * WALK_ONE_BLOCK_COST;
} }
@Override public static GoalXZ fromDirection(Vec3d origin, float yaw, double distance) {
public String toString() { double theta = Utils.degToRad(yaw);
return "Goal{x=" + x + ",z=" + z + "}"; double x = origin.x - Math.sin(theta) * distance;
double z = origin.z + Math.cos(theta) * distance;
return new GoalXZ((int) x, (int) z);
} }
} }

View File

@ -50,6 +50,10 @@ public interface Helper {
return new BlockPos(player().posX, player().posY, player().posZ); return new BlockPos(player().posX, player().posY, player().posZ);
} }
default Vec3d playerFeetAsVec() {
return new Vec3d(player().posX, player().posY, player().posZ);
}
default Vec3d playerHead() { default Vec3d playerHead() {
return new Vec3d(player().posX, player().posY + player().getEyeHeight(), player().posZ); return new Vec3d(player().posX, player().posY + player().getEyeHeight(), player().posZ);
} }