diff --git a/gradle.properties b/gradle.properties index 9f455435d..a9f24e150 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,12 +21,12 @@ mcp_version = 20240102.171137 special_source = net.md-5:SpecialSource:1.9.0 special_source_mcp = net.md-5:SpecialSource:1.8.5 binary_patcher = net.minecraftforge:binarypatcher:1.1.1:fatjar -installer_tools_version = 1.3.0 +installer_tools_version = 1.4.1 # Libraries asm_version = 9.6 asm_deprecated = 7.1 -bouncepad_version = 0.4.37-cursed +bouncepad_version = 0.4.38-cursed lwjgl_version = 3.3.4-27-CLEANROOM # Sets default memory used for Gradle commands. Can be overridden by user or command line properties. diff --git a/src/main/java/com/cleanroommc/configanytime/ConfigAnytime.java b/src/main/java/com/cleanroommc/configanytime/ConfigAnytime.java new file mode 100644 index 000000000..895dc6074 --- /dev/null +++ b/src/main/java/com/cleanroommc/configanytime/ConfigAnytime.java @@ -0,0 +1,15 @@ +package com.cleanroommc.configanytime; + +import net.minecraftforge.common.config.Config; +import net.minecraftforge.common.config.ConfigManager; + +@Deprecated +public class ConfigAnytime { + /** + * A wrapper of {@link ConfigManager#register(Class)}, created for compatibility. + * @param configClass configuration class that is annotated with {@link Config} + */ + public static void register(Class configClass) { + ConfigManager.register(configClass); + } +} diff --git a/src/main/java/net/minecraftforge/common/config/ConfigManager.java b/src/main/java/net/minecraftforge/common/config/ConfigManager.java index a4f7b0363..8c2069642 100644 --- a/src/main/java/net/minecraftforge/common/config/ConfigManager.java +++ b/src/main/java/net/minecraftforge/common/config/ConfigManager.java @@ -33,6 +33,7 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Sets; +import net.minecraft.launchwrapper.Launch; import net.minecraftforge.common.config.Config.Comment; import net.minecraftforge.common.config.Config.LangKey; import net.minecraftforge.common.config.Config.Name; @@ -377,4 +378,32 @@ private static String getName(Field f) return f.getName(); } + /** + * Register configuration class that is annotated with {@link Config} here for it to be processed immediately with saving and loading supported. + * Preferably call this method in a static init block at the very end of your configuration class. + * @param configClass configuration class that is annotated with {@link Config} + */ + public static void register(Class configClass) { + if (Launch.classLoader.isClassLoaded("net.minecraftforge.fml.common.Loader")) { + if (Loader.instance().hasReachedState(LoaderState.PREINITIALIZATION)) { + throw new RuntimeException("Please call this method before pre-init!"); + } + } + Config config = configClass.getAnnotation(Config.class); + String modId = config.modid(); + Set> modConfigClasses = MOD_CONFIG_CLASSES.computeIfAbsent(modId, k -> Sets.newHashSet()); + modConfigClasses.add(configClass); + File configDir = new File(Launch.minecraftHome, "config"); + File configFile = new File(configDir, config.name() + ".cfg"); + Configuration cfg = CONFIGS.get(configFile.getAbsolutePath()); + if (cfg == null) { + cfg = new Configuration(configFile); + cfg.load(); + CONFIGS.put(configFile.getAbsolutePath(), cfg); + } + sync(cfg, configClass, modId, config.category(), true, null); + + cfg.save(); + } + } diff --git a/src/main/java/net/minecraftforge/fml/common/ConfigAnytimeContainer.java b/src/main/java/net/minecraftforge/fml/common/ConfigAnytimeContainer.java new file mode 100644 index 000000000..5a9f4a6b3 --- /dev/null +++ b/src/main/java/net/minecraftforge/fml/common/ConfigAnytimeContainer.java @@ -0,0 +1,21 @@ +package net.minecraftforge.fml.common; + +import com.google.common.eventbus.EventBus; + +public class ConfigAnytimeContainer extends DummyModContainer{ + public ConfigAnytimeContainer() { + super(new ModMetadata()); + ModMetadata meta = this.getMetadata(); + meta.modId = "configanytime"; + meta.name = "ConfigAnytime"; + meta.description = "Allows Forge configurations to be setup at any point in time."; + meta.version = "2.0"; + meta.authorList.add("Rongmario"); + } + + @Override + public boolean registerBus(EventBus bus, LoadController controller) { + bus.register(this); + return true; + } +} diff --git a/src/main/java/net/minecraftforge/fml/common/Loader.java b/src/main/java/net/minecraftforge/fml/common/Loader.java index 6bb30c25d..2a52fd015 100644 --- a/src/main/java/net/minecraftforge/fml/common/Loader.java +++ b/src/main/java/net/minecraftforge/fml/common/Loader.java @@ -371,6 +371,7 @@ private ModDiscoverer identifyMods(List additionalContainers) mods.add(minecraft); // Add in the MCP mod container mods.add(new InjectedModContainer(mcp,new File("minecraft.jar"))); + mods.add(new ConfigAnytimeContainer()); for (String cont : injectedContainers) { ModContainer mc; diff --git a/src/main/java/net/minecraftforge/fml/common/MixinContainer.java b/src/main/java/net/minecraftforge/fml/common/MixinContainer.java index c25f23169..ed4657909 100644 --- a/src/main/java/net/minecraftforge/fml/common/MixinContainer.java +++ b/src/main/java/net/minecraftforge/fml/common/MixinContainer.java @@ -9,8 +9,7 @@ public MixinContainer() { meta.modId = "mixinbooter"; meta.name = "MixinBooter"; meta.description = "A Mixin library and loader."; - meta.version = "100.0"; - meta.logoFile = "/icon.png"; + meta.version = "10.0"; meta.authorList.add("Rongmario"); }