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 java.util.Objects;
021
022/**
023 * Invert any goal.
024 * <p>
025 * In the old chat control system, #invert just tried to pick a {@link GoalRunAway} that <i>effectively</i> inverted the
026 * current goal. This goal just reverses the heuristic to act as a TRUE invert. Inverting a Y level? Baritone tries to
027 * get away from that Y level. Inverting a GoalBlock? Baritone will try to make distance whether it's in the X, Y or Z
028 * directions. And of course, you can always invert a GoalXZ.
029 *
030 * @author LoganDark
031 */
032public class GoalInverted implements Goal {
033
034    public final Goal origin;
035
036    public GoalInverted(Goal origin) {
037        this.origin = origin;
038    }
039
040    @Override
041    public boolean isInGoal(int x, int y, int z) {
042        return false;
043    }
044
045    @Override
046    public double heuristic(int x, int y, int z) {
047        return -origin.heuristic(x, y, z);
048    }
049
050    @Override
051    public double heuristic() {
052        return Double.NEGATIVE_INFINITY;
053    }
054
055    @Override
056    public boolean equals(Object o) {
057        if (this == o) {
058            return true;
059        }
060        if (o == null || getClass() != o.getClass()) {
061            return false;
062        }
063
064        GoalInverted goal = (GoalInverted) o;
065        return Objects.equals(origin, goal.origin);
066    }
067
068    @Override
069    public int hashCode() {
070        return origin.hashCode() * 495796690;
071    }
072
073    @Override
074    public String toString() {
075        return String.format("GoalInverted{%s}", origin.toString());
076    }
077}