Skip to content

Commit

Permalink
ensure the obsolete modlist only gets generated once
Browse files Browse the repository at this point in the history
  • Loading branch information
WaitingIdly committed Dec 20, 2024
1 parent 2cd9e26 commit ec9e544
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
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
{
@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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -141,15 +142,35 @@ public class UTObsoleteModsHandler
}
});

public static boolean showObsoleteMods = true;
private static List<String> obsoleteModsList;
private static boolean hasShownObsoleteMods = false;

public static boolean hasObsoleteModsMessage()
{
return !UTObsoleteModsHandler.hasShownObsoleteMods() && !UTConfigGeneral.DEBUG.utBypassIncompatibilityToggle && !getObsoleteModsList().isEmpty();
}

public static List<String> obsoleteModsMessage()
{
List<String> messages = new ArrayList<>();
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<String> getObsoleteModsList()
{
if (obsoleteModsList == null) obsoleteModsList = generateObsoleteModsList();
return obsoleteModsList;
}

private static List<String> generateObsoleteModsList()
{
List<String> messages = new ArrayList<>();
Map<String, ModContainer> modIdMap = Loader.instance().getIndexedModList();
for (String modId : obsoleteModMap.keySet())
{
Expand All @@ -164,9 +185,23 @@ public static List<String> 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;
}

}

0 comments on commit ec9e544

Please sign in to comment.