Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple getter for configs by mod and the loaded configs #185

Merged
merged 3 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading