001/*
002 * This file is part of Baritone.
003 *
004 * Baritone is free software: you can redistribute it and/or modify
005 * it under the terms of the GNU Lesser General Public License as published by
006 * the Free Software Foundation, either version 3 of the License, or
007 * (at your option) any later version.
008 *
009 * Baritone is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU Lesser General Public License for more details.
013 *
014 * You should have received a copy of the GNU Lesser General Public License
015 * along with Baritone.  If not, see <https://www.gnu.org/licenses/>.
016 */
017
018package baritone.api.pathing.goals;
019
020import baritone.api.utils.SettingsUtil;
021import baritone.api.utils.interfaces.IGoalRenderPos;
022import net.minecraft.util.math.BlockPos;
023
024/**
025 * Useful if the goal is just to mine a block. This goal will be satisfied if the specified
026 * {@link BlockPos} is at to or above the specified position for this goal.
027 *
028 * @author leijurv
029 */
030public class GoalTwoBlocks implements Goal, IGoalRenderPos {
031
032    /**
033     * The X block position of this goal
034     */
035    protected final int x;
036
037    /**
038     * The Y block position of this goal
039     */
040    protected final int y;
041
042    /**
043     * The Z block position of this goal
044     */
045    protected final int z;
046
047    public GoalTwoBlocks(BlockPos pos) {
048        this(pos.getX(), pos.getY(), pos.getZ());
049    }
050
051    public GoalTwoBlocks(int x, int y, int z) {
052        this.x = x;
053        this.y = y;
054        this.z = z;
055    }
056
057    @Override
058    public boolean isInGoal(int x, int y, int z) {
059        return x == this.x && (y == this.y || y == this.y - 1) && z == this.z;
060    }
061
062    @Override
063    public double heuristic(int x, int y, int z) {
064        int xDiff = x - this.x;
065        int yDiff = y - this.y;
066        int zDiff = z - this.z;
067        return GoalBlock.calculate(xDiff, yDiff < 0 ? yDiff + 1 : yDiff, zDiff);
068    }
069
070    @Override
071    public BlockPos getGoalPos() {
072        return new BlockPos(x, y, z);
073    }
074
075    @Override
076    public String toString() {
077        return String.format(
078                "GoalTwoBlocks{x=%s,y=%s,z=%s}",
079                SettingsUtil.maybeCensor(x),
080                SettingsUtil.maybeCensor(y),
081                SettingsUtil.maybeCensor(z)
082        );
083    }
084}