aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java11
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/forge/ForgeCompat.java31
-rw-r--r--versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java66
3 files changed, 106 insertions, 2 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
index ffac8e3..841a157 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ModCard.java
@@ -8,6 +8,7 @@ import cc.polyfrost.oneconfig.gui.pages.ModsPage;
import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.internal.assets.SVGs;
import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
+import cc.polyfrost.oneconfig.internal.config.compatibility.forge.ForgeCompat;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.platform.Platform;
import cc.polyfrost.oneconfig.renderer.RenderManager;
@@ -92,8 +93,16 @@ public class ModCard extends BasicElement {
}
public void onClick() {
- if (isHoveredMain)
+ if (isHoveredMain) {
+ if (modData instanceof ForgeCompat.ForgeCompatMod) {
+ Runnable runnable = ForgeCompat.compatMods.get(modData);
+ if (runnable != null) {
+ runnable.run();
+ return;
+ }
+ }
OneConfigGui.INSTANCE.openPage(new ModConfigPage(modData.defaultPage));
+ }
}
public Mod getModData() {
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/forge/ForgeCompat.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/forge/ForgeCompat.java
new file mode 100644
index 0000000..fc5ca5e
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/compatibility/forge/ForgeCompat.java
@@ -0,0 +1,31 @@
+package cc.polyfrost.oneconfig.internal.config.compatibility.forge;
+
+import cc.polyfrost.oneconfig.config.data.Mod;
+import cc.polyfrost.oneconfig.config.data.ModType;
+import cc.polyfrost.oneconfig.config.migration.Migrator;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+
+public class ForgeCompat {
+ public static final HashMap<Mod, Runnable> compatMods = new HashMap<>();
+
+ public static class ForgeCompatMod extends Mod {
+
+ public ForgeCompatMod(String name, ModType modType, @Nullable String modIcon, @Nullable Migrator migrator) {
+ super(name, modType, modIcon, migrator);
+ }
+
+ public ForgeCompatMod(String name, ModType modType, @Nullable String modIcon) {
+ super(name, modType, modIcon);
+ }
+
+ public ForgeCompatMod(String name, ModType modType, @Nullable Migrator migrator) {
+ super(name, modType, migrator);
+ }
+
+ public ForgeCompatMod(String name, ModType modType) {
+ super(name, modType);
+ }
+ }
+}
diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java b/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
index 7eb5ef9..398aceb 100644
--- a/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
+++ b/versions/src/main/java/cc/polyfrost/oneconfig/internal/OneConfig.java
@@ -1,10 +1,13 @@
package cc.polyfrost.oneconfig.internal;
+import cc.polyfrost.oneconfig.config.data.Mod;
+import cc.polyfrost.oneconfig.config.data.ModType;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.ShutdownEvent;
import cc.polyfrost.oneconfig.internal.command.OneConfigCommand;
import cc.polyfrost.oneconfig.internal.config.OneConfigConfig;
import cc.polyfrost.oneconfig.internal.config.Preferences;
+import cc.polyfrost.oneconfig.internal.config.compatibility.forge.ForgeCompat;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
import cc.polyfrost.oneconfig.internal.config.core.KeyBindHandler;
import cc.polyfrost.oneconfig.internal.gui.BlurHandler;
@@ -13,10 +16,21 @@ import cc.polyfrost.oneconfig.libs.eventbus.Subscribe;
import cc.polyfrost.oneconfig.utils.commands.CommandManager;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+//#if FORGE==1
+import net.minecraftforge.fml.common.ModContainer;
+//#endif
+
+//#if MC<=11202
+import net.minecraftforge.fml.client.FMLClientHandler;
+import net.minecraftforge.fml.client.IModGuiFactory;
+import net.minecraftforge.fml.common.Loader;
+//#endif
-import java.io.File;
+import java.util.Map;
/**
* The main class of OneConfig.
@@ -50,6 +64,56 @@ public class OneConfig {
if (Preferences.getInstance() == null) {
Preferences.getInstance();
}
+ //#if FORGE==1
+ //#if MC<=11202
+ for (ModContainer mod : Loader.instance().getActiveModList()) {
+
+ IModGuiFactory factory = FMLClientHandler.instance().getGuiFactoryFor(mod);
+ //#if MC<=10809
+ if (factory == null || factory.mainConfigGuiClass() == null) continue;
+ //#else
+ //$$ if (factory == null || !factory.hasConfigGui()) continue;
+ //#endif
+ ForgeCompat.compatMods.put(new ForgeCompat.ForgeCompatMod(mod.getName(), ModType.THIRD_PARTY), () -> {
+ try {
+ GuiUtils.displayScreen(
+ //#if MC<=10809
+ factory.mainConfigGuiClass().getConstructor(GuiScreen.class).newInstance(Minecraft.getMinecraft().currentScreen)
+ //#else
+ //$$ factory.createConfigGui(Minecraft.getMinecraft().currentScreen)
+ //#endif
+ );
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
+ }
+ //#else
+ //$$ try {
+ //$$ java.lang.reflect.Field mods = net.minecraftforge.fml.ModList.class.getDeclaredField("mods");
+ //$$ mods.setAccessible(true);
+ //$$ for (ModContainer container : ((java.util.List<ModContainer>) mods.get(net.minecraftforge.fml.ModList.get()))) {
+ //$$ try {
+ //$$ java.util.Optional<java.util.function.BiFunction<Minecraft, net.minecraft.client.gui.screen.Screen, net.minecraft.client.gui.screen.Screen>> gui = container.getCustomExtension(net.minecraftforge.fml.ExtensionPoint.CONFIGGUIFACTORY);
+ //$$ gui.ifPresent(minecraftScreenScreenBiFunction -> ForgeCompat.compatMods.put(new ForgeCompat.ForgeCompatMod(container.getModId(), ModType.THIRD_PARTY), () -> {
+ //$$ net.minecraft.client.gui.screen.Screen screen = minecraftScreenScreenBiFunction.apply(Minecraft.getInstance(), Minecraft.getInstance().currentScreen);
+ //$$ if (screen != null) {
+ //$$ GuiUtils.displayScreen(screen);
+ //$$ }
+ //$$ }));
+ //$$ } catch (Exception e) {
+ //$$ e.printStackTrace();
+ //$$ }
+ //$$ }
+ //$$ } catch (Exception e) {
+ //$$ e.printStackTrace();
+ //$$ }
+ //#endif
+
+ for (Map.Entry<Mod, Runnable> entry : ForgeCompat.compatMods.entrySet()) {
+ ConfigCore.mods.add(entry.getKey());
+ }
+ //#endif
GuiUtils.getDeltaTime(); // called to make sure static initializer is called
try {
EventManager.INSTANCE.register(BlurHandler.INSTANCE);