From f7037bf775165e42bf7cc5e11b903030ae954f8e Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 8 Aug 2018 18:55:20 -0500 Subject: [PATCH] Some general cleanups to goal implementations --- .../baritone/bot/pathing/goals/GoalBlock.java | 36 ++++++++++++++----- .../bot/pathing/goals/GoalComposite.java | 4 +++ .../bot/pathing/goals/GoalGetToBlock.java | 4 +-- .../bot/pathing/goals/GoalRunAway.java | 2 +- .../bot/pathing/goals/GoalTwoBlocks.java | 20 +++++++++-- .../baritone/bot/pathing/goals/GoalXZ.java | 17 ++++++--- .../bot/pathing/goals/GoalYLevel.java | 11 ++++-- 7 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/main/java/baritone/bot/pathing/goals/GoalBlock.java b/src/main/java/baritone/bot/pathing/goals/GoalBlock.java index 6d2b9066..2f141444 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalBlock.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalBlock.java @@ -26,7 +26,20 @@ import net.minecraft.util.math.BlockPos; */ public class GoalBlock implements Goal { - private final int x, y, z; + /** + * The X block position of this goal + */ + private final int x; + + /** + * The Y block position of this goal + */ + private final int y; + + /** + * The Z block position of this goal + */ + private final int z; public GoalBlock(BlockPos pos) { this(pos.getX(), pos.getY(), pos.getZ()); @@ -44,10 +57,14 @@ public class GoalBlock implements Goal { } /** - * The range over which to begin considering Y coordinate in the heuristic + * The min range value over which to begin considering Y coordinate in the heuristic */ - static final double MIN = 20; - static final double MAX = 150; + private static final double MIN = 20; + + /** + * The max range value over which to begin considering Y coordinate in the heuristic + */ + private static final double MAX = 150; @Override public double heuristic(BlockPos pos) { @@ -62,6 +79,13 @@ public class GoalBlock implements Goal { return "Goal{x=" + x + ",y=" + y + ",z=" + z + "}"; } + /** + * @return The position of this goal as a {@link BlockPos} + */ + public BlockPos getGoalPos() { + return new BlockPos(x, y, z); + } + public static double calculate(double xDiff, double yDiff, double zDiff) { double pythaDist = Math.sqrt(xDiff * xDiff + zDiff * zDiff); double heuristic = 0; @@ -83,8 +107,4 @@ public class GoalBlock implements Goal { heuristic += GoalXZ.calculate(xDiff, zDiff, pythaDist); return heuristic; } - - public BlockPos getGoalPos() { - return new BlockPos(x, y, z); - } } diff --git a/src/main/java/baritone/bot/pathing/goals/GoalComposite.java b/src/main/java/baritone/bot/pathing/goals/GoalComposite.java index 6adc1fcc..ad0036ce 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalComposite.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalComposite.java @@ -25,10 +25,14 @@ import net.minecraft.util.math.BlockPos; * A composite of many goals, any one of which satisfies the composite. * For example, a GoalComposite of block goals for every oak log in loaded chunks * would result in it pathing to the easiest oak log to get to + * * @author avecowa */ public class GoalComposite implements Goal { + /** + * An array of goals that any one of must be satisfied + */ public final Goal[] goals; public GoalComposite(Goal... goals) { diff --git a/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java index 116ee53d..e06e2674 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalGetToBlock.java @@ -21,8 +21,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; /** - * Don't get into the block, but get directly adjacent to it. - * Useful for chests. + * Don't get into the block, but get directly adjacent to it. Useful for chests. + * * @author avecowa */ public class GoalGetToBlock extends GoalComposite { diff --git a/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java b/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java index 5573a369..7580925c 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalRunAway.java @@ -21,7 +21,7 @@ import java.util.Arrays; import net.minecraft.util.math.BlockPos; /** - * Useful for automated combat (etreating specifically) + * Useful for automated combat (retreating specifically) * @author leijurv */ public class GoalRunAway implements Goal { diff --git a/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java index a7c289e7..724c0ff8 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalTwoBlocks.java @@ -20,13 +20,27 @@ package baritone.bot.pathing.goals; import net.minecraft.util.math.BlockPos; /** - * Useful if the goal is just to mine a block. - * This goal gets either the player's feet or head into the desired block. + * Useful if the goal is just to mine a block. This goal will be satisfied if the specified + * {@link BlockPos} is at to or above the specified position for this goal. + * * @author leijurv */ public class GoalTwoBlocks implements Goal { - final int x, y, z; + /** + * The X block position of this goal + */ + private final int x; + + /** + * The Y block position of this goal + */ + private final int y; + + /** + * The Z block position of this goal + */ + private final int z; public GoalTwoBlocks(BlockPos pos) { this(pos.getX(), pos.getY(), pos.getZ()); diff --git a/src/main/java/baritone/bot/pathing/goals/GoalXZ.java b/src/main/java/baritone/bot/pathing/goals/GoalXZ.java index 2dadfa03..324b2371 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalXZ.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalXZ.java @@ -25,12 +25,23 @@ import net.minecraft.util.math.BlockPos; */ public class GoalXZ implements Goal { - final int x, z; + private static final double SQRT_2 = Math.sqrt(2); + + /** + * The X block position of this goal + */ + private final int x; + + /** + * The Z block position of this goal + */ + private final int z; public GoalXZ(int x, int z) { this.x = x; this.z = z; } + @Override public boolean isInGoal(BlockPos pos) { return pos.getX() == x && pos.getZ() == z; @@ -61,8 +72,6 @@ public class GoalXZ implements Goal { } */ - 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 @@ -80,7 +89,7 @@ public class GoalXZ implements Goal { straight = x - z; diagonal = z; } - diagonal *= sq; + diagonal *= SQRT_2; return (diagonal + straight) * WALK_ONE_BLOCK_COST; } diff --git a/src/main/java/baritone/bot/pathing/goals/GoalYLevel.java b/src/main/java/baritone/bot/pathing/goals/GoalYLevel.java index 862838ca..abd5973d 100644 --- a/src/main/java/baritone/bot/pathing/goals/GoalYLevel.java +++ b/src/main/java/baritone/bot/pathing/goals/GoalYLevel.java @@ -21,11 +21,15 @@ import net.minecraft.util.math.BlockPos; /** * Useful for mining (getting to diamond / iron level) + * * @author leijurv */ public class GoalYLevel implements Goal { - final int level; + /** + * The target Y level + */ + private final int level; public GoalYLevel(int level) { this.level = level; @@ -38,8 +42,9 @@ public class GoalYLevel implements Goal { @Override public double heuristic(BlockPos pos) { - return 20 * Math.abs(pos.getY() - level);//the number 20 was chosen somewhat randomly. - //TODO fix that + // The number 20 was chosen somewhat randomly. + // TODO fix that ^ + return 20 * Math.abs(pos.getY() - level); } @Override