Package net.neoforged.neoforge.common
Class ModConfigSpec
java.lang.Object
net.neoforged.neoforge.common.ModConfigSpec
- All Implemented Interfaces:
IConfigSpec
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classprivate static classstatic classstatic classstatic classModConfigSpec.EnumValue<T extends Enum<T>>static classstatic classstatic classstatic classModConfigSpec.Range<V extends Comparable<? super V>>static enumUsed to prevent cached config values from being updated unless the game or the world is restarted.static classNested classes/interfaces inherited from interface net.neoforged.fml.config.IConfigSpec
IConfigSpec.ILoadedConfig -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Joinerprivate static final SplitterStores the comments for intermediate levels.Stores the translation keys for intermediate levels.private static final Joinerprivate @Nullable IConfigSpec.ILoadedConfigThe currently loaded config values.private static final org.apache.logging.log4j.Loggerprivate final com.electronwill.nightconfig.core.UnmodifiableConfigStores theModConfigSpec.ValueSpecs, (ab)using the hierarchical structure ofConfig.private final com.electronwill.nightconfig.core.UnmodifiableConfigStores theModConfigSpec.ConfigValues, (ab)using the hierarchical structure ofConfig. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidacceptConfig(@Nullable IConfigSpec.ILoadedConfig config) Updates the spec's data to a config.voidvoidcorrect(com.electronwill.nightconfig.core.CommentedConfig config) Corrects a config.intcorrect(com.electronwill.nightconfig.core.CommentedConfig config, com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener listener) intcorrect(com.electronwill.nightconfig.core.CommentedConfig config, com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener listener, @Nullable com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener commentListener) private intcorrect(com.electronwill.nightconfig.core.UnmodifiableConfig spec, com.electronwill.nightconfig.core.UnmodifiableCommentedConfig config, LinkedList<String> parentPath, List<String> parentPathUnmodifiable, com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener listener, @Nullable com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener commentListener, boolean dryRun) configwill be downcast toCommentedConfigifdryRunisfalseand a modification needs to be made.private voidforEachValue(Iterable<Object> configValues, Consumer<ModConfigSpec.ConfigValue<?>> consumer) getLevelComment(List<String> path) getLevelTranslationKey(List<String> path) com.electronwill.nightconfig.core.UnmodifiableConfiggetSpec()com.electronwill.nightconfig.core.UnmodifiableConfigbooleanisCorrect(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig config) Checks that a config is correct.booleanisEmpty()Returnstrueif this spec is empty.booleanisLoaded()voidresetCaches(ModConfigSpec.RestartType restartType) voidsave()Saves the current config values to the config file, and fires the config reloading event.private booleanstringsMatchNormalizingNewLines(@Nullable String string1, @Nullable String string2) voidvalidateSpec(ModConfig config) Validate this specification in the context of the givenconfig.
-
Field Details
-
levelComments
Stores the comments for intermediate levels. -
levelTranslationKeys
Stores the translation keys for intermediate levels. -
spec
private final com.electronwill.nightconfig.core.UnmodifiableConfig specStores theModConfigSpec.ValueSpecs, (ab)using the hierarchical structure ofConfig. -
values
private final com.electronwill.nightconfig.core.UnmodifiableConfig valuesStores theModConfigSpec.ConfigValues, (ab)using the hierarchical structure ofConfig. -
loadedConfig
The currently loaded config values. -
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER -
LINE_JOINER
-
DOT_JOINER
-
DOT_SPLITTER
-
-
Constructor Details
-
ModConfigSpec
-
-
Method Details
-
isEmpty
public boolean isEmpty()Description copied from interface:IConfigSpecReturnstrueif this spec is empty.- Specified by:
isEmptyin interfaceIConfigSpec
-
getLevelComment
-
getLevelTranslationKey
-
acceptConfig
Description copied from interface:IConfigSpecUpdates the spec's data to a config. This is called on loading and on reloading. The config is guaranteed to be valid according toIConfigSpec.isCorrect(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig).- Specified by:
acceptConfigin interfaceIConfigSpec
-
validateSpec
Description copied from interface:IConfigSpecValidate this specification in the context of the givenconfig.- Specified by:
validateSpecin interfaceIConfigSpec- Parameters:
config- the configuration this spec is used by
-
isLoaded
public boolean isLoaded() -
getSpec
public com.electronwill.nightconfig.core.UnmodifiableConfig getSpec() -
getValues
public com.electronwill.nightconfig.core.UnmodifiableConfig getValues() -
forEachValue
private void forEachValue(Iterable<Object> configValues, Consumer<ModConfigSpec.ConfigValue<?>> consumer) -
afterReload
public void afterReload() -
resetCaches
-
save
public void save()Saves the current config values to the config file, and fires the config reloading event. -
isCorrect
public boolean isCorrect(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig config) Description copied from interface:IConfigSpecChecks that a config is correct. If this function returnsfalse, a backup is made (except for initial creation) then the config is fed throughIConfigSpec.correct(com.electronwill.nightconfig.core.CommentedConfig).- Specified by:
isCorrectin interfaceIConfigSpec
-
correct
public void correct(com.electronwill.nightconfig.core.CommentedConfig config) Description copied from interface:IConfigSpecCorrects a config. Only called ifIConfigSpec.isCorrect(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig)returnedfalse.This can be used to fix broken entries, add back missing entries or comments, etc... The returned config will be saved to disk.
This function is also used to construct the default instance of a config, by passing in an empty config.
The config should not be loaded into the spec yet. A call to
IConfigSpec.acceptConfig(net.neoforged.fml.config.IConfigSpec.ILoadedConfig)will be made for that.The config should not be saved yet. FML will take care of that after this method.
- Specified by:
correctin interfaceIConfigSpec
-
correct
public int correct(com.electronwill.nightconfig.core.CommentedConfig config, com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener listener) -
correct
public int correct(com.electronwill.nightconfig.core.CommentedConfig config, com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener listener, @Nullable com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener commentListener) -
correct
private int correct(com.electronwill.nightconfig.core.UnmodifiableConfig spec, com.electronwill.nightconfig.core.UnmodifiableCommentedConfig config, LinkedList<String> parentPath, List<String> parentPathUnmodifiable, com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener listener, @Nullable com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener commentListener, boolean dryRun) configwill be downcast toCommentedConfigifdryRunisfalseand a modification needs to be made. -
stringsMatchNormalizingNewLines
-
split
-