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.BetterBlockPos; 021import baritone.api.utils.SettingsUtil; 022import baritone.api.utils.interfaces.IGoalRenderPos; 023import net.minecraft.core.BlockPos; 024 025/** 026 * Useful if the goal is just to mine a block. This goal will be satisfied if the specified 027 * {@link BlockPos} is at to or above the specified position for this goal. 028 * 029 * @author leijurv 030 */ 031public class GoalTwoBlocks implements Goal, IGoalRenderPos { 032 033 /** 034 * The X block position of this goal 035 */ 036 protected final int x; 037 038 /** 039 * The Y block position of this goal 040 */ 041 protected final int y; 042 043 /** 044 * The Z block position of this goal 045 */ 046 protected final int z; 047 048 public GoalTwoBlocks(BlockPos pos) { 049 this(pos.getX(), pos.getY(), pos.getZ()); 050 } 051 052 public GoalTwoBlocks(int x, int y, int z) { 053 this.x = x; 054 this.y = y; 055 this.z = z; 056 } 057 058 @Override 059 public boolean isInGoal(int x, int y, int z) { 060 return x == this.x && (y == this.y || y == this.y - 1) && z == this.z; 061 } 062 063 @Override 064 public double heuristic(int x, int y, int z) { 065 int xDiff = x - this.x; 066 int yDiff = y - this.y; 067 int zDiff = z - this.z; 068 return GoalBlock.calculate(xDiff, yDiff < 0 ? yDiff + 1 : yDiff, zDiff); 069 } 070 071 @Override 072 public BlockPos getGoalPos() { 073 return new BlockPos(x, y, z); 074 } 075 076 @Override 077 public boolean equals(Object o) { 078 if (this == o) { 079 return true; 080 } 081 if (o == null || getClass() != o.getClass()) { 082 return false; 083 } 084 085 GoalTwoBlocks goal = (GoalTwoBlocks) o; 086 return x == goal.x 087 && y == goal.y 088 && z == goal.z; 089 } 090 091 @Override 092 public int hashCode() { 093 return (int) BetterBlockPos.longHash(x, y, z) * 516508351; 094 } 095 096 @Override 097 public String toString() { 098 return String.format( 099 "GoalTwoBlocks{x=%s,y=%s,z=%s}", 100 SettingsUtil.maybeCensor(x), 101 SettingsUtil.maybeCensor(y), 102 SettingsUtil.maybeCensor(z) 103 ); 104 } 105}