Skip to content

Commit

Permalink
Move empty checks and deprecate old methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dhyces committed Mar 24, 2024
1 parent 2365efc commit 9472b4d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
26 changes: 26 additions & 0 deletions loader/src/main/java/net/neoforged/fml/ModContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,37 @@ 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));
}

Expand Down
22 changes: 8 additions & 14 deletions loader/src/main/java/net/neoforged/fml/ModLoadingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,19 @@ 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().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().registerConfig(type, spec, fileName);
}

Expand Down

0 comments on commit 9472b4d

Please sign in to comment.