From 46fefa9298910802426d4d936a40f2c15cd3ac6f Mon Sep 17 00:00:00 2001 From: leijurv Date: Tue, 28 Aug 2018 08:55:56 -0700 Subject: [PATCH] simplification support for more goal types --- .../behavior/impl/PathingBehavior.java | 27 +++++++++++++------ .../pathing/goals/GoalGetToBlock.java | 7 +++++ .../java/baritone/pathing/goals/GoalNear.java | 4 +++ .../baritone/pathing/goals/GoalTwoBlocks.java | 4 +++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 37690f21..8b43d2f6 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -26,9 +26,7 @@ import baritone.api.event.events.TickEvent; import baritone.pathing.calc.AStarPathFinder; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.calc.IPathFinder; -import baritone.pathing.goals.Goal; -import baritone.pathing.goals.GoalBlock; -import baritone.pathing.goals.GoalXZ; +import baritone.pathing.goals.*; import baritone.pathing.path.IPath; import baritone.pathing.path.PathExecutor; import baritone.utils.BlockStateInterface; @@ -293,10 +291,23 @@ public class PathingBehavior extends Behavior { displayChatMessageRaw("no goal"); return Optional.empty(); } - if (Baritone.settings().simplifyUnloadedYCoord.get() && goal instanceof GoalBlock) { - BlockPos pos = ((GoalBlock) goal).getGoalPos(); - if (world().getChunk(pos) instanceof EmptyChunk) { - displayChatMessageRaw("Simplifying GoalBlock to GoalXZ due to distance"); + if (Baritone.settings().simplifyUnloadedYCoord.get()) { + BlockPos pos = null; + if (goal instanceof GoalBlock) { + pos = ((GoalBlock) goal).getGoalPos(); + } + if (goal instanceof GoalTwoBlocks) { + pos = ((GoalTwoBlocks) goal).getGoalPos(); + } + if (goal instanceof GoalNear) { + pos = ((GoalNear) goal).getGoalPos(); + } + if (goal instanceof GoalGetToBlock) { + pos = ((GoalGetToBlock) goal).getGoalPos(); + } + // TODO simplify each individual goal in a GoalComposite + if (pos != null && world().getChunk(pos) instanceof EmptyChunk) { + displayChatMessageRaw("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); goal = new GoalXZ(pos.getX(), pos.getZ()); } } @@ -304,7 +315,7 @@ public class PathingBehavior extends Behavior { IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions)); return pf.calculate(); } catch (Exception e) { - displayChatMessageRaw("Exception: " + e); + displayChatMessageRaw("Pathing exception: " + e); e.printStackTrace(); return Optional.empty(); } diff --git a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java index daf7fc9d..9c847918 100644 --- a/src/main/java/baritone/pathing/goals/GoalGetToBlock.java +++ b/src/main/java/baritone/pathing/goals/GoalGetToBlock.java @@ -27,8 +27,11 @@ import net.minecraft.util.math.BlockPos; */ public class GoalGetToBlock extends GoalComposite { + private final BlockPos pos; + public GoalGetToBlock(BlockPos pos) { super(adjacentBlocks(pos)); + this.pos = pos; } private static BlockPos[] adjacentBlocks(BlockPos pos) { @@ -38,4 +41,8 @@ public class GoalGetToBlock extends GoalComposite { } return sides; } + + public BlockPos getGoalPos() { + return pos; + } } diff --git a/src/main/java/baritone/pathing/goals/GoalNear.java b/src/main/java/baritone/pathing/goals/GoalNear.java index e375f17c..d19fadf8 100644 --- a/src/main/java/baritone/pathing/goals/GoalNear.java +++ b/src/main/java/baritone/pathing/goals/GoalNear.java @@ -47,4 +47,8 @@ public class GoalNear implements Goal { int diffZ = z - pos.getZ(); return GoalBlock.calculate(diffX, diffY, diffZ); } + + public BlockPos getGoalPos() { + return new BlockPos(x, y, z); + } } diff --git a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java index 70690fa3..65571a49 100644 --- a/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java +++ b/src/main/java/baritone/pathing/goals/GoalTwoBlocks.java @@ -68,6 +68,10 @@ public class GoalTwoBlocks implements Goal { return GoalBlock.calculate(xDiff, yDiff, zDiff); } + public BlockPos getGoalPos() { + return new BlockPos(x, y, z); + } + @Override public String toString() { return "GoalTwoBlocks{x=" + x + ",y=" + y + ",z=" + z + "}";