diff --git a/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/fastSwitchMasaConfigGui/FastMasaGuiSwitcher.java b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/fastSwitchMasaConfigGui/FastMasaGuiSwitcher.java index c7e9363..a2420f7 100644 --- a/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/fastSwitchMasaConfigGui/FastMasaGuiSwitcher.java +++ b/src/main/java/com/plusls/MasaGadget/impl/mod_tweak/malilib/fastSwitchMasaConfigGui/FastMasaGuiSwitcher.java @@ -37,6 +37,9 @@ //$$ import net.neoforged.fml.ModContainer; //$$ import net.neoforged.fml.ModList; //$$ import net.neoforged.neoforge.client.gui.IConfigScreenFactory; +//$$ import org.thinkingstudio.mafglib.loader.entrypoints.ConfigScreenEntrypoint; +//$$ +//$$ import java.util.Optional; //#endif public class FastMasaGuiSwitcher { @@ -81,14 +84,12 @@ public void init() { throw new IllegalStateException("Re-trigger initialize."); } - if (MagicLib.getInstance().getCurrentPlatform().getPlatformType().isFabricLike() && - !MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModId.mod_menu)) { + //#if FABRIC_LIKE + if (!MagicLib.getInstance().getCurrentPlatform().isModLoaded(ModId.mod_menu)) { return; } - Minecraft client = Minecraft.getInstance(); - - //#if FABRIC_LIKE + Minecraft mc = Minecraft.getInstance(); FabricLoader.getInstance().getEntrypointContainers("modmenu", Object.class).forEach(entrypoint -> { ModMetadata metadata = entrypoint.getProvider().getMetadata(); try { @@ -129,7 +130,7 @@ public void init() { return; } - Screen screen = configScreenFactoryCompat.create(client.screen); + Screen screen = configScreenFactoryCompat.create(mc.screen); if (!(screen instanceof GuiConfigsBase)) { return; @@ -153,38 +154,55 @@ public void init() { } }); //#elseif FORGE_LIKE - //$$ ModList.get().getSortedMods().forEach(modContainer -> - //$$ modContainer.getCustomExtension(IConfigScreenFactory.class).ifPresent( - //$$ factory -> { - //$$ Screen screen = factory.createScreen(modContainer, client.screen); - //$$ - //$$ if (!(screen instanceof GuiConfigsBase)) { - //$$ return; - //$$ } + //$$ for (ModContainer mod : ModList.get().getSortedMods()) { + //$$ // Backward compatibility + //$$ try { + //$$ Optional entrypoint = mod.getCustomExtension(ConfigScreenEntrypoint.class); //$$ - //$$ String modName = modContainer.getModInfo().getDisplayName(); + //$$ if (entrypoint.isPresent()) { + //$$ this.buildGuiMap(mod, entrypoint.get().getModConfigScreenFactory()); + //$$ continue; + //$$ } + //$$ } catch (NoClassDefFoundError ignore) { + //$$ // NO-OP + //$$ } //$$ - //$$ if (!this.guiClass.containsKey(screen.getClass())) { - //$$ MasaGadgetScreenFactory masaGadgetScreenFactory = new MasaGadgetScreenFactory(modContainer, factory); - //$$ this.guiModName.put(masaGadgetScreenFactory, () -> modName); - //$$ this.guiClass.put(screen.getClass(), masaGadgetScreenFactory); - //$$ } else { - //$$ MasaGadgetScreenFactory savedConfigScreenFactory = this.guiClass.get(screen.getClass()); - //$$ String savedName = savedConfigScreenFactory.getClass().getName(); - //$$ - //$$ if (savedName.length() > modName.length()) { - //$$ MasaGadgetScreenFactory masaGadgetScreenFactory = new MasaGadgetScreenFactory(modContainer, factory); - //$$ this.guiModName.put(masaGadgetScreenFactory, () -> modName); - //$$ } - //$$ } - //$$ } - //$$ ) - //$$ ); + //$$ mod.getCustomExtension(IConfigScreenFactory.class).ifPresent(factory -> + //$$ this.buildGuiMap(mod, factory) + //$$ ); + //$$ } //#endif this.initialized.set(true); } + //#if FORGE_LIKE + //$$ private void buildGuiMap(ModContainer mod, IConfigScreenFactory factory) { + //$$ Minecraft mc = Minecraft.getInstance(); + //$$ Screen screen = factory.createScreen(mod, mc.screen); + //$$ + //$$ if (!(screen instanceof GuiConfigsBase)) { + //$$ return; + //$$ } + //$$ + //$$ String modName = mod.getModInfo().getDisplayName(); + //$$ + //$$ if (!this.guiClass.containsKey(screen.getClass())) { + //$$ MasaGadgetScreenFactory masaGadgetScreenFactory = new MasaGadgetScreenFactory(mod, factory); + //$$ this.guiModName.put(masaGadgetScreenFactory, () -> modName); + //$$ this.guiClass.put(screen.getClass(), masaGadgetScreenFactory); + //$$ } else { + //$$ MasaGadgetScreenFactory savedConfigScreenFactory = this.guiClass.get(screen.getClass()); + //$$ String savedName = savedConfigScreenFactory.getClass().getName(); + //$$ + //$$ if (savedName.length() > modName.length()) { + //$$ MasaGadgetScreenFactory masaGadgetScreenFactory = new MasaGadgetScreenFactory(mod, factory); + //$$ this.guiModName.put(masaGadgetScreenFactory, () -> modName); + //$$ } + //$$ } + //$$ } + //#endif + public List getModNameList() { return this.guiModName.values() .stream() diff --git a/versions/1.21.1-neoforge/gradle.properties b/versions/1.21.1-neoforge/gradle.properties index 61799c9..ee81c5a 100644 --- a/versions/1.21.1-neoforge/gradle.properties +++ b/versions/1.21.1-neoforge/gradle.properties @@ -8,9 +8,9 @@ dependencies.api.fabric_api_version=0.104.0+2.0.14+1.21.1 # Compatible Libraries dependencies.api.itemscroller_version=0.2.2-mc1.21.1 -dependencies.api.litematica_version=0.2.3-mc1.21.1 -dependencies.api.minihud_version=0.2.2-mc1.21.1 -dependencies.api.tweakeroo_version=0.2.4-mc1.21.1 +dependencies.api.litematica_version=0.3.1-mc1.21.1 +dependencies.api.minihud_version=0.3.1-mc1.21.1 +dependencies.api.tweakeroo_version=0.3.1-mc1.21.1 # Loom Properties loom.platform=neoforge