From 1c17943044ac41dccfc9e631cf73f37f45a5068c Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 18 Jul 2024 23:32:56 +0200 Subject: [PATCH 1/3] Add simple getter for configs by mod --- loader/src/main/java/net/neoforged/fml/config/ModConfigs.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/loader/src/main/java/net/neoforged/fml/config/ModConfigs.java b/loader/src/main/java/net/neoforged/fml/config/ModConfigs.java index 30b40c49c..8d7154f14 100644 --- a/loader/src/main/java/net/neoforged/fml/config/ModConfigs.java +++ b/loader/src/main/java/net/neoforged/fml/config/ModConfigs.java @@ -17,6 +17,10 @@ * Configs are registered via {@link ModContainer#registerConfig(ModConfig.Type, IConfigSpec)}. */ public final class ModConfigs { + public static List getModConfigs(String modId) { + return List.copyOf(ConfigTracker.INSTANCE.configsByMod.getOrDefault(modId, List.of())); + } + public static List getConfigFileNames(String modId, ModConfig.Type type) { var config = ConfigTracker.INSTANCE.configsByMod.getOrDefault(modId, List.of()); synchronized (config) { // Synchronized list: requires explicit synchronization for stream From 6083ed955251e70d89028ddd5c52a30f6a5c49a4 Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Wed, 24 Jul 2024 22:10:16 +0200 Subject: [PATCH 2/3] Add a getter for the loaded config --- .../main/java/net/neoforged/fml/config/ModConfig.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/loader/src/main/java/net/neoforged/fml/config/ModConfig.java b/loader/src/main/java/net/neoforged/fml/config/ModConfig.java index bcb08c051..5e92ef7e4 100644 --- a/loader/src/main/java/net/neoforged/fml/config/ModConfig.java +++ b/loader/src/main/java/net/neoforged/fml/config/ModConfig.java @@ -5,6 +5,7 @@ package net.neoforged.fml.config; +import com.electronwill.nightconfig.core.CommentedConfig; import java.nio.file.Path; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; @@ -51,6 +52,15 @@ public String getModId() { return container.getModId(); } + /** + * Retrieve the currently loaded config, for direct manipulation of the underlying {@link CommentedConfig}. + * Note that the config will change on reloads, and will be {@code null} when the config is not loaded. + */ + @Nullable + public IConfigSpec.ILoadedConfig getLoadedConfig() { + return loadedConfig; + } + // TODO: remove from public API? public Path getFullPath() { if (this.loadedConfig != null && loadedConfig.path() != null) { From 7a74eaa59419d67ed6ea7f2b75a4d68e179a169a Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Sun, 28 Jul 2024 19:33:14 +0200 Subject: [PATCH 3/3] unmodifiableList actually --- loader/src/main/java/net/neoforged/fml/config/ModConfigs.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loader/src/main/java/net/neoforged/fml/config/ModConfigs.java b/loader/src/main/java/net/neoforged/fml/config/ModConfigs.java index 8d7154f14..f0d7afffd 100644 --- a/loader/src/main/java/net/neoforged/fml/config/ModConfigs.java +++ b/loader/src/main/java/net/neoforged/fml/config/ModConfigs.java @@ -18,7 +18,7 @@ */ public final class ModConfigs { public static List getModConfigs(String modId) { - return List.copyOf(ConfigTracker.INSTANCE.configsByMod.getOrDefault(modId, List.of())); + return Collections.unmodifiableList(ConfigTracker.INSTANCE.configsByMod.getOrDefault(modId, List.of())); } public static List getConfigFileNames(String modId, ModConfig.Type type) {