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/** 027 * Don't get into the block, but get directly adjacent to it. Useful for chests. 028 * 029 * @author avecowa 030 */ 031public class GoalGetToBlock implements Goal, IGoalRenderPos { 032 033 public final int x; 034 public final int y; 035 public final int z; 036 037 public GoalGetToBlock(BlockPos pos) { 038 this.x = pos.getX(); 039 this.y = pos.getY(); 040 this.z = pos.getZ(); 041 } 042 043 @Override 044 public BlockPos getGoalPos() { 045 return new BlockPos(x, y, z); 046 } 047 048 @Override 049 public boolean isInGoal(int x, int y, int z) { 050 int xDiff = x - this.x; 051 int yDiff = y - this.y; 052 int zDiff = z - this.z; 053 return Math.abs(xDiff) + Math.abs(yDiff < 0 ? yDiff + 1 : yDiff) + Math.abs(zDiff) <= 1; 054 } 055 056 @Override 057 public double heuristic(int x, int y, int z) { 058 int xDiff = x - this.x; 059 int yDiff = y - this.y; 060 int zDiff = z - this.z; 061 return GoalBlock.calculate(xDiff, yDiff < 0 ? yDiff + 1 : yDiff, zDiff); 062 } 063 064 @Override 065 public boolean equals(Object o) { 066 if (this == o) { 067 return true; 068 } 069 if (o == null || getClass() != o.getClass()) { 070 return false; 071 } 072 073 GoalGetToBlock goal = (GoalGetToBlock) o; 074 return x == goal.x 075 && y == goal.y 076 && z == goal.z; 077 } 078 079 @Override 080 public int hashCode() { 081 return (int) BetterBlockPos.longHash(x, y, z) * -49639096; 082 } 083 084 @Override 085 public String toString() { 086 return String.format( 087 "GoalGetToBlock{x=%s,y=%s,z=%s}", 088 SettingsUtil.maybeCensor(x), 089 SettingsUtil.maybeCensor(y), 090 SettingsUtil.maybeCensor(z) 091 ); 092 } 093}