From 60537cda1bcb91633489544d78b5ceba4c8dd025 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Wed, 24 Dec 2025 22:04:50 -0600 Subject: [PATCH] Replace MC color code strings with an enum --- .../core/api/internal/ClientApi.java | 34 ++++++++------- .../core/enums/EMinecraftColor.java | 41 +++++++++++++++++-- .../core/logging/DhLogger.java | 17 ++++---- .../core/pooling/PhantomArrayListPool.java | 4 +- .../core/world/DhClientServerWorld.java | 3 +- .../core/world/DhClientWorld.java | 7 ++-- .../core/world/DhServerWorld.java | 7 ++-- 7 files changed, 75 insertions(+), 38 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 6ef56d478..bdbd87193 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 @@ -24,6 +24,7 @@ import com.seibel.distanthorizons.api.enums.config.EDhApiMcRenderingFadeMode; import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass; import com.seibel.distanthorizons.api.methods.events.abstractEvents.*; import com.seibel.distanthorizons.core.api.internal.rendering.DhRenderState; +import com.seibel.distanthorizons.core.enums.EMinecraftColor; import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.network.messages.MessageRegistry; @@ -152,10 +153,10 @@ public class ClientApi if (Config.Common.Logging.Warning.showReplayWarningOnStartup.get()) { - MC_CLIENT.sendChatMessage("\u00A76" + "Distant Horizons: Replay detected." + "\u00A7r"); // gold color + MC_CLIENT.sendChatMessage(EMinecraftColor.ORANGE + "Distant Horizons: Replay detected." + EMinecraftColor.CLEAR_FORMATTING); MC_CLIENT.sendChatMessage("DH may behave strangely or have missing functionality."); MC_CLIENT.sendChatMessage("In order to use pre-generated LODs, put your DH database(s) in:"); - MC_CLIENT.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_CLIENT.sendChatMessage(EMinecraftColor.GRAY +".Minecraft" + File.separator + ClientOnlySaveStructure.SERVER_DATA_FOLDER_NAME + File.separator + ClientOnlySaveStructure.REPLAY_SERVER_FOLDER_NAME + File.separator + "DIMENSION_NAME"+EMinecraftColor.CLEAR_FORMATTING); MC_CLIENT.sendChatMessage("This can be disabled in DH's config under Advanced -> Logging."); MC_CLIENT.sendChatMessage(""); } @@ -507,10 +508,10 @@ public class ClientApi this.rendererDisabledBecauseOfExceptions = true; LOGGER.error("Unexpected Renderer error in render pass [" + renderPass + "]. Error: " + e.getMessage(), e); - MC_CLIENT.sendChatMessage("\u00A74\u00A7l\u00A7uERROR: Distant Horizons renderer has encountered an exception!"); - MC_CLIENT.sendChatMessage("\u00A74Renderer disabled to try preventing GL state corruption."); - MC_CLIENT.sendChatMessage("\u00A74Toggle DH rendering via the config UI to re-activate DH rendering."); - MC_CLIENT.sendChatMessage("\u00A74Error: " + e); + MC_CLIENT.sendChatMessage(EMinecraftColor.DARK_RED + "" + EMinecraftColor.BOLD + "ERROR: Distant Horizons renderer has encountered an exception!" + EMinecraftColor.CLEAR_FORMATTING); + MC_CLIENT.sendChatMessage(EMinecraftColor.DARK_RED + "Renderer disabled to try preventing GL state corruption." + EMinecraftColor.CLEAR_FORMATTING); + MC_CLIENT.sendChatMessage(EMinecraftColor.DARK_RED + "Toggle DH rendering via the config UI to re-activate DH rendering." + EMinecraftColor.CLEAR_FORMATTING); + MC_CLIENT.sendChatMessage(EMinecraftColor.DARK_RED + "Error: " + EMinecraftColor.CLEAR_FORMATTING + e); } @@ -655,8 +656,7 @@ public class ClientApi // remind the user that this is a development build String message = - // green text - "\u00A72" + "Distant Horizons: nightly/unstable build, version: [" + ModInfo.VERSION+"]." + "\u00A7r\n" + + EMinecraftColor.DARK_GREEN + "Distant Horizons: nightly/unstable build, version: [" + ModInfo.VERSION+"]." +EMinecraftColor.CLEAR_FORMATTING + "\n" + "Issues may occur with this version.\n" + "Here be dragons!\n"; MC_CLIENT.sendChatMessage(message); @@ -680,7 +680,7 @@ public class ClientApi { String message = // orange text - "\u00A76" + "Distant Horizons: Low memory detected." + "\u00A7r \n" + + EMinecraftColor.ORANGE + "Distant Horizons: Low memory detected." + EMinecraftColor.CLEAR_FORMATTING + "\n" + "Stuttering or low FPS may occur. \n" + "Please increase Minecraft's available memory to 4 GB or more. \n" + "This warning can be disabled in DH's config under Advanced -> Logging. \n"; @@ -702,15 +702,13 @@ public class ClientApi this.lastStaticWarningMessageSentMsTime = System.currentTimeMillis(); String message = - // yellow text - "\u00A7e" + "Distant Horizons: High vanilla render distance detected." + "\u00A7r \n" + - "Using a high vanilla render distance uses a lot of CPU power \n" + - "and doesn't improve graphics much after about 12.\n" + - "Lowing your vanilla render distance will give you better FPS\n" + - "and reduce stuttering at a similar visual quality.\n" + - // gray text - "\u00A77" + "A vanilla render distance of 8 is recommended." + "\u00A7r \n" + - "This message can be disabled in DH's config under Advanced -> Logging.\n"; + EMinecraftColor.YELLOW + "Distant Horizons: High vanilla render distance detected." + EMinecraftColor.CLEAR_FORMATTING + "\n" + + "Using a high vanilla render distance uses a lot of CPU power \n" + + "and doesn't improve graphics much after about 12.\n" + + "Lowing your vanilla render distance will give you better FPS\n" + + "and reduce stuttering at a similar visual quality.\n" + + EMinecraftColor.GRAY + "A vanilla render distance of 8 is recommended." + EMinecraftColor.CLEAR_FORMATTING + "\n" + + "This message can be disabled in DH's config under Advanced -> Logging.\n"; MC_CLIENT.sendChatMessage(message); } } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/enums/EMinecraftColor.java b/core/src/main/java/com/seibel/distanthorizons/core/enums/EMinecraftColor.java index 3e4164192..8e03f461d 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/enums/EMinecraftColor.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/enums/EMinecraftColor.java @@ -1,12 +1,47 @@ package com.seibel.distanthorizons.core.enums; /** - * TODO * might be deprecated in the future? in that case we'll probably want a wrapper * function to handle colors for new MC versions - * + *

* source: https://minecraft.wiki/w/Formatting_codes */ -public class EMinecraftColor +public enum EMinecraftColor // TODO EMinecraftTextFormat { + BLACK("\u00A70"), + DARK_BLUE("\u00A71"), + DARK_GREEN("\u00A72"), + DARK_AQUA("\u00A73"), + DARK_RED("\u00A74"), + DARK_PURPLE("\u00A75"), + ORANGE("\u00A76"), + GRAY("\u00A77"), + DARK_GRAY("\u00A78"), + BLUE("\u00A79"), + GREEN("\u00A7a"), + AQUA("\u00A7b"), + RED("\u00A7c"), + LIGHT_PURPLE("\u00A7d"), + YELLOW("\u00A7e"), + WHITE("\u00A7f"), + + OBFUSCATED("\u00A7k"), + BOLD("\u00A7l"), + STRIKETHROUGH("\u00A7m"), + UNDERLINE("\u00A7n"), + ITALIC("\u00A7o"), + CLEAR_FORMATTING("\u00A7r"); + + public final String colorCode; + + EMinecraftColor(String colorCode) + { + this.colorCode = colorCode; + } + + + + @Override + public String toString() { return this.colorCode; } + } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/logging/DhLogger.java b/core/src/main/java/com/seibel/distanthorizons/core/logging/DhLogger.java index 6a5de6fda..1840da3e3 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/logging/DhLogger.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/logging/DhLogger.java @@ -24,6 +24,7 @@ import com.seibel.distanthorizons.core.config.Config; import com.seibel.distanthorizons.core.config.listeners.IConfigListener; import com.seibel.distanthorizons.core.config.types.ConfigEntry; import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector; +import com.seibel.distanthorizons.core.enums.EMinecraftColor; import com.seibel.distanthorizons.core.util.ThreadUtil; import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper; import com.seibel.distanthorizons.coreapi.ModInfo; @@ -302,32 +303,32 @@ public class DhLogger implements IConfigListener String prefix = "[" + ModInfo.READABLE_NAME + "] "; if (logLevel == Level.ERROR) { - prefix += "\u00A74"; + prefix += EMinecraftColor.DARK_RED; } else if (logLevel == Level.WARN) { - prefix += "\u00A76"; + prefix += EMinecraftColor.ORANGE; } else if (logLevel == Level.INFO) { - prefix += "\u00A7f"; + prefix += EMinecraftColor.AQUA; } else if (logLevel == Level.DEBUG) { - prefix += "\u00A77"; + prefix += EMinecraftColor.GREEN; } else if (logLevel == Level.TRACE) { - prefix += "\u00A78"; + prefix += EMinecraftColor.DARK_GRAY; } else { - prefix += "\u00A7f"; + prefix += EMinecraftColor.WHITE; } - prefix += "\u00A7l\u00A7u"; + prefix += EMinecraftColor.BOLD + "" + EMinecraftColor.WHITE; prefix += logLevel.name(); - prefix += ":\u00A7r "; + prefix += EMinecraftColor.CLEAR_FORMATTING + " "; mc_client.sendChatMessage(prefix + message); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/pooling/PhantomArrayListPool.java b/core/src/main/java/com/seibel/distanthorizons/core/pooling/PhantomArrayListPool.java index 595a7630e..9b471eebd 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/pooling/PhantomArrayListPool.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/pooling/PhantomArrayListPool.java @@ -2,6 +2,7 @@ package com.seibel.distanthorizons.core.pooling; import com.seibel.distanthorizons.core.api.internal.ClientApi; import com.seibel.distanthorizons.core.config.Config; +import com.seibel.distanthorizons.core.enums.EMinecraftColor; import com.seibel.distanthorizons.core.logging.DhLogger; import com.seibel.distanthorizons.core.logging.DhLoggerBuilder; import com.seibel.distanthorizons.core.logging.f3.F3Screen; @@ -178,8 +179,7 @@ public class PhantomArrayListPool { lowMemoryWarningLogged = true; - // orange text - String message = "\u00A76" + "Distant Horizons: Insufficient memory detected." + "\u00A7r \n" + + String message = EMinecraftColor.ORANGE + "Distant Horizons: Insufficient memory detected." + EMinecraftColor.CLEAR_FORMATTING + "\n" + "This may cause stuttering or crashing. \n" + "Potential causes: \n" + "1. your allocated memory isn't high enough \n" + diff --git a/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientServerWorld.java b/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientServerWorld.java index af19c94f5..70a4ce003 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientServerWorld.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/world/DhClientServerWorld.java @@ -20,6 +20,7 @@ package com.seibel.distanthorizons.core.world; import com.seibel.distanthorizons.core.api.internal.ClientApi; +import com.seibel.distanthorizons.core.enums.EMinecraftColor; import com.seibel.distanthorizons.core.level.DhClientServerLevel; import com.seibel.distanthorizons.core.util.TimerUtil; import com.seibel.distanthorizons.core.util.LodUtil; @@ -82,7 +83,7 @@ public class DhClientServerWorld extends AbstractDhServerWorld { LOGGER.fatal("Failed to load server level, error: ["+e.getMessage()+"].", e); - ClientApi.INSTANCE.showChatMessageNextFrame(// red text - "\u00A7c" + "Distant Horizons: Server level loading failed." + "\u00A7r \n" + - "Unable to load level ["+serverLevelWrapper.getDhIdentifier()+"], LODs may not appear. See log for more information."); + ClientApi.INSTANCE.showChatMessageNextFrame( + EMinecraftColor.RED + "Distant Horizons: Server level loading failed." + EMinecraftColor.CLEAR_FORMATTING + "\n" + + "Unable to load level ["+serverLevelWrapper.getDhIdentifier()+"], LODs may not appear. See log for more information."); return null; }