From 1680eeb80da785338a2d27e4c432610be5e102f2 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 10 Jan 2023 17:25:32 +0100 Subject: [PATCH 1/4] Handle mods breaking our world loading hook --- .../java/baritone/cache/WorldProvider.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index a7756137c..03ada444f 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -24,6 +24,7 @@ import baritone.utils.accessor.IAnvilChunkLoader; import baritone.utils.accessor.IChunkProviderServer; import net.minecraft.server.integrated.IntegratedServer; import net.minecraft.world.WorldServer; +import net.minecraft.world.World; import org.apache.commons.lang3.SystemUtils; import java.io.File; @@ -44,9 +45,11 @@ public class WorldProvider implements IWorldProvider, Helper { private static final Map worldCache = new HashMap<>(); // this is how the bots have the same cached world private WorldData currentWorld; + private World mcWorld; // this let's us detect a broken load/unload hook @Override public final WorldData getCurrentWorld() { + detectAndHandleBrokenLoading(); return this.currentWorld; } @@ -83,6 +86,7 @@ public class WorldProvider implements IWorldProvider, Helper { } else { //replaymod causes null currentServerData and false singleplayer. currentWorld = null; + mcWorld = mc.world; return; } if (SystemUtils.IS_OS_WINDOWS) { @@ -110,11 +114,13 @@ public class WorldProvider implements IWorldProvider, Helper { synchronized (worldCache) { this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimension)); } + this.mcWorld = mc.world; } public final void closeWorld() { WorldData world = this.currentWorld; this.currentWorld = null; + this.mcWorld = null; if (world == null) { return; } @@ -122,8 +128,20 @@ public class WorldProvider implements IWorldProvider, Helper { } public final void ifWorldLoaded(Consumer currentWorldConsumer) { + detectAndHandleBrokenLoading(); if (this.currentWorld != null) { currentWorldConsumer.accept(this.currentWorld); } } + + private final void detectAndHandleBrokenLoading() { + if (this.mcWorld != mc.world) { + if (this.currentWorld != null) { + closeWorld(); + } + if (mc.world != null) { + initWorld(mc.world.provider.getDimensionType().getId()); + } + } + } } From 77b2b26a7a86bfd7a3a3d05fd7055f81349f2a05 Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 10 Jan 2023 18:52:18 +0100 Subject: [PATCH 2/4] Add fix for 1.19.3 here already --- src/main/java/baritone/cache/WorldProvider.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index 03ada444f..c335b364b 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -142,6 +142,8 @@ public class WorldProvider implements IWorldProvider, Helper { if (mc.world != null) { initWorld(mc.world.provider.getDimensionType().getId()); } + } else if (currentWorld == null && mc.world != null) { + initWorld(mc.world.provider.getDimensionType().getId()); } } } From 75e39e7ef553a07cfe0e2f577e8bd1802dc8e1fb Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 10 Jan 2023 17:30:33 +0100 Subject: [PATCH 3/4] Log when doing things out of the ordinary --- src/main/java/baritone/cache/WorldProvider.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index c335b364b..3addb1762 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -85,6 +85,7 @@ public class WorldProvider implements IWorldProvider, Helper { folderName = mc.getCurrentServerData().serverIP; } else { //replaymod causes null currentServerData and false singleplayer. + System.out.println("World seems to be a replay. Not loading Baritone cache."); currentWorld = null; mcWorld = mc.world; return; @@ -137,12 +138,15 @@ public class WorldProvider implements IWorldProvider, Helper { private final void detectAndHandleBrokenLoading() { if (this.mcWorld != mc.world) { if (this.currentWorld != null) { + System.out.println("mc.world unloaded unnoticed! Unloading Baritone cache now."); closeWorld(); } if (mc.world != null) { + System.out.println("mc.world loaded unnoticed! Loading Baritone cache now."); initWorld(mc.world.provider.getDimensionType().getId()); } } else if (currentWorld == null && mc.world != null) { + System.out.println("Retrying to load Baritone cache"); initWorld(mc.world.provider.getDimensionType().getId()); } } From a6f3c956846a357fbf3cafd1e6f5bf44bc158e2c Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Tue, 10 Jan 2023 18:53:43 +0100 Subject: [PATCH 4/4] Don't spam the log when in a replay --- src/main/java/baritone/cache/WorldProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index 3addb1762..98ec1bbb2 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -145,7 +145,7 @@ public class WorldProvider implements IWorldProvider, Helper { System.out.println("mc.world loaded unnoticed! Loading Baritone cache now."); initWorld(mc.world.provider.getDimensionType().getId()); } - } else if (currentWorld == null && mc.world != null) { + } else if (currentWorld == null && mc.world != null && (mc.isSingleplayer() || mc.getCurrentServerData() != null)) { System.out.println("Retrying to load Baritone cache"); initWorld(mc.world.provider.getDimensionType().getId()); }