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

65 lines
1.7 KiB
Java

/*
* 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
* 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,
* 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.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.pathing.goals;
import net.minecraft.util.math.BlockPos;
/**
* Useful for mining (getting to diamond / iron level)
*
* @author leijurv
*/
public class GoalYLevel implements Goal {
/**
* The target Y level
*/
private final int level;
public GoalYLevel(int level) {
this.level = level;
}
@Override
public boolean isInGoal(BlockPos pos) {
return pos.getY() == level;
}
@Override
public double heuristic(BlockPos pos) {
return calculate(level, pos.getY());
}
public static double calculate(int goalY, int currentY) {
if (currentY > goalY) {
// need to descend
return FALL_N_BLOCKS_COST[2] / 2 * (currentY - goalY);
}
if (currentY < goalY) {
// need to ascend
return (goalY - currentY) * JUMP_ONE_BLOCK_COST;
}
return 0;
}
@Override
public String toString() {
return "GoalYLevel{y=" + level + "}";
}
}