fix goal get to block

This commit is contained in:
Leijurv
2018-09-03 20:42:28 -07:00
parent bfafca541f
commit a2f0a1839a
2 changed files with 78 additions and 14 deletions

View File

@@ -17,32 +17,47 @@
package baritone.pathing.goals;
import net.minecraft.util.EnumFacing;
import baritone.utils.pathing.BetterBlockPos;
import net.minecraft.util.math.BlockPos;
/**
* Don't get into the block, but get directly adjacent to it. Useful for chests.
*
* @author avecowa
*/
public class GoalGetToBlock extends GoalComposite {
public class GoalGetToBlock implements Goal {
private final BlockPos pos;
private final int x;
private final int y;
private final int z;
public GoalGetToBlock(BlockPos pos) {
super(adjacentBlocks(pos));
this.pos = pos;
}
private static BlockPos[] adjacentBlocks(BlockPos pos) {
BlockPos[] sides = new BlockPos[6];
for (int i = 0; i < 6; i++) {
sides[i] = pos.offset(EnumFacing.values()[i]);
}
return sides;
this.x = pos.getX();
this.y = pos.getY();
this.z = pos.getZ();
}
public BlockPos getGoalPos() {
return pos;
return new BetterBlockPos(x, y, z);
}
@Override
public boolean isInGoal(BlockPos pos) {
int xDiff = pos.getX() - this.x;
int yDiff = pos.getY() - this.y;
int zDiff = pos.getZ() - this.z;
if (yDiff == -2 && xDiff == 0 && zDiff == 0) {
return true;
}
return Math.abs(xDiff) + Math.abs(yDiff) + Math.abs(zDiff) <= 1;
}
@Override
public double heuristic(BlockPos pos) {
int xDiff = pos.getX() - this.x;
int yDiff = pos.getY() - this.y;
int zDiff = pos.getZ() - this.z;
return GoalBlock.calculate(xDiff, yDiff, zDiff);
}
}