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
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* 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
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-08-02 03:30:12 +00:00
|
|
|
package baritone.bot.pathing.goals;
|
2018-08-02 03:13:48 +00:00
|
|
|
|
2018-08-14 00:15:59 +00:00
|
|
|
import baritone.bot.Baritone;
|
2018-08-09 21:35:42 +00:00
|
|
|
import baritone.bot.utils.Utils;
|
2018-08-02 03:13:48 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
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() {
|
|
|
|
return "Goal{x=" + x + ",z=" + z + "}";
|
|
|
|
}
|
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
public static double calculate(double xDiff, double zDiff) {
|
|
|
|
return calculate(xDiff, zDiff, 0);
|
|
|
|
}
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
/*
|
|
|
|
public static double calculate(double xDiff, double zDiff) {
|
|
|
|
double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff);
|
|
|
|
return calculate(xDiff, zDiff, pythaDist);
|
|
|
|
}
|
|
|
|
public static double calculateOld(double xDiff, double zDiff, double pythaDist) {
|
|
|
|
double heuristic = 0;
|
2018-08-02 22:35:36 +00:00
|
|
|
heuristic += Math.abs(xDiff) * Movement.WALK_ONE_BLOCK_COST * 1.1;//overestimate
|
|
|
|
heuristic += Math.abs(zDiff) * Movement.WALK_ONE_BLOCK_COST * 1.1;
|
|
|
|
heuristic += pythaDist / 10 * Movement.WALK_ONE_BLOCK_COST;
|
2018-08-02 03:13:48 +00:00
|
|
|
return heuristic;
|
|
|
|
}
|
|
|
|
*/
|
2018-08-02 04:22:21 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
public static double calculate(double xDiff, double zDiff, double pythaDist) {
|
|
|
|
//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) {
|
|
|
|
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);
|
2018-08-02 03:13:48 +00:00
|
|
|
}
|
|
|
|
}
|