Skip to content

Commit

Permalink
Add registerConfig method to ModContainer (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhyces authored Mar 25, 2024
1 parent 1979b07 commit 76df451
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
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

0 comments on commit 76df451

Please sign in to comment.