Fixed ModMenu Integration

This commit is contained in:
Frank 2021-12-13 16:10:13 +01:00
parent 3dc1470085
commit ff49e1325c
5 changed files with 88 additions and 20 deletions

View file

@ -0,0 +1,37 @@
/**
* MIT License
*
* Copyright (c) 2018-2020 Prospector
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.terraformersmc.modmenu.api;
import net.minecraft.client.gui.screens.Screen;
// This File was included from TerraformersMC/ModMenu
// to enable a ModMenu-Integration without having to
// compile against the actual plugin in an attempt
// to reduce dependencies
@FunctionalInterface
public interface ConfigScreenFactory<S extends Screen> {
S create(Screen parent);
}

View file

@ -0,0 +1,43 @@
/**
* MIT License
*
* Copyright (c) 2018-2020 Prospector
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.terraformersmc.modmenu.api;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
// This File was included from TerraformersMC/ModMenu
// to enable a ModMenu-Integration without having to
// compile against the actual plugin in an attempt
// to reduce dependencies
public interface ModMenuApi {
default ConfigScreenFactory<?> getModConfigScreenFactory() {
return screen -> null;
}
default Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
return ImmutableMap.of();
}
}

View file

@ -1,11 +0,0 @@
package com.terraformersmc.modmenu.util;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
//This File was included from TerraformersMC/ModMenu
// to enable a ModMenu-Integration without having to
// compile against the actual plugin
@Environment(EnvType.CLIENT)
public interface ModMenuApiMarker {}

View file

@ -1,10 +1,10 @@
package ru.bclib.gui.modmenu;
import com.terraformersmc.modmenu.util.ModMenuApiMarker;
import com.terraformersmc.modmenu.api.ModMenuApi;
import ru.bclib.integration.ModMenuIntegration;
public class EntryPoint extends ModMenuIntegration {
public static final ModMenuApiMarker entrypointObject = createEntrypoint(new EntryPoint());
public static final ModMenuApi entrypointObject = (ModMenuApi) createEntrypoint(new EntryPoint());
public EntryPoint() {
super(MainScreen::new);

View file

@ -1,7 +1,8 @@
package ru.bclib.integration;
import com.google.common.collect.ImmutableMap;
import com.terraformersmc.modmenu.util.ModMenuApiMarker;
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;
@ -49,7 +50,7 @@ class ModMenuScreenFactoryImpl {
* Mod is installed on the Client, and the correct ModMenu-EntryPoint is registered in your <i>fabric.mod.json</i>
* the screen will show up.
* <p>
* You only need to subclass this class, and initialize a static Field of Type {@link ModMenuApiMarker} using
* You only need to subclass this class, and initialize a static Field of Type {@link ModMenuApi} using
* the {@link #createEntrypoint(ModMenuIntegration)}-Method.
* <p>
* Example:
@ -72,7 +73,7 @@ public abstract class ModMenuIntegration {
* @param target The delegate Object that will receive calls from ModMenu
* @return A Proxy that conforms to the ModMenu spec
*/
public static ModMenuApiMarker createEntrypoint(ModMenuIntegration target) {
public static ModMenuApi createEntrypoint(ModMenuIntegration target) {
Class<?> iModMenuAPI;
//Class<?> iModMenuAPIMarker = null;
try {
@ -89,7 +90,7 @@ public abstract class ModMenuIntegration {
new Class[] {iModMenuAPI},
new BCLibModMenuInvocationHandler(target));
return (ModMenuApiMarker)o;
return (ModMenuApi) o;
}
/**
@ -156,9 +157,7 @@ public abstract class ModMenuIntegration {
* The Interface matches {@code com.terraformersmc.modmenu.api.ConfigScreenFactory}
*/
@FunctionalInterface
public interface ModMenuScreenFactory {
Screen create(Screen parent);
}
public interface ModMenuScreenFactory extends ConfigScreenFactory{}
record BCLibModMenuInvocationHandler(ModMenuIntegration target) implements InvocationHandler {
@Override