Implement Auto Config Screen registration (Forge/ModMenu)
This commit is contained in:
@@ -39,4 +39,7 @@ public class ConfigController implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static HashMap<Object, FileWatcher> getMonitoredConfigs() {
|
||||||
|
return monitoredConfigs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,8 @@ public class ModuleConfig {
|
|||||||
|
|
||||||
private final transient String configName;
|
private final transient String configName;
|
||||||
|
|
||||||
|
private final transient String modId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the config
|
* Set up the config
|
||||||
*
|
*
|
||||||
@@ -36,6 +38,7 @@ public class ModuleConfig {
|
|||||||
File configDir = new File("config" + (subFolder.isEmpty() ? "" : File.separator + subFolder));
|
File configDir = new File("config" + (subFolder.isEmpty() ? "" : File.separator + subFolder));
|
||||||
configPath = new File(configDir + File.separator + configName + ".toml");
|
configPath = new File(configDir + File.separator + configName + ".toml");
|
||||||
networkID = modId + ":conf_" + configName.replace("-", "_");
|
networkID = modId + ":conf_" + configName.replace("-", "_");
|
||||||
|
this.modId = modId;
|
||||||
this.configName = configName;
|
this.configName = configName;
|
||||||
|
|
||||||
/* Check if the required directories exists, otherwise we create them */
|
/* Check if the required directories exists, otherwise we create them */
|
||||||
@@ -154,4 +157,12 @@ public class ModuleConfig {
|
|||||||
public String getConfigName() {
|
public String getConfigName() {
|
||||||
return configName;
|
return configName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the MODID of the Module the config is registered to
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getModId() {
|
||||||
|
return modId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,13 @@
|
|||||||
|
package me.hypherionmc.craterlib.common.config.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
* @date 06/08/2022
|
||||||
|
* Allows Modules to disable Automatic Config Screens
|
||||||
|
*/
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface NoConfigScreen {
|
||||||
|
}
|
@@ -14,6 +14,10 @@ dependencies {
|
|||||||
include 'me.hypherionmc.night-config:toml:3.6.5_custom'
|
include 'me.hypherionmc.night-config:toml:3.6.5_custom'
|
||||||
include 'me.hypherionmc.night-config:core:3.6.5_custom'
|
include 'me.hypherionmc.night-config:core:3.6.5_custom'
|
||||||
implementation project(":Common")
|
implementation project(":Common")
|
||||||
|
|
||||||
|
modApi("com.terraformersmc:modmenu:${mod_menu_version}") {
|
||||||
|
exclude(group: "net.fabricmc.fabric-api")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
|
@@ -0,0 +1,31 @@
|
|||||||
|
package me.hypherionmc.craterlib;
|
||||||
|
|
||||||
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
|
import me.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||||
|
import me.hypherionmc.craterlib.common.config.ConfigController;
|
||||||
|
import me.hypherionmc.craterlib.common.config.ModuleConfig;
|
||||||
|
import me.hypherionmc.craterlib.common.config.annotations.NoConfigScreen;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
* @date 06/08/2022
|
||||||
|
*/
|
||||||
|
public class CraterLibModMenuIntegration implements ModMenuApi {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, ConfigScreenFactory<?>> getProvidedConfigScreenFactories() {
|
||||||
|
Map<String, ConfigScreenFactory<?>> configScreens = new HashMap<>();
|
||||||
|
|
||||||
|
ConfigController.getMonitoredConfigs().forEach((conf, watcher) -> {
|
||||||
|
if (!conf.getClass().isAnnotationPresent(NoConfigScreen.class)) {
|
||||||
|
configScreens.put(((ModuleConfig) conf).getModId(), screen -> new CraterConfigScreen((ModuleConfig) conf, screen));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return configScreens;
|
||||||
|
}
|
||||||
|
}
|
@@ -24,6 +24,9 @@
|
|||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"me.hypherionmc.craterlib.client.CraterLibClientInitializer"
|
"me.hypherionmc.craterlib.client.CraterLibClientInitializer"
|
||||||
|
],
|
||||||
|
"modmenu": [
|
||||||
|
"me.hypherionmc.craterlib.CraterLibModMenuIntegration"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
@@ -0,0 +1,45 @@
|
|||||||
|
package me.hypherionmc.craterlib.mixin;
|
||||||
|
|
||||||
|
import me.hypherionmc.craterlib.client.gui.config.CraterConfigScreen;
|
||||||
|
import me.hypherionmc.craterlib.common.config.ConfigController;
|
||||||
|
import me.hypherionmc.craterlib.common.config.ModuleConfig;
|
||||||
|
import me.hypherionmc.craterlib.common.config.annotations.NoConfigScreen;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
|
import net.minecraftforge.client.ConfigScreenHandler;
|
||||||
|
import net.minecraftforge.forgespi.language.IModInfo;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HypherionSA
|
||||||
|
* @date 06/08/2022
|
||||||
|
*/
|
||||||
|
@Mixin(ConfigScreenHandler.class)
|
||||||
|
public class ConfigScreenHandlerMixin {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inject Auto Generated config Screens into forge
|
||||||
|
* @param selectedMod
|
||||||
|
* @param cir
|
||||||
|
*/
|
||||||
|
@Inject(at = @At("RETURN"), method = "getScreenFactoryFor", cancellable = true, remap = false)
|
||||||
|
private static void injectConfigScreen(IModInfo selectedMod, CallbackInfoReturnable<Optional<BiFunction<Minecraft, Screen, Screen>>> cir) {
|
||||||
|
ConfigController.getMonitoredConfigs().forEach((conf, watcher) -> {
|
||||||
|
if (!conf.getClass().isAnnotationPresent(NoConfigScreen.class)) {
|
||||||
|
ModuleConfig config = (ModuleConfig) conf;
|
||||||
|
if (config.getModId().equals(selectedMod.getModId())) {
|
||||||
|
cir.setReturnValue(
|
||||||
|
Optional.of((minecraft, screen) -> new CraterConfigScreen(config, screen))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -6,6 +6,7 @@
|
|||||||
"mixins": [
|
"mixins": [
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
|
"ConfigScreenHandlerMixin"
|
||||||
],
|
],
|
||||||
"server": [
|
"server": [
|
||||||
],
|
],
|
||||||
|
@@ -18,6 +18,7 @@ A library mod used by HypherionSA's mods. Mostly used by Hyper Lighting 2.
|
|||||||
* Various utilities for Blockstates, LANG, Math and Rendering
|
* Various utilities for Blockstates, LANG, Math and Rendering
|
||||||
* Cross Mod-Loader Events
|
* Cross Mod-Loader Events
|
||||||
* Cross Mod-Loader Config Screens (Based on [Cloth Config Lite](https://github.com/shedaniel/cloth-config-lite))
|
* Cross Mod-Loader Config Screens (Based on [Cloth Config Lite](https://github.com/shedaniel/cloth-config-lite))
|
||||||
|
* Automatic ModMenu and Forge Config screen registration
|
||||||
* TODO: Built in Cross Mod-Loader Network system
|
* TODO: Built in Cross Mod-Loader Network system
|
||||||
* TODO: Various GUI widgets and Utilities
|
* TODO: Various GUI widgets and Utilities
|
||||||
* TODO: Cross Mod-Loader Dynamic Lighting
|
* TODO: Cross Mod-Loader Dynamic Lighting
|
||||||
|
@@ -62,6 +62,10 @@ subprojects {
|
|||||||
name = 'Hypherion Maven'
|
name = 'Hypherion Maven'
|
||||||
url = 'https://maven.firstdarkdev.xyz/releases/'
|
url = 'https://maven.firstdarkdev.xyz/releases/'
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
name = "TerraformersMC Maven"
|
||||||
|
url = "https://maven.terraformersmc.com/releases"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@@ -26,3 +26,6 @@ mod_id=craterlib
|
|||||||
# Gradle
|
# Gradle
|
||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
mod_menu_version=4.0.5
|
||||||
|
Reference in New Issue
Block a user