Skip to content

Commit

Permalink
Add simple getter for configs by mod and the loaded configs (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Jul 28, 2024
1 parent 4665bb7 commit 11f1ec3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions loader/src/main/java/net/neoforged/fml/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions loader/src/main/java/net/neoforged/fml/config/ModConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
* Configs are registered via {@link ModContainer#registerConfig(ModConfig.Type, IConfigSpec)}.
*/
public final class ModConfigs {
public static List<ModConfig> getModConfigs(String modId) {
return Collections.unmodifiableList(ConfigTracker.INSTANCE.configsByMod.getOrDefault(modId, List.of()));
}

public static List<String> getConfigFileNames(String modId, ModConfig.Type type) {
var config = ConfigTracker.INSTANCE.configsByMod.getOrDefault(modId, List.of());
synchronized (config) { // Synchronized list: requires explicit synchronization for stream
Expand Down

0 comments on commit 11f1ec3

Please sign in to comment.