2018-08-08 03:16:53 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Baritone.
|
|
|
|
*
|
|
|
|
* Baritone is free software: you can redistribute it and/or modify
|
2018-09-17 22:11:40 +00:00
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
2018-08-08 03:16:53 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2018-08-08 04:15:22 +00:00
|
|
|
* Baritone is distributed in the hope that it will be useful,
|
2018-08-08 03:16:53 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-09-17 22:11:40 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2018-08-08 03:16:53 +00:00
|
|
|
*
|
2018-09-17 22:11:40 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2018-08-08 03:16:53 +00:00
|
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-08-22 20:15:56 +00:00
|
|
|
package baritone.pathing.goals;
|
2018-08-02 03:13:48 +00:00
|
|
|
|
2018-08-22 20:15:56 +00:00
|
|
|
import baritone.Baritone;
|
|
|
|
import baritone.utils.Utils;
|
2018-08-02 03:13:48 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2018-08-29 23:45:16 +00:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2018-08-09 21:35:42 +00:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2018-08-02 03:13:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Useful for long-range goals that don't have a specific Y level.
|
2018-08-13 23:41:08 +00:00
|
|
|
*
|
2018-08-02 03:13:48 +00:00
|
|
|
* @author leijurv
|
|
|
|
*/
|
|
|
|
public class GoalXZ implements Goal {
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-08 23:55:20 +00:00
|
|
|
private static final double SQRT_2 = Math.sqrt(2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The X block position of this goal
|
|
|
|
*/
|
|
|
|
private final int x;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Z block position of this goal
|
|
|
|
*/
|
|
|
|
private final int z;
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
public GoalXZ(int x, int z) {
|
|
|
|
this.x = x;
|
|
|
|
this.z = z;
|
|
|
|
}
|
2018-08-08 23:55:20 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
@Override
|
|
|
|
public boolean isInGoal(BlockPos pos) {
|
|
|
|
return pos.getX() == x && pos.getZ() == z;
|
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
@Override
|
|
|
|
public double heuristic(BlockPos pos) {//mostly copied from GoalBlock
|
|
|
|
double xDiff = pos.getX() - this.x;
|
|
|
|
double zDiff = pos.getZ() - this.z;
|
|
|
|
return calculate(xDiff, zDiff);
|
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-09 21:35:42 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2018-09-15 19:51:37 +00:00
|
|
|
return "GoalXZ{x=" + x + ",z=" + z + "}";
|
2018-08-09 21:35:42 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
public static double calculate(double xDiff, double zDiff) {
|
|
|
|
//This is a combination of pythagorean and manhattan distance
|
|
|
|
//It takes into account the fact that pathing can either walk diagonally or forwards
|
|
|
|
|
|
|
|
//It's not possible to walk forward 1 and right 2 in sqrt(5) time
|
|
|
|
//It's really 1+sqrt(2) because it'll walk forward 1 then diagonally 1
|
|
|
|
double x = Math.abs(xDiff);
|
|
|
|
double z = Math.abs(zDiff);
|
|
|
|
double straight;
|
|
|
|
double diagonal;
|
|
|
|
if (x < z) {
|
|
|
|
straight = z - x;
|
|
|
|
diagonal = x;
|
|
|
|
} else {
|
|
|
|
straight = x - z;
|
|
|
|
diagonal = z;
|
|
|
|
}
|
2018-08-08 23:55:20 +00:00
|
|
|
diagonal *= SQRT_2;
|
2018-08-14 22:04:41 +00:00
|
|
|
return (diagonal + straight) * Baritone.settings().costHeuristic.get(); // big TODO tune
|
2018-08-02 03:13:48 +00:00
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-09 21:35:42 +00:00
|
|
|
public static GoalXZ fromDirection(Vec3d origin, float yaw, double distance) {
|
2018-08-29 23:45:16 +00:00
|
|
|
float theta = (float) Utils.degToRad(yaw);
|
|
|
|
double x = origin.x - MathHelper.sin(theta) * distance;
|
|
|
|
double z = origin.z + MathHelper.cos(theta) * distance;
|
2018-08-09 21:35:42 +00:00
|
|
|
return new GoalXZ((int) x, (int) z);
|
2018-08-02 03:13:48 +00:00
|
|
|
}
|
2018-08-16 22:34:23 +00:00
|
|
|
|
|
|
|
public int getX() {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getZ() {
|
|
|
|
return z;
|
|
|
|
}
|
2018-08-02 03:13:48 +00:00
|
|
|
}
|