Skip to content

Commit

Permalink
Merge pull request #607 from WaitingIdly/improve-obsolete-handler
Browse files Browse the repository at this point in the history
Use primitive Supplier and improve obsolete mod list handling
  • Loading branch information
ACGaming authored Dec 20, 2024
2 parents e58fe99 + 5b0037a commit cf0c1e0
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 24 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.setHasShownObsoleteMods(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mod.acgaming.universaltweaks.core;

import java.util.*;
import java.util.function.Supplier;
import java.util.function.BooleanSupplier;
import javax.annotation.Nullable;

import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -35,15 +35,15 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader

public static long launchTime;

private static final Map<String, Supplier<Boolean>> serversideMixinConfigs = ImmutableMap.copyOf(new HashMap<String, Supplier<Boolean>>()
private static final Map<String, BooleanSupplier> serversideMixinConfigs = ImmutableMap.copyOf(new HashMap<String, BooleanSupplier>()
{
{
put("mixins.tweaks.misc.buttons.snooper.server.json", () -> UTConfigTweaks.MISC.utSnooperToggle);
put("mixins.tweaks.misc.difficulty.server.json", () -> true);
}
});

private static final Map<String, Supplier<Boolean>> commonMixinConfigs = ImmutableMap.copyOf(new HashMap<String, Supplier<Boolean>>()
private static final Map<String, BooleanSupplier> commonMixinConfigs = ImmutableMap.copyOf(new HashMap<String, BooleanSupplier>()
{
{
put("mixins.bugfixes.blocks.comparatortiming.json", () -> UTConfigBugfixes.BLOCKS.utComparatorTimingToggle);
Expand Down Expand Up @@ -170,7 +170,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
}
});

private static final Map<String, Supplier<Boolean>> clientsideMixinConfigs = ImmutableMap.copyOf(new HashMap<String, Supplier<Boolean>>()
private static final Map<String, BooleanSupplier> clientsideMixinConfigs = ImmutableMap.copyOf(new HashMap<String, BooleanSupplier>()
{
{
put("mixins.bugfixes.blocks.banner.json", () -> UTConfigBugfixes.BLOCKS.utBannerBoundingBoxToggle && !renderLibLoaded);
Expand Down Expand Up @@ -307,8 +307,8 @@ public boolean shouldMixinConfigQueue(String mixinConfig)
// Causes crashes in dev env only
return !mixinConfig.equals("mixins.tweaks.misc.armorcurve.json");
}
Supplier<Boolean> sidedSupplier = UTLoadingPlugin.isClient ? clientsideMixinConfigs.get(mixinConfig) : null;
Supplier<Boolean> commonSupplier = commonMixinConfigs.get(mixinConfig);
return sidedSupplier != null ? sidedSupplier.get() : commonSupplier == null || commonSupplier.get();
BooleanSupplier sidedSupplier = UTLoadingPlugin.isClient ? clientsideMixinConfigs.get(mixinConfig) : null;
BooleanSupplier commonSupplier = commonMixinConfigs.get(mixinConfig);
return sidedSupplier != null ? sidedSupplier.getAsBoolean() : commonSupplier == null || commonSupplier.getAsBoolean();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.function.BooleanSupplier;

import com.google.common.collect.ImmutableMap;
import net.minecraftforge.fml.common.Loader;
Expand All @@ -15,7 +15,7 @@

public class UTMixinLoader implements ILateMixinLoader
{
private static final Map<String, Supplier<Boolean>> clientsideMixinConfigs = ImmutableMap.copyOf(new HashMap<String, Supplier<Boolean>>()
private static final Map<String, BooleanSupplier> clientsideMixinConfigs = ImmutableMap.copyOf(new HashMap<String, BooleanSupplier>()
{
{
put("mixins.mods.bibliocraft.json", () -> loaded("bibliocraft") && UTConfigMods.BIBLIOCRAFT.utDisableVersionCheckToggle);
Expand All @@ -34,7 +34,7 @@ public class UTMixinLoader implements ILateMixinLoader
}
});

private static final Map<String, Supplier<Boolean>> commonMixinConfigs = ImmutableMap.copyOf(new HashMap<String, Supplier<Boolean>>()
private static final Map<String, BooleanSupplier> commonMixinConfigs = ImmutableMap.copyOf(new HashMap<String, BooleanSupplier>()
{
{
put("mixins.mods.abyssalcraft.json", () -> loaded("abyssalcraft"));
Expand Down Expand Up @@ -140,8 +140,8 @@ public List<String> getMixinConfigs()
@Override
public boolean shouldMixinConfigQueue(String mixinConfig)
{
Supplier<Boolean> sidedSupplier = UTLoadingPlugin.isClient ? clientsideMixinConfigs.get(mixinConfig) : null;
Supplier<Boolean> commonSupplier = commonMixinConfigs.get(mixinConfig);
return sidedSupplier != null ? sidedSupplier.get() : commonSupplier == null || commonSupplier.get();
BooleanSupplier sidedSupplier = UTLoadingPlugin.isClient ? clientsideMixinConfigs.get(mixinConfig) : null;
BooleanSupplier commonSupplier = commonMixinConfigs.get(mixinConfig);
return sidedSupplier != null ? sidedSupplier.getAsBoolean() : commonSupplier == null || commonSupplier.getAsBoolean();
}
}
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 @@ -4,21 +4,22 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.function.BooleanSupplier;

import com.google.common.collect.ImmutableMap;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.fml.common.Loader;
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;

public class UTObsoleteModsHandler
{
private static final Map<String, Supplier<Boolean>> obsoleteModMap = ImmutableMap.copyOf(new HashMap<String, Supplier<Boolean>>()
private static final Map<String, BooleanSupplier> obsoleteModMap = ImmutableMap.copyOf(new HashMap<String, BooleanSupplier>()
{
{
put("aiimprovements", () -> UTConfigTweaks.ENTITIES.utAIReplacementToggle || UTConfigTweaks.ENTITIES.utAIRemovalToggle);
Expand Down Expand Up @@ -141,19 +142,39 @@ 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())
{
if (Loader.isModLoaded(modId) && obsoleteModMap.get(modId).get())
if (Loader.isModLoaded(modId) && obsoleteModMap.get(modId).getAsBoolean())
{
messages.add(modIdMap.get(modId).getName());
}
Expand All @@ -164,9 +185,16 @@ 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;
}
}

0 comments on commit cf0c1e0

Please sign in to comment.