baritone/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java

82 lines
2.2 KiB
Java
Raw Normal View History

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 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.
*
* 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 Lesser General Public License for more details.
2018-08-08 03:16:53 +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-09-08 01:23:32 +00:00
import baritone.utils.interfaces.IGoalRenderPos;
2018-08-02 03:13:48 +00:00
import net.minecraft.util.math.BlockPos;
/**
* Useful if the goal is just to mine a block. This goal will be satisfied if the specified
* {@link BlockPos} is at to or above the specified position for this goal.
*
2018-08-02 03:13:48 +00:00
* @author leijurv
*/
2018-09-08 01:23:32 +00:00
public class GoalTwoBlocks implements Goal, IGoalRenderPos {
2018-08-02 04:22:21 +00:00
/**
* The X block position of this goal
*/
private final int x;
/**
* The Y block position of this goal
*/
private final int y;
/**
* 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 GoalTwoBlocks(BlockPos pos) {
this(pos.getX(), pos.getY(), pos.getZ());
}
2018-08-02 04:22:21 +00:00
2018-08-02 03:13:48 +00:00
public GoalTwoBlocks(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
2018-08-02 04:22:21 +00:00
2018-08-02 03:13:48 +00:00
@Override
public boolean isInGoal(BlockPos pos) {
return pos.getX() == this.x && (pos.getY() == this.y || pos.getY() == this.y - 1) && pos.getZ() == this.z;
}
2018-08-02 04:22:21 +00:00
2018-08-02 03:13:48 +00:00
@Override
public double heuristic(BlockPos pos) {
double xDiff = pos.getX() - this.x;
int yDiff = pos.getY() - this.y;
2018-08-02 03:13:48 +00:00
if (yDiff < 0) {
yDiff++;
}
double zDiff = pos.getZ() - this.z;
return GoalBlock.calculate(xDiff, yDiff, zDiff);
}
2018-08-02 04:22:21 +00:00
2018-09-17 02:18:39 +00:00
@Override
public BlockPos getGoalPos() {
2018-09-08 03:43:12 +00:00
return new BlockPos(x, y, z);
}
2018-08-02 03:13:48 +00:00
@Override
public String toString() {
return "GoalTwoBlocks{x=" + x + ",y=" + y + ",z=" + z + "}";
}
}