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 net.minecraft.util.math.BlockPos;
021
022/**
023 * An abstract Goal for pathing, can be anything from a specific block to just a Y coordinate.
024 *
025 * @author leijurv
026 */
027public interface Goal {
028
029    /**
030     * Returns whether or not the specified position
031     * meets the requirement for this goal based.
032     *
033     * @param x The goal X position
034     * @param y The goal Y position
035     * @param z The goal Z position
036     * @return Whether or not it satisfies this goal
037     */
038    boolean isInGoal(int x, int y, int z);
039
040    /**
041     * Estimate the number of ticks it will take to get to the goal
042     *
043     * @param x The goal X position
044     * @param y The goal Y position
045     * @param z The goal Z position
046     * @return The estimate number of ticks to satisfy the goal
047     */
048    double heuristic(int x, int y, int z);
049
050    default boolean isInGoal(BlockPos pos) {
051        return isInGoal(pos.getX(), pos.getY(), pos.getZ());
052    }
053
054    default double heuristic(BlockPos pos) {
055        return heuristic(pos.getX(), pos.getY(), pos.getZ());
056    }
057
058    /**
059     * Returns the heuristic at the goal.
060     * i.e. {@code heuristic() == heuristic(x,y,z)}
061     * when {@code isInGoal(x,y,z) == true}
062     * This is needed by {@code PathingBehavior#estimatedTicksToGoal} because
063     * some Goals actually do not have a heuristic of 0 when that condition is met
064     *
065     * @return The estimate number of ticks to satisfy the goal when the goal
066     * is already satisfied
067     */
068    default double heuristic() {
069        return 0;
070    }
071}