From ec9e5447ce1b8187f332661d192ce895c5e81f3a Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:02:56 -0800 Subject: [PATCH] ensure the obsolete modlist only gets generated once --- .../universaltweaks/UniversalTweaks.java | 2 +- .../config/UTConfigGeneral.java | 2 +- .../util/compat/UTCompatScreenHandler.java | 5 +-- .../util/compat/UTObsoleteModsHandler.java | 41 +++++++++++++++++-- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java b/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java index 2ad393f0..40724c44 100644 --- a/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/UniversalTweaks.java @@ -234,7 +234,7 @@ public void onLoadComplete(FMLLoadCompleteEvent event) if (Loader.isModLoaded("tconstruct") && UTConfigMods.TINKERS_CONSTRUCT.utTConOreDictCacheToggle) UTOreDictCache.onLoadComplete(); if (UTConfigTweaks.PERFORMANCE.ENTITY_RADIUS_CHECK.utEntityRadiusCheckCategoryToggle) UTEntityRadiusCheck.onLoadComplete(); if (UTConfigGeneral.DEBUG.utLoadingTimeToggle) LOGGER.info("The game loaded in approximately {} seconds", (System.currentTimeMillis() - UTLoadingPlugin.launchTime) / 1000F); - if (UTObsoleteModsHandler.showObsoleteMods && UTObsoleteModsHandler.obsoleteModsMessage().size() > 5 && !UTConfigGeneral.DEBUG.utBypassIncompatibilityToggle) + if (UTObsoleteModsHandler.hasObsoleteModsMessage()) { for (String line : UTObsoleteModsHandler.obsoleteModsMessage()) { diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigGeneral.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigGeneral.java index f68a7690..43f1b538 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigGeneral.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigGeneral.java @@ -46,7 +46,7 @@ public static void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event if (event.getModID().equals(UniversalTweaks.MODID)) { ConfigManager.sync(UniversalTweaks.MODID, Config.Type.INSTANCE); - UTObsoleteModsHandler.showObsoleteMods = true; + UTObsoleteModsHandler.resetObsoleteMods(); } } } diff --git a/src/main/java/mod/acgaming/universaltweaks/util/compat/UTCompatScreenHandler.java b/src/main/java/mod/acgaming/universaltweaks/util/compat/UTCompatScreenHandler.java index c118f559..a81bc591 100644 --- a/src/main/java/mod/acgaming/universaltweaks/util/compat/UTCompatScreenHandler.java +++ b/src/main/java/mod/acgaming/universaltweaks/util/compat/UTCompatScreenHandler.java @@ -8,7 +8,6 @@ import net.minecraftforge.fml.relauncher.Side; import mod.acgaming.universaltweaks.UniversalTweaks; -import mod.acgaming.universaltweaks.config.UTConfigGeneral; @Mod.EventBusSubscriber(modid = UniversalTweaks.MODID, value = Side.CLIENT) public class UTCompatScreenHandler @@ -16,10 +15,10 @@ public class UTCompatScreenHandler @SubscribeEvent(priority = EventPriority.LOWEST) public static void utDisplayCompatScreens(GuiOpenEvent event) { - if (event.getGui() instanceof GuiMainMenu && UTObsoleteModsHandler.showObsoleteMods && UTObsoleteModsHandler.obsoleteModsMessage().size() > 5 && !UTConfigGeneral.DEBUG.utBypassIncompatibilityToggle) + if (event.getGui() instanceof GuiMainMenu && UTObsoleteModsHandler.hasObsoleteModsMessage()) { event.setGui(new UTCompatScreen(UTObsoleteModsHandler.obsoleteModsMessage())); - UTObsoleteModsHandler.showObsoleteMods = false; + UTObsoleteModsHandler.setHasShownObsoleteMods(true); } } } \ No newline at end of file diff --git a/src/main/java/mod/acgaming/universaltweaks/util/compat/UTObsoleteModsHandler.java b/src/main/java/mod/acgaming/universaltweaks/util/compat/UTObsoleteModsHandler.java index 2729a024..299e2980 100644 --- a/src/main/java/mod/acgaming/universaltweaks/util/compat/UTObsoleteModsHandler.java +++ b/src/main/java/mod/acgaming/universaltweaks/util/compat/UTObsoleteModsHandler.java @@ -12,6 +12,7 @@ import net.minecraftforge.fml.common.ModContainer; import mod.acgaming.universaltweaks.config.UTConfigBugfixes; +import mod.acgaming.universaltweaks.config.UTConfigGeneral; import mod.acgaming.universaltweaks.config.UTConfigMods; import mod.acgaming.universaltweaks.config.UTConfigTweaks; import mod.acgaming.universaltweaks.util.UTReflectionUtil; @@ -141,7 +142,13 @@ public class UTObsoleteModsHandler } }); - public static boolean showObsoleteMods = true; + private static List obsoleteModsList; + private static boolean hasShownObsoleteMods = false; + + public static boolean hasObsoleteModsMessage() + { + return !UTObsoleteModsHandler.hasShownObsoleteMods() && !UTConfigGeneral.DEBUG.utBypassIncompatibilityToggle && !getObsoleteModsList().isEmpty(); + } public static List obsoleteModsMessage() { @@ -149,7 +156,21 @@ public static List obsoleteModsMessage() messages.add(new TextComponentTranslation("msg.universaltweaks.obsoletemods.warning1").getFormattedText()); messages.add(new TextComponentTranslation("msg.universaltweaks.obsoletemods.warning2").getFormattedText()); messages.add(""); + messages.addAll(getObsoleteModsList()); + messages.add(""); + messages.add(new TextComponentTranslation("msg.universaltweaks.obsoletemods.warning3").getFormattedText()); + return messages; + } + + private static List getObsoleteModsList() + { + if (obsoleteModsList == null) obsoleteModsList = generateObsoleteModsList(); + return obsoleteModsList; + } + private static List generateObsoleteModsList() + { + List messages = new ArrayList<>(); Map modIdMap = Loader.instance().getIndexedModList(); for (String modId : obsoleteModMap.keySet()) { @@ -164,9 +185,23 @@ public static List obsoleteModsMessage() if (UTReflectionUtil.isClassLoaded("io.github.jikuja.LocaleTweaker") && UTConfigBugfixes.MISC.utLocaleToggle) messages.add("LocaleFixer"); if (UTReflectionUtil.isClassLoaded("com.cleanroommc.blockdelayremover.BlockDelayRemoverCore") && UTConfigTweaks.BLOCKS.utBlockHitDelay != 5) messages.add("Block Delay Remover"); if (UTReflectionUtil.isClassLoaded("io.github.barteks2x.chunkgenlimiter.ChunkGenLimitMod") && UTConfigTweaks.WORLD.CHUNK_GEN_LIMIT.utChunkGenLimitToggle) messages.add("Chunk Generation Limiter"); - messages.add(""); - messages.add(new TextComponentTranslation("msg.universaltweaks.obsoletemods.warning3").getFormattedText()); return messages; } + public static boolean hasShownObsoleteMods() + { + return hasShownObsoleteMods; + } + + public static void setHasShownObsoleteMods(boolean value) + { + hasShownObsoleteMods = value; + } + + public static void resetObsoleteMods() + { + hasShownObsoleteMods = false; + obsoleteModsList = null; + } + } \ No newline at end of file