From 51243f09818bd9f5937cd5f0cec0fe85e968017f Mon Sep 17 00:00:00 2001 From: Brady Date: Sun, 11 Nov 2018 16:22:00 -0600 Subject: [PATCH] Some comments --- .../java/baritone/cache/WorldProvider.java | 30 +++++++++++-------- .../java/baritone/event/GameEventHandler.java | 2 +- .../utils/accessor/IAnvilChunkLoader.java | 4 +++ .../utils/accessor/IChunkProviderServer.java | 3 ++ .../utils/pathing/BetterWorldBorder.java | 8 +++-- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index ab690a23..dd6e3561 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -22,7 +22,6 @@ import baritone.api.cache.IWorldProvider; import baritone.utils.Helper; import baritone.utils.accessor.IAnvilChunkLoader; import baritone.utils.accessor.IChunkProviderServer; -import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.server.integrated.IntegratedServer; import net.minecraft.world.WorldServer; @@ -50,13 +49,20 @@ public class WorldProvider implements IWorldProvider, Helper { return this.currentWorld; } - public final void initWorld(WorldClient world) { - int dimensionID = world.provider.getDimensionType().getId(); - File directory; - File readme; + /** + * Called when a new world is initialized to discover the + * + * @param dimension The ID of the world's dimension + */ + public final void initWorld(int dimension) { + // Fight me @leijurv + File directory, readme; + IntegratedServer integratedServer = mc.getIntegratedServer(); + + // If there is an integrated server running (Aka Singleplayer) then do magic to find the world save file if (integratedServer != null) { - WorldServer localServerWorld = integratedServer.getWorld(dimensionID); + WorldServer localServerWorld = integratedServer.getWorld(dimension); IChunkProviderServer provider = (IChunkProviderServer) localServerWorld.getChunkProvider(); IAnvilChunkLoader loader = (IAnvilChunkLoader) provider.getChunkLoader(); directory = loader.getChunkSaveLocation(); @@ -69,27 +75,27 @@ public class WorldProvider implements IWorldProvider, Helper { directory = new File(directory, "baritone"); readme = directory; - - } else { - //remote + } else { // Otherwise, the server must be remote... directory = new File(Baritone.getDir(), mc.getCurrentServerData().serverIP); readme = Baritone.getDir(); } + // lol wtf is this baritone folder in my minecraft save? try (FileOutputStream out = new FileOutputStream(new File(readme, "readme.txt"))) { // good thing we have a readme out.write("https://github.com/cabaletta/baritone\n".getBytes()); } catch (IOException ignored) {} - directory = new File(directory, "DIM" + dimensionID); - Path dir = directory.toPath(); + // We will actually store the world data in a subfolder: "DIM" + Path dir = new File(directory, "DIM" + dimension).toPath(); if (!Files.exists(dir)) { try { Files.createDirectories(dir); } catch (IOException ignored) {} } + System.out.println("Baritone world data dir: " + dir); - this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimensionID)); + this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, dimension)); } public final void closeWorld() { diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index 2859731a..5646a1d4 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -103,7 +103,7 @@ public final class GameEventHandler implements IGameEventListener, Helper { if (event.getState() == EventState.POST) { cache.closeWorld(); if (event.getWorld() != null) { - cache.initWorld(event.getWorld()); + cache.initWorld(event.getWorld().provider.getDimensionType().getId()); } } diff --git a/src/main/java/baritone/utils/accessor/IAnvilChunkLoader.java b/src/main/java/baritone/utils/accessor/IAnvilChunkLoader.java index c243ae0e..8606bc3f 100644 --- a/src/main/java/baritone/utils/accessor/IAnvilChunkLoader.java +++ b/src/main/java/baritone/utils/accessor/IAnvilChunkLoader.java @@ -17,9 +17,13 @@ package baritone.utils.accessor; +import baritone.cache.WorldProvider; + import java.io.File; /** + * @see WorldProvider + * * @author Brady * @since 8/4/2018 11:36 AM */ diff --git a/src/main/java/baritone/utils/accessor/IChunkProviderServer.java b/src/main/java/baritone/utils/accessor/IChunkProviderServer.java index 78a471b2..176f05a3 100644 --- a/src/main/java/baritone/utils/accessor/IChunkProviderServer.java +++ b/src/main/java/baritone/utils/accessor/IChunkProviderServer.java @@ -17,9 +17,12 @@ package baritone.utils.accessor; +import net.minecraft.world.WorldProvider; import net.minecraft.world.chunk.storage.IChunkLoader; /** + * @see WorldProvider + * * @author Brady * @since 8/4/2018 11:33 AM */ diff --git a/src/main/java/baritone/utils/pathing/BetterWorldBorder.java b/src/main/java/baritone/utils/pathing/BetterWorldBorder.java index 8a5c79d5..9d8f3ef8 100644 --- a/src/main/java/baritone/utils/pathing/BetterWorldBorder.java +++ b/src/main/java/baritone/utils/pathing/BetterWorldBorder.java @@ -17,10 +17,14 @@ package baritone.utils.pathing; -import baritone.utils.Helper; import net.minecraft.world.border.WorldBorder; -public class BetterWorldBorder implements Helper { +/** + * Essentially, a "rule" for the path finder, prevents proposed movements from attempting to venture + * into the world border, and prevents actual movements from placing blocks in the world border. + */ +public class BetterWorldBorder { + private final double minX; private final double maxX; private final double minZ;