Added ModMenu as build dependency and refactored Integration
This commit is contained in:
parent
3e18eb839f
commit
08e400ae20
11 changed files with 80 additions and 90 deletions
|
@ -1,4 +1,4 @@
|
|||
package ru.bclib.integration;
|
||||
package ru.bclib.integration.modmenu;
|
||||
|
||||
import net.fabricmc.fabric.api.tag.TagFactory;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
29
src/main/java/ru/bclib/integration/modmenu/ModMenu.java
Normal file
29
src/main/java/ru/bclib/integration/modmenu/ModMenu.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package ru.bclib.integration.modmenu;
|
||||
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Integration, to provide a custom Screen for ModMenu.
|
||||
* <p>
|
||||
* This integration allows you to use ModMenu without adding a dependency to your project. If the
|
||||
* Mod is installed on the Client.
|
||||
* <p>
|
||||
* You can add a screen for your mod by calling {@link #addModMenuScreen(String, Function)}
|
||||
*/
|
||||
public class ModMenu {
|
||||
static final Map<String, Function<Screen, Screen>> screen = new HashMap<>();
|
||||
|
||||
/**
|
||||
* registers a ModMenu entrypoint for another Mod. For Example {@code addModMenuScreen("myMod", (parent)->new Screen(parent));}
|
||||
* @param modID The ID of your Mod
|
||||
* @param scr a function that takes a parent {@link Screen} and provides the main Screen you want
|
||||
* to show with ModMenu for your Mod.
|
||||
*/
|
||||
public static void addModMenuScreen(String modID, Function<Screen, Screen> scr) {
|
||||
screen.put(modID, scr);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package ru.bclib.integration.modmenu;
|
||||
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
import ru.bclib.gui.modmenu.MainScreen;
|
||||
|
||||
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<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
|
||||
Map<String, ConfigScreenFactory<?>> 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,16 +1,19 @@
|
|||
package ru.bclib.integration;
|
||||
package ru.bclib.integration.modmenu;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import ru.bclib.integration.ModMenuIntegration.ModMenuScreenFactory;
|
||||
import ru.bclib.integration.modmenu.ModMenuIntegration.ModMenuScreenFactory;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Deprecated
|
||||
class ModMenuScreenFactoryImpl {
|
||||
record ScreenFactoryInvocationHandler(ModMenuScreenFactory act) implements InvocationHandler {
|
||||
@Override
|
||||
|
@ -43,6 +46,7 @@ class ModMenuScreenFactoryImpl {
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
/**
|
||||
* Integration, to provide a custom Screen for ModMenu.
|
||||
* <p>
|
||||
|
@ -172,4 +176,5 @@ public abstract class ModMenuIntegration {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue