From d38711ca4bee9ec8bb1f9a6067993a851a66f41f Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sun, 21 Jul 2024 20:05:36 -0500 Subject: [PATCH] Fix replay mod not showing LODs --- .../core/api/internal/ClientApi.java | 25 +++++++++++++++++-- .../distanthorizons/core/config/Config.java | 8 ++++++ .../structure/ClientOnlySaveStructure.java | 24 +++++++++++++----- .../minecraft/IMinecraftClientWrapper.java | 2 ++ .../assets/distanthorizons/lang/en_us.json | 2 ++ 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java index b37910884..355396630 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/api/internal/ClientApi.java @@ -23,6 +23,7 @@ import com.seibel.distanthorizons.api.DhApi; import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass; import com.seibel.distanthorizons.api.methods.events.abstractEvents.*; import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam; +import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure; import com.seibel.distanthorizons.core.level.IKeyedClientLevelManager; import com.seibel.distanthorizons.core.pos.DhChunkPos; import com.seibel.distanthorizons.core.render.DhApiRenderProxy; @@ -53,6 +54,7 @@ import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; +import java.io.File; import java.util.HashMap; import java.util.HashSet; import java.util.Queue; @@ -125,9 +127,28 @@ public class ClientApi public synchronized void onClientOnlyConnected() { // only continue if the client is connected to a different server - if (MC.clientConnectedToDedicatedServer()) + boolean connectedToServer = MC.clientConnectedToDedicatedServer(); + boolean connectedToReplay = MC.connectedToReplay(); + if (connectedToServer || connectedToReplay) { - LOGGER.info("Client on ClientOnly mode connecting."); + if (connectedToServer) + { + LOGGER.info("Client on ClientOnly mode connecting."); + } + else + { + LOGGER.info("Replay on ClientServer mode connecting."); + + if (Config.Client.Advanced.Logging.showReplayWarningOnStartup.get()) + { + MC.sendChatMessage("\u00A76" + "Distant Horizons: Replay detected." + "\u00A7r"); // gold color + MC.sendChatMessage("DH may behave strangely or have missing functionality."); + MC.sendChatMessage("In order to use pre-generated LODs, put your DH database(s) in:"); + MC.sendChatMessage("\u00A77"+".Minecraft" + File.separator + ClientOnlySaveStructure.SERVER_DATA_FOLDER_NAME + File.separator + ClientOnlySaveStructure.REPLAY_SERVER_FOLDER_NAME + File.separator + "DIMENSION_NAME"+"\u00A7r"); // light gray color + MC.sendChatMessage("This can be disabled in DH's config under Advanced -> Logging."); + MC.sendChatMessage(""); + } + } // firing after clientLevelLoadEvent // TODO if level has prepped to load it should fire level load event diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java index 56a3cde8e..a2c786984 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/Config.java @@ -616,6 +616,7 @@ public class Config @Deprecated public static ConfigEntry caveCullingHeight = new ConfigEntry.Builder() .setMinDefaultMax(-4096, 40, 4096) + .setAppearance(EConfigEntryAppearance.ONLY_IN_API) .comment("" + "At what Y value should cave culling start?") .build(); @@ -1209,6 +1210,13 @@ public class Config + "memory allocated to run DH well.") .build(); + public static ConfigEntry showReplayWarningOnStartup = new ConfigEntry.Builder() + .set(true) + .comment("" + + "If enabled, a chat message will be displayed when a replay is started \n" + + "giving some basic information about how DH will function.") + .build(); + } public static class Debugging diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/structure/ClientOnlySaveStructure.java b/core/src/main/java/com/seibel/distanthorizons/core/file/structure/ClientOnlySaveStructure.java index dc8cad673..17a2c4d90 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/structure/ClientOnlySaveStructure.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/structure/ClientOnlySaveStructure.java @@ -41,13 +41,17 @@ import java.util.*; */ public class ClientOnlySaveStructure extends AbstractSaveStructure { - final File folder; - private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); - private static final IMinecraftSharedWrapper MC_SHARED = SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class); + public static final String SERVER_DATA_FOLDER_NAME = "Distant_Horizons_server_data"; + public static final String REPLAY_SERVER_FOLDER_NAME = "REPLAY"; public static final String INVALID_FILE_CHARACTERS_REGEX = "[\\\\/:*?\"<>|]"; - SubDimensionLevelMatcher subDimMatcher = null; - final HashMap levelWrapperToFileMap = new HashMap<>(); + private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class); + private static final IMinecraftSharedWrapper MC_SHARED = SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class); + + + private SubDimensionLevelMatcher subDimMatcher = null; + private final File folder; + private final HashMap levelWrapperToFileMap = new HashMap<>(); @@ -237,7 +241,7 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure private static String getSaveStructureFolderPath() { String path = MC_SHARED.getInstallationDirectory().getPath() + File.separatorChar - + "Distant_Horizons_server_data" + File.separatorChar + + SERVER_DATA_FOLDER_NAME + File.separatorChar + getServerFolderName(); return path; } @@ -245,6 +249,14 @@ public class ClientOnlySaveStructure extends AbstractSaveStructure /** Generated from the server the client is currently connected to. */ private static String getServerFolderName() { + // if connected to a replay we won't have any server info + // use the dedicated replay server folder + if (MC_CLIENT.connectedToReplay()) + { + return REPLAY_SERVER_FOLDER_NAME; + } + + // parse the current server's IP ParsedIp parsedIp = new ParsedIp(MC_CLIENT.getCurrentServerIp()); String serverIpCleaned = parsedIp.ip.replaceAll(INVALID_FILE_CHARACTERS_REGEX, ""); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftClientWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftClientWrapper.java index 0c946c2aa..1a57a7221 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftClientWrapper.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/minecraft/IMinecraftClientWrapper.java @@ -62,6 +62,8 @@ public interface IMinecraftClientWrapper extends IBindable boolean hasSinglePlayerServer(); boolean clientConnectedToDedicatedServer(); + /** for use with the Replay mod */ + boolean connectedToReplay(); String getCurrentServerName(); String getCurrentServerIp(); diff --git a/core/src/main/resources/assets/distanthorizons/lang/en_us.json b/core/src/main/resources/assets/distanthorizons/lang/en_us.json index f003bd700..8918f8820 100644 --- a/core/src/main/resources/assets/distanthorizons/lang/en_us.json +++ b/core/src/main/resources/assets/distanthorizons/lang/en_us.json @@ -558,6 +558,8 @@ "Network Events", "distanthorizons.config.client.advanced.logging.showLowMemoryWarningOnStartup": "Show Low Memory Warning", + "distanthorizons.config.client.advanced.logging.showReplayWarningOnStartup": + "Show Replay Warning",