Added ModMenu as build dependency and refactored Integration

This commit is contained in:
Frank 2021-12-16 11:34:08 +01:00
parent 3e18eb839f
commit 08e400ae20
11 changed files with 80 additions and 90 deletions

View file

@ -16,11 +16,11 @@ group = project.maven_group
repositories {
maven { url "https://maven.dblsaiko.net/" }
maven { url "https://server.bbkr.space:8081/artifactory/libs-release/" }
maven { url "https://maven.fabricmc.net/" }
maven { url "https://maven.shedaniel.me/" }
maven { url 'https://maven.blamejared.com' }
maven { url 'https://jitpack.io' }
maven { url 'https://maven.terraformersmc.com/releases' }
}
loom {
@ -32,6 +32,7 @@ dependencies {
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
//useApi "vazkii.patchouli:Patchouli:1.16.4-${project.patchouli_version}"
}

View file

@ -16,4 +16,5 @@ maven_group = ru.bclib
archives_base_name = bclib
# Dependencies
patchouli_version = 50-FABRIC
patchouli_version = 50-FABRIC
modmenu_version=3.0.0

View file

@ -1,37 +0,0 @@
/**
* 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

@ -1,43 +0,0 @@
/**
* 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

@ -2,7 +2,7 @@ package ru.bclib.api;
import com.google.common.collect.Lists;
import net.fabricmc.loader.api.FabricLoader;
import ru.bclib.integration.ModIntegration;
import ru.bclib.integration.modmenu.ModIntegration;
import java.util.List;

View file

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

View file

@ -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;

View 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);
}
}

View file

@ -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);
}
}

View file

@ -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 {
};
}
}
}

View file

@ -26,7 +26,9 @@
"server": [
"ru.bclib.server.BCLibServer"
],
"modmenu": [ "ru.bclib.gui.modmenu.EntryPoint::entrypointObject" ]
"modmenu": [
"ru.bclib.integration.modmenu.ModMenuEntryPoint"
]
},
"accessWidener" : "bclib.accesswidener",
"mixins": [