From 5bf7e3b5c633f48645c1c2c2e14e5b0c61f8ab75 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 8 Jun 2023 00:34:53 +0200 Subject: [PATCH] [Change] Re-Enabled ModMenu Support --- bclib.gradle | 2 +- gradle.properties | 2 +- .../modmenu/ModMenuEntryPoint.java | 63 +++--- .../modmenu/ModMenuIntegration.java | 184 ------------------ src/main/resources/fabric.mod.json | 4 +- 5 files changed, 35 insertions(+), 220 deletions(-) delete mode 100644 src/main/java/org/betterx/bclib/integration/modmenu/ModMenuIntegration.java diff --git a/bclib.gradle b/bclib.gradle index bdb5c402..1158b4d8 100644 --- a/bclib.gradle +++ b/bclib.gradle @@ -59,7 +59,7 @@ dependencies { mappings loom.officialMojangMappings() modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" -// modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}" + modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}" // // modCompileOnly "dev.emi:emi:${emi_version}" diff --git a/gradle.properties b/gradle.properties index b8443f89..6540b695 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,6 +16,6 @@ mod_version=3.0.0 maven_group=org.betterx.bclib archives_base_name=bclib # Dependencies -modmenu_version=6.1.0-rc.3 +modmenu_version=7.0.0 emi_version=0.7.3+1.19.4 wunderlib_version=1.1.0 \ No newline at end of file diff --git a/src/main/java/org/betterx/bclib/integration/modmenu/ModMenuEntryPoint.java b/src/main/java/org/betterx/bclib/integration/modmenu/ModMenuEntryPoint.java index 52253da4..7a10c0e1 100644 --- a/src/main/java/org/betterx/bclib/integration/modmenu/ModMenuEntryPoint.java +++ b/src/main/java/org/betterx/bclib/integration/modmenu/ModMenuEntryPoint.java @@ -1,34 +1,33 @@ package org.betterx.bclib.integration.modmenu; -//import org.betterx.bclib.client.gui.modmenu.MainScreen; -// -//import com.terraformersmc.modmenu.api.ConfigScreenFactory; -//import com.terraformersmc.modmenu.api.ModMenuApi; -// -//import java.util.HashMap; -//import java.util.Map; -//import java.util.function.Function; -// -// -///** -// * Internal class to hook into ModMenu, you should not need to use this class. If you want to register a -// * ModMenu Screen for a Mod using BCLib, use {@link ModMenu#addModMenuScreen(String, Function)} -// */ -//public class ModMenuEntryPoint implements ModMenuApi { -// @Override -// public Map> getProvidedConfigScreenFactories() { -// Map> copy = new HashMap<>(); -// for (var entry : ModMenu.screen.entrySet()) { -// copy.put(entry.getKey(), (parent) -> entry.getValue().apply(parent)); -// } -// return copy; -// } -// -// @Override -// public ConfigScreenFactory getModConfigScreenFactory() { -// //return (parent) -> new TestScreen(parent, Component.literal("Hello Test")); -// return (parent) -> new MainScreen(parent); -// } -// -// -//} +import org.betterx.bclib.client.gui.modmenu.MainScreen; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + + +/** + * Internal class to hook into ModMenu, you should not need to use this class. If you want to register a + * ModMenu Screen for a Mod using BCLib, use {@link ModMenu#addModMenuScreen(String, Function)} + */ +public class ModMenuEntryPoint implements ModMenuApi { + @Override + public Map> getProvidedConfigScreenFactories() { + Map> copy = new HashMap<>(); + for (var entry : ModMenu.screen.entrySet()) { + copy.put(entry.getKey(), (parent) -> entry.getValue().apply(parent)); + } + return copy; + } + + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return (parent) -> new MainScreen(parent); + } + + +} diff --git a/src/main/java/org/betterx/bclib/integration/modmenu/ModMenuIntegration.java b/src/main/java/org/betterx/bclib/integration/modmenu/ModMenuIntegration.java deleted file mode 100644 index e7df0a70..00000000 --- a/src/main/java/org/betterx/bclib/integration/modmenu/ModMenuIntegration.java +++ /dev/null @@ -1,184 +0,0 @@ -package org.betterx.bclib.integration.modmenu; - -//import org.betterx.bclib.integration.modmenu.ModMenuIntegration.ModMenuScreenFactory; -// -//import net.minecraft.client.gui.screens.Screen; -// -//import com.google.common.collect.ImmutableMap; -// -//import java.lang.reflect.InvocationHandler; -//import java.lang.reflect.Method; -//import java.lang.reflect.Proxy; -//import java.util.Map; -// -//@Deprecated -//class ModMenuScreenFactoryImpl { -// record ScreenFactoryInvocationHandler(ModMenuScreenFactory act) implements InvocationHandler { -// @Override -// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { -//// return switch (method.getName()) { -//// case "toString" -> ""; -//// case "equals" -> false; -//// case "hashCode" -> 0; -//// default -> act.create((Screen) args[0]); -//// }; -// return null; -// } -// } -// -// public static ModMenuScreenFactory create(ModMenuScreenFactory act) { -// Class iConfigScreenFactory = null; -// try { -// iConfigScreenFactory = Class.forName("com.terraformersmc.modmenu.api.ConfigScreenFactory"); -// } catch (ClassNotFoundException e) { -// e.printStackTrace(); -// return null; -// } -// -// Object o = Proxy.newProxyInstance( -// ModMenuIntegration.class.getClassLoader(), -// new Class[]{iConfigScreenFactory, ModMenuScreenFactory.class}, -// new ScreenFactoryInvocationHandler(act) -// ); -// -// return (ModMenuScreenFactory) o; -// } -//} -// -//@Deprecated -///** -// * Integration, to provide a custom Screen for ModMenu. -// *

-// * This integration allows you to use ModMenu without adding a dependency to your project. If the -// * Mod is installed on the Client, and the correct ModMenu-EntryPoint is registered in your fabric.mod.json -// * the screen will show up. -// *

-// * You only need to subclass this class, and initialize a static Field of Type {@link ModMenuApi} using -// * the {@link #createEntrypoint(ModMenuIntegration)}-Method. -// *

-// * Example: -// *

{@code public class ModMenu extends ModMenuIntegration {
-// *	 public static final ModMenuApiMarker entrypointObject = createEntrypoint(new EntryPoint());
-// *
-// * 		public EntryPoint() {
-// * 			super(GridScreen::new);
-// *      }
-// * }}
-// * You'd also need to add the ModMenu-Entrypoint to your fabric.mod.json: -// *
"entrypoints": {
-// * 		...
-// *	 "modmenu": [ "your.mod.ModMenu::entrypointObject" ]
-// * }
-// */ -//public abstract class ModMenuIntegration { -// /** -// * Creates a new EntryPoint Object that is accepted by ModMenu -// * -// * @param target The delegate Object that will receive calls from ModMenu -// * @return A Proxy that conforms to the ModMenu spec -// */ -//// public static ModMenuApi createEntrypoint(ModMenuIntegration target) { -//// Class iModMenuAPI; -//// //Class iModMenuAPIMarker = null; -//// try { -//// iModMenuAPI = Class.forName("com.terraformersmc.modmenu.api.ModMenuApi"); -//// //iModMenuAPIMarker = Class.forName("com.terraformersmc.modmenu.util.ModMenuApiMarker"); -//// } catch (ClassNotFoundException e) { -//// e.printStackTrace(); -//// return null; -//// } -//// -//// Object o = Proxy.newProxyInstance( -//// ModMenuIntegration.class.getClassLoader(), -//// new Class[]{iModMenuAPI}, -//// new BCLibModMenuInvocationHandler(target) -//// ); -//// -//// return (ModMenuApi) o; -//// } -// -// /** -// * The factory passed to {@link #ModMenuIntegration(ModMenuScreenFactory)} -// */ -// protected final ModMenuScreenFactory screenFactory; -// -// /** -// * Create a new ModMenu delegate -// * -// * @param screenFactory A Factory. The Factory receives the currently visible {@code parent}-Screen -// * and must return a new Screen Object. -// */ -// public ModMenuIntegration(ModMenuScreenFactory screenFactory) { -// this.screenFactory = screenFactory; -// } -// -// /** -// * A Helper class to make a BCLib-Factory conform to the ModMenu-Factory Interface. -// * -// * @param factory A BCLib-Type Factory, ie. {@code GridScreen::new } -// * @return A ModMenu Factory for a Screen -// */ -// final protected ModMenuScreenFactory createFactory(ModMenuScreenFactory factory) { -// return ModMenuScreenFactoryImpl.create(factory); -// } -// -// /** -// * Used to construct a new config screen instance when your mod's -// * configuration button is selected on the mod menu screen. The -// * screen instance parameter is the active mod menu screen. -// * (Text copied from ModMenu) -// * -// * @return A factory for constructing config screen instances. -// */ -// public ModMenuScreenFactory getModConfigScreenFactory() { -// return createFactory(screenFactory); -// } -// -// /** -// * Used to provide config screen factories for other mods. This takes second -// * priority to a mod's own config screen factory provider. For example, if -// * mod `xyz` supplies a config screen factory, mod `abc` providing a config -// * screen to `xyz` will be pointless, as the one provided by `xyz` will be -// * used. -// *

-// * This method is NOT meant to be used to add a config screen factory to -// * your own mod. -// * (Text copied from ModMenu) -// * -// * @return a map of mod ids to screen factories. -// */ -// public Map getProvidedConfigScreenFactories() { -// return ImmutableMap.of(); -// } -// -// @Override -// public String toString() { -// return super.toString(); -// } -// -// /** -// * A Factory Interface for ModMenu-Screens -// *

-// * The Interface matches {@code com.terraformersmc.modmenu.api.ConfigScreenFactory} -// */ -// @FunctionalInterface -// public interface ModMenuScreenFactory/*extends ConfigScreenFactory*/ { -// S create(Screen parent); -// } -// -// record BCLibModMenuInvocationHandler(ModMenuIntegration target) implements InvocationHandler { -// @Override -// public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { -//// return switch (method.getName()) { -//// case "getModConfigScreenFactory" -> target.getModConfigScreenFactory(); -//// case "getProvidedConfigScreenFactories" -> target.getProvidedConfigScreenFactories(); -//// case "toString" -> target.toString(); -//// case "equals" -> target.equals(args[0]); -//// case "hashCode" -> target.hashCode(); -//// default -> null; -//// }; -// return null; -// } -// } -// -//} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 99012077..284c81f9 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -30,7 +30,7 @@ "modmenu": [ "org.betterx.bclib.integration.modmenu.ModMenuEntryPoint" ], - "emi": [ + "emi_": [ "org.betterx.bclib.integration.emi.EMIPlugin" ], "fabric-datagen": [ @@ -59,7 +59,7 @@ "curseforge": "https://www.curseforge.com/minecraft/mc-mods/bclib" } }, - "modmenu_": { + "modmenu": { "links": { "title.link.bclib.discord": "https://discord.gg/kYuATbYbKW" }