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-09-25 01:32:39 +00:00
|
|
|
package baritone.api.pathing.goals;
|
2018-08-02 03:13:48 +00:00
|
|
|
|
2019-09-01 16:47:27 +00:00
|
|
|
import baritone.api.utils.SettingsUtil;
|
2018-09-25 01:32:39 +00:00
|
|
|
import baritone.api.utils.interfaces.IGoalRenderPos;
|
2018-08-02 03:13:48 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A specific BlockPos goal
|
2018-08-04 22:28:36 +00:00
|
|
|
*
|
2018-08-02 03:13:48 +00:00
|
|
|
* @author leijurv
|
|
|
|
*/
|
2018-09-08 01:23:32 +00:00
|
|
|
public class GoalBlock implements Goal, IGoalRenderPos {
|
2018-08-02 03:13:48 +00:00
|
|
|
|
2018-08-08 23:55:20 +00:00
|
|
|
/**
|
|
|
|
* The X block position of this goal
|
|
|
|
*/
|
2019-01-09 22:36:44 +00:00
|
|
|
public final int x;
|
2018-08-08 23:55:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Y block position of this goal
|
|
|
|
*/
|
2019-01-09 22:36:44 +00:00
|
|
|
public final int y;
|
2018-08-08 23:55:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Z block position of this goal
|
|
|
|
*/
|
2019-01-09 22:36:44 +00:00
|
|
|
public final int z;
|
2018-08-02 03:13:48 +00:00
|
|
|
|
|
|
|
public GoalBlock(BlockPos pos) {
|
|
|
|
this(pos.getX(), pos.getY(), pos.getZ());
|
|
|
|
}
|
|
|
|
|
|
|
|
public GoalBlock(int x, int y, int z) {
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-09-23 15:52:03 +00:00
|
|
|
public boolean isInGoal(int x, int y, int z) {
|
|
|
|
return x == this.x && y == this.y && z == this.z;
|
2018-08-02 03:13:48 +00:00
|
|
|
}
|
2018-08-02 03:17:10 +00:00
|
|
|
|
2018-08-02 03:13:48 +00:00
|
|
|
@Override
|
2018-09-23 15:52:03 +00:00
|
|
|
public double heuristic(int x, int y, int z) {
|
|
|
|
int xDiff = x - this.x;
|
|
|
|
int yDiff = y - this.y;
|
|
|
|
int zDiff = z - this.z;
|
2018-08-02 03:13:48 +00:00
|
|
|
return calculate(xDiff, yDiff, zDiff);
|
|
|
|
}
|
2018-08-04 22:28:36 +00:00
|
|
|
|
2018-08-02 04:50:48 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2019-09-01 16:47:27 +00:00
|
|
|
return String.format(
|
2019-09-19 19:53:15 +00:00
|
|
|
"GoalBlock{x=%s,y=%s,z=%s}",
|
|
|
|
SettingsUtil.maybeCensor(x),
|
|
|
|
SettingsUtil.maybeCensor(y),
|
|
|
|
SettingsUtil.maybeCensor(z)
|
2019-09-01 16:47:27 +00:00
|
|
|
);
|
2018-08-02 04:50:48 +00:00
|
|
|
}
|
2018-08-02 03:13:48 +00:00
|
|
|
|
2018-08-08 23:55:20 +00:00
|
|
|
/**
|
|
|
|
* @return The position of this goal as a {@link BlockPos}
|
|
|
|
*/
|
2018-09-17 02:18:39 +00:00
|
|
|
@Override
|
2018-08-08 23:55:20 +00:00
|
|
|
public BlockPos getGoalPos() {
|
|
|
|
return new BlockPos(x, y, z);
|
|
|
|
}
|
|
|
|
|
2018-08-17 20:17:16 +00:00
|
|
|
public static double calculate(double xDiff, int yDiff, double zDiff) {
|
2018-08-02 03:13:48 +00:00
|
|
|
double heuristic = 0;
|
2018-08-19 21:08:16 +00:00
|
|
|
|
2021-08-26 05:20:13 +00:00
|
|
|
// if yDiff is 1 that means that currentY-goalY==1 which means that we're 1 block above where we should be
|
|
|
|
// therefore going from 0,yDiff,0 to a GoalYLevel of 0 is accurate
|
2021-08-22 08:28:42 +00:00
|
|
|
heuristic += GoalYLevel.calculate(0, yDiff);
|
2018-08-19 21:08:16 +00:00
|
|
|
|
2018-08-02 03:17:10 +00:00
|
|
|
//use the pythagorean and manhattan mixture from GoalXZ
|
2018-08-17 20:17:16 +00:00
|
|
|
heuristic += GoalXZ.calculate(xDiff, zDiff);
|
2018-08-02 03:13:48 +00:00
|
|
|
return heuristic;
|
|
|
|
}
|
|
|
|
}
|