diff --git a/src/main/java/baritone/bot/pathing/goals/Goal.java b/src/main/java/baritone/bot/pathing/goals/Goal.java index 76a4fa29..0c7b4be9 100644 --- a/src/main/java/baritone/bot/pathing/goals/Goal.java +++ b/src/main/java/baritone/bot/pathing/goals/Goal.java @@ -12,25 +12,28 @@ import net.minecraft.util.math.BlockPos; * @author leijurv */ public interface Goal { + /** - * Does this position satisfy the goal? + * Returns whether or not the specified position + * meets the requirement for this goal based. * - * @param pos - * @return + * @param pos The position + * @return Whether or not it satisfies this goal */ - public boolean isInGoal(BlockPos pos); + boolean isInGoal(BlockPos pos); + /** * Estimate the number of ticks it will take to get to the goal * - * @param pos - * @return + * @param pos The + * @return The estimate number of ticks to satisfy the goal */ - public double heuristic(BlockPos pos); + double heuristic(BlockPos pos); /** * Summarize the goal * @return */ @Override - public String toString(); + String toString(); } diff --git a/src/main/java/baritone/bot/pathing/goals/GoalBlock.java b/src/main/java/baritone/bot/pathing/goals/GoalBlock.java index c4f6cf59..c314cb4c 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalBlock.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalBlock.java @@ -5,8 +5,7 @@ */ package baritone.bot.pathing.goals; -import baritone.Baritone; -import baritone.pathfinding.actions.Action; +import baritone.bot.pathing.actions.ActionCosts; import net.minecraft.util.math.BlockPos; /** @@ -17,10 +16,6 @@ public class GoalBlock implements Goal { final int x, y, z; - public GoalBlock() { - this(Baritone.playerFeet); - } - public GoalBlock(BlockPos pos) { this(pos.getX(), pos.getY(), pos.getZ()); } @@ -57,14 +52,14 @@ public class GoalBlock implements Goal { public static double calculate(double xDiff, double yDiff, double zDiff) { double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff); double heuristic = 0; - double baseline = (Action.PLACE_ONE_BLOCK_COST + Action.FALL_ONE_BLOCK_COST) * 32; + double baseline = (ActionCosts.PLACE_ONE_BLOCK_COST + ActionCosts.FALL_ONE_BLOCK_COST) * 32; if (pythaDist < MAX) {//if we are more than MAX away, ignore the Y coordinate. It really doesn't matter how far away your Y coordinate is if you X coordinate is 1000 blocks away. //as we get closer, slowly reintroduce the Y coordinate as a heuristic cost double multiplier = pythaDist < MIN ? 1 : 1 - (pythaDist - MIN) / (MAX - MIN); if (yDiff < 0) {//pos.getY()-this.y<0 therefore pos.getY() blocks) { goals = new Goal[blocks.size()]; int i = 0; @@ -34,9 +38,11 @@ public class GoalComposite implements Goal { i++; } } + public Goal[] goals() { return goals; } + @Override public boolean isInGoal(BlockPos pos) { for (Goal g : goals) { @@ -46,6 +52,7 @@ public class GoalComposite implements Goal { } return false; } + @Override public double heuristic(BlockPos pos) { double min = Double.MAX_VALUE; @@ -54,6 +61,7 @@ public class GoalComposite implements Goal { } return min; } + @Override public String toString() { return "GoalComposite" + Arrays.toString(goals); diff --git a/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java index ba17e133..cc3fe7c3 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java @@ -5,7 +5,6 @@ */ package baritone.bot.pathing.goals; -import baritone.Baritone; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -22,10 +21,6 @@ public class GoalGetToBlock extends GoalComposite { super(ajacentBlocks(goalPos = pos)); } - public GoalGetToBlock() { - this(Baritone.playerFeet); - } - public static BlockPos[] ajacentBlocks(BlockPos pos) { BlockPos[] sides = new BlockPos[6]; for (int i = 0; i < 6; i++) { diff --git a/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java b/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java index 801cd04d..4685d1ee 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java @@ -13,8 +13,11 @@ import net.minecraft.util.math.BlockPos; * @author leijurv */ public class GoalRunAway implements Goal { + public final BlockPos[] from; + final double distanceSq; + public GoalRunAway(double distance, BlockPos... from) { if (from.length == 0) { throw new IllegalArgumentException(); @@ -22,6 +25,7 @@ public class GoalRunAway implements Goal { this.from = from; this.distanceSq = distance * distance; } + @Override public boolean isInGoal(BlockPos pos) { for (BlockPos p : from) { @@ -34,6 +38,7 @@ public class GoalRunAway implements Goal { } return true; } + @Override public double heuristic(BlockPos pos) {//mostly copied from GoalBlock double min = Double.MAX_VALUE; @@ -45,6 +50,7 @@ public class GoalRunAway implements Goal { } return -min; } + @Override public String toString() { return "GoalRunAwayFrom[" + Arrays.asList(from) + "]"; diff --git a/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java index e9170ad9..7c7bbcd6 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java @@ -13,19 +13,24 @@ import net.minecraft.util.math.BlockPos; * @author leijurv */ public class GoalTwoBlocks implements Goal { + final int x, y, z; + public GoalTwoBlocks(BlockPos pos) { this(pos.getX(), pos.getY(), pos.getZ()); } + public GoalTwoBlocks(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } + @Override public boolean isInGoal(BlockPos pos) { return pos.getX() == this.x && (pos.getY() == this.y || pos.getY() == this.y - 1) && pos.getZ() == this.z; } + @Override public double heuristic(BlockPos pos) { double xDiff = pos.getX() - this.x; @@ -36,6 +41,7 @@ public class GoalTwoBlocks implements Goal { double zDiff = pos.getZ() - this.z; return GoalBlock.calculate(xDiff, yDiff, zDiff); } + @Override public String toString() { return "GoalTwoBlocks{x=" + x + ",y=" + y + ",z=" + z + "}"; diff --git a/src/main/java/baritone/bot/pathing/goals/GoalXZ.java b/src/main/java/baritone/bot/pathing/goals/GoalXZ.java index a7e6f7a2..30c107ce 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalXZ.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalXZ.java @@ -5,7 +5,7 @@ */ package baritone.bot.pathing.goals; -import baritone.pathfinding.actions.Action; +import baritone.bot.pathing.actions.ActionCosts; import net.minecraft.util.math.BlockPos; /** @@ -13,8 +13,9 @@ import net.minecraft.util.math.BlockPos; * @author leijurv */ public class GoalXZ implements Goal { - final int x; - final int z; + + final int x, z; + public GoalXZ(int x, int z) { this.x = x; this.z = z; @@ -23,15 +24,18 @@ public class GoalXZ implements Goal { public boolean isInGoal(BlockPos pos) { return pos.getX() == x && pos.getZ() == z; } + @Override public double heuristic(BlockPos pos) {//mostly copied from GoalBlock double xDiff = pos.getX() - this.x; double zDiff = pos.getZ() - this.z; return calculate(xDiff, zDiff); } + public static double calculate(double xDiff, double zDiff) { return calculate(xDiff, zDiff, 0); } + /* public static double calculate(double xDiff, double zDiff) { double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff); @@ -45,7 +49,9 @@ public class GoalXZ implements Goal { return heuristic; } */ + static final double sq = Math.sqrt(2); + public static double calculate(double xDiff, double zDiff, double pythaDist) { //This is a combination of pythagorean and manhattan distance //It takes into account the fact that pathing can either walk diagonally or forwards @@ -64,8 +70,9 @@ public class GoalXZ implements Goal { diagonal = z; } diagonal *= sq; - return (diagonal + straight) * Action.WALK_ONE_BLOCK_COST; + return (diagonal + straight) * ActionCosts.WALK_ONE_BLOCK_COST; } + @Override public String toString() { return "Goal{x=" + x + ",z=" + z + "}";