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 registerConfig method to ModContainer #99

Merged
merged 3 commits into from
Mar 25, 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
35 changes: 35 additions & 0 deletions loader/src/main/java/net/neoforged/fml/ModContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.neoforged.bus.api.Event;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.config.IConfigSpec;
import net.neoforged.fml.config.ModConfig;
import net.neoforged.fml.event.IModBusEvent;
import net.neoforged.fml.loading.progress.ProgressMeter;
Expand Down Expand Up @@ -155,6 +156,40 @@ public void addConfig(final ModConfig modConfig) {
configs.put(modConfig.getType(), modConfig);
}

/**
* Adds a {@link ModConfig} with the given type and spec. An empty config spec will be ignored and a debug line will
* be logged.
* @param type The type of config
* @param configSpec A config spec
*/
public void registerConfig(ModConfig.Type type, IConfigSpec<?> configSpec) {
if (configSpec.isEmpty())
{
// This handles the case where a mod tries to register a config, without any options configured inside it.
LOGGER.debug("Attempted to register an empty config for type {} on mod {}", type, modId);
return;
}

addConfig(new ModConfig(type, configSpec, this));
}

/**
* Adds a {@link ModConfig} with the given type, spec, and overridden file name. An empty config spec will be
* ignored and a debug line will be logged.
* @param type The type of config
* @param configSpec A config spec
*/
public void registerConfig(ModConfig.Type type, IConfigSpec<?> configSpec, String fileName) {
if (configSpec.isEmpty())
{
// This handles the case where a mod tries to register a config, without any options configured inside it.
LOGGER.debug("Attempted to register an empty config for type {} on mod {} using file name {}", type, modId, fileName);
return;
}

addConfig(new ModConfig(type, configSpec, this, fileName));
}

/**
* Does this mod match the supplied mod?
*
Expand Down
26 changes: 10 additions & 16 deletions loader/src/main/java/net/neoforged/fml/ModLoadingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,20 @@ public <T extends Record & IExtensionPoint<T>> void registerExtensionPoint(Class
getActiveContainer().registerExtensionPoint(point, extension);
}

/**
* @deprecated Use the corresponding method {@link ModContainer#registerConfig(ModConfig.Type, IConfigSpec)}
*/
@Deprecated(forRemoval = true)
public void registerConfig(ModConfig.Type type, IConfigSpec<?> spec) {
if (spec.isEmpty())
{
// This handles the case where a mod tries to register a config, without any options configured inside it.
LOGGER.debug("Attempted to register an empty config for type {} on mod {}", type, getActiveContainer().getModId());
return;
}

getActiveContainer().addConfig(new ModConfig(type, spec, getActiveContainer()));
getActiveContainer().registerConfig(type, spec);
}

/**
* @deprecated Use the corresponding method {@link ModContainer#registerConfig(ModConfig.Type, IConfigSpec, String)}
*/
@Deprecated(forRemoval = true)
public void registerConfig(ModConfig.Type type, IConfigSpec<?> spec, String fileName) {
if (spec.isEmpty())
{
// This handles the case where a mod tries to register a config, without any options configured inside it.
LOGGER.debug("Attempted to register an empty config for type {} on mod {} using file name {}", type, getActiveContainer().getModId(), fileName);
return;
}

getActiveContainer().addConfig(new ModConfig(type, spec, getActiveContainer(), fileName));
getActiveContainer().registerConfig(type, spec, fileName);
}


Expand Down
Loading