From 6d6cbd8a44ecc27e18d3227c7ab6edb921cf1068 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Wed, 11 Sep 2024 17:11:55 -0500 Subject: [PATCH] add more getDimensinoName() calls and minor cleanup --- .../core/config/file/ConfigFileHandling.java | 44 ++++++++++++++++--- .../SubDimensionLevelMatcher.java | 2 +- .../core/level/DhClientLevel.java | 2 +- .../core/world/DhApiWorldProxy.java | 10 ++--- .../core/world/DhServerWorld.java | 2 + 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandling.java b/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandling.java index 966bc8310..ff5098250 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandling.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/file/ConfigFileHandling.java @@ -25,6 +25,7 @@ import com.seibel.distanthorizons.core.config.ConfigBase; import com.seibel.distanthorizons.core.config.types.AbstractConfigType; import com.seibel.distanthorizons.core.config.types.ConfigEntry; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; +import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -40,6 +41,9 @@ import java.nio.file.Path; */ public class ConfigFileHandling { + private static final IMinecraftSharedWrapper MC_SHARED = SingletonInjector.INSTANCE.get(IMinecraftSharedWrapper.class); + + public final ConfigBase configBase; public final Path configPath; @@ -48,6 +52,12 @@ public class ConfigFileHandling /** This is the object for night-config */ private final CommentedFileConfig nightConfig; + + + //=============// + // constructor // + //=============// + public ConfigFileHandling(ConfigBase configBase, Path configPath) { this.LOGGER = LogManager.getLogger(this.getClass().getSimpleName() + ", " + configBase.modID); @@ -57,6 +67,9 @@ public class ConfigFileHandling this.nightConfig = CommentedFileConfig.builder(this.configPath.toFile()).build(); } + + + /** Saves the entire config to the file */ public void saveToFile() { @@ -190,9 +203,20 @@ public class ConfigFileHandling /** Save an entry */ public void saveEntry(ConfigEntry entry, CommentedFileConfig workConfig) { - if (!entry.getAppearance().showInFile) return; - if (entry.getTrueValue() == null) - throw new IllegalArgumentException("Entry [" + entry.getNameWCategory() + "] is null, this may be a problem with [" + configBase.modName + "]. Please contact the authors"); + if (!entry.getAppearance().showInFile) + { + return; + } + else if (MC_SHARED.isDedicatedServer() && entry.getServersideShortName() == null) + { + // don't save server configs on the client + return; + } + else if (entry.getTrueValue() == null) + { + // TODO when can this happen? + throw new IllegalArgumentException("Entry [" + entry.getNameWCategory() + "] is null, this may be a problem with [" + configBase.modName + "]. Please contact the authors."); + } workConfig.set(entry.getNameWCategory(), ConfigTypeConverters.attemptToConvertToString(entry.getType(), entry.getTrueValue())); } @@ -259,11 +283,17 @@ public class ConfigFileHandling // Creates a comment for an entry public void createComment(ConfigEntry entry, CommentedFileConfig nightConfig) { - if ( - !entry.getAppearance().showInFile || - entry.getComment() == null - ) + if (!entry.getAppearance().showInFile + || entry.getComment() == null) + { return; + } + + if (MC_SHARED.isDedicatedServer() && entry.getServersideShortName() == null) + { + return; + } + String comment = entry.getComment().replaceAll("\n", "\n ").trim(); // the new line makes it easier to read and separate configs diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/subDimMatching/SubDimensionLevelMatcher.java b/core/src/main/java/com/seibel/distanthorizons/core/file/subDimMatching/SubDimensionLevelMatcher.java index 1442f168f..0e2bb8ee2 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/subDimMatching/SubDimensionLevelMatcher.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/subDimMatching/SubDimensionLevelMatcher.java @@ -196,7 +196,7 @@ public class SubDimensionLevelMatcher implements AutoCloseable //================================// // log the start of this attempt - LOGGER.info("Attempting to determine sub-dimension for [" + MC_CLIENT.getWrappedClientLevel().getDimensionType().getDimensionName() + "]"); + LOGGER.info("Attempting to determine sub-dimension for [" + MC_CLIENT.getWrappedClientLevel().getDimensionName() + "]"); LOGGER.info("Player block pos in dimension: [" + this.playerData.playerBlockPos.getX() + "," + this.playerData.playerBlockPos.getY() + "," + this.playerData.playerBlockPos.getZ() + "]"); LOGGER.info("Potential Sub Dimension folders: [" + this.potentialLevelFolders.size() + "]"); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java b/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java index 41f776f4f..0452cfec9 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java @@ -129,7 +129,7 @@ public class DhClientLevel extends AbstractDhLevel implements IDhClientLevel @Override public void addDebugMenuStringsToList(List messageList) { - String dimName = this.levelWrapper.getDimensionType().getDimensionName(); + String dimName = this.levelWrapper.getDimensionName(); boolean rendering = this.clientside.isRendering(); messageList.add("["+dimName+"] rendering: "+(rendering ? "yes" : "no")); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/world/DhApiWorldProxy.java b/core/src/main/java/com/seibel/distanthorizons/core/world/DhApiWorldProxy.java index b9a943691..3d61c026c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/world/DhApiWorldProxy.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/world/DhApiWorldProxy.java @@ -73,15 +73,13 @@ public class DhApiWorldProxy implements IDhApiWorldProxy throw new IllegalStateException(NO_WORLD_EXCEPTION_STRING); } - - if (!MC_SHARED.isDedicatedServer()) - { - return MC_CLIENT.getWrappedClientLevel(); - } - else + if (MC_SHARED.isDedicatedServer()) { return null; } + + + return MC_CLIENT.getWrappedClientLevel(); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java b/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java index 508271a02..dc140279c 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java @@ -186,8 +186,10 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld } } + @Override public void serverTick() { this.levels.values().forEach(DhServerLevel::serverTick); } + @Override public void doWorldGen() { this.levels.values().forEach(DhServerLevel::doWorldGen); }