From bd1dcff385737e683e932de0294cbbc9a9f0cdeb Mon Sep 17 00:00:00 2001 From: Leijurv Date: Thu, 14 Mar 2019 14:52:51 -0700 Subject: [PATCH] allow ties for closest to explore to --- .../java/baritone/process/ExploreProcess.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/baritone/process/ExploreProcess.java b/src/main/java/baritone/process/ExploreProcess.java index eb98cbde..eff4d2de 100644 --- a/src/main/java/baritone/process/ExploreProcess.java +++ b/src/main/java/baritone/process/ExploreProcess.java @@ -19,6 +19,8 @@ package baritone.process; import baritone.Baritone; import baritone.api.cache.ICachedWorld; +import baritone.api.pathing.goals.Goal; +import baritone.api.pathing.goals.GoalComposite; import baritone.api.pathing.goals.GoalXZ; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; @@ -26,6 +28,9 @@ import baritone.cache.CachedWorld; import baritone.utils.BaritoneProcessHelper; import net.minecraft.util.math.BlockPos; +import java.util.ArrayList; +import java.util.List; + public class ExploreProcess extends BaritoneProcessHelper { private BlockPos explorationOrigin; @@ -50,23 +55,24 @@ public class ExploreProcess extends BaritoneProcessHelper { onLostControl(); return null; } - BlockPos closestUncached = closestUncachedChunk(explorationOrigin); + Goal[] closestUncached = closestUncachedChunks(explorationOrigin); if (closestUncached == null) { logDebug("awaiting region load from disk"); return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); } System.out.println("Closest uncached: " + closestUncached); - return new PathingCommand(new GoalXZ(closestUncached.getX(), closestUncached.getZ()), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH); + return new PathingCommand(new GoalComposite(closestUncached), PathingCommandType.FORCE_REVALIDATE_GOAL_AND_PATH); } - private BlockPos closestUncachedChunk(BlockPos pos) { - int chunkX = pos.getX() >> 4; - int chunkZ = pos.getZ() >> 4; + private Goal[] closestUncachedChunks(BlockPos center) { + int chunkX = center.getX() >> 4; + int chunkZ = center.getZ() >> 4; ICachedWorld cache = baritone.getWorldProvider().getCurrentWorld().getCachedWorld(); for (int dist = 0; ; dist++) { + List centers = new ArrayList<>(); for (int dx = -dist; dx <= dist; dx++) { for (int dz = -dist; dz <= dist; dz++) { - int trueDist = Baritone.settings().exploreUsePythagorean.value ? dx * dx + dz + dz : Math.abs(dx) + Math.abs(dz); + int trueDist = Baritone.settings().exploreUsePythagorean.value ? dx * dx + dz * dz : Math.abs(dx) + Math.abs(dz); if (trueDist != dist) { continue; // not considering this one just yet in our expanding search } @@ -82,9 +88,12 @@ public class ExploreProcess extends BaritoneProcessHelper { }); return null; // we still need to load regions from disk in order to decide properly } - return new BlockPos(centerX, 0, centerZ); + centers.add(new BlockPos(centerX, 0, centerZ)); } } + if (!centers.isEmpty()) { + return centers.stream().map(pos -> new GoalXZ(pos.getX(), pos.getZ())).toArray(Goal[]::new); + } } } @@ -95,6 +104,6 @@ public class ExploreProcess extends BaritoneProcessHelper { @Override public String displayName0() { - return "Exploring around " + explorationOrigin + ", currently going to " + closestUncachedChunk(explorationOrigin); + return "Exploring around " + explorationOrigin + ", currently going to " + new GoalComposite(closestUncachedChunks(explorationOrigin)); } }