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 class
static class
private static class
static class
static class
static class
ModConfigSpec.EnumValue<T extends Enum<T>>
static class
static class
static class
static class
ModConfigSpec.Range<V extends Comparable<? super V>>
static enum
Used to prevent cached config values from being updated unless the game or the world is restarted.static class
Nested classes/interfaces inherited from interface net.neoforged.fml.config.IConfigSpec
IConfigSpec.ILoadedConfig
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final com.google.common.base.Joiner
private static final com.google.common.base.Splitter
Stores the comments for intermediate levels.Stores the translation keys for intermediate levels.private static final com.google.common.base.Joiner
private @Nullable IConfigSpec.ILoadedConfig
The currently loaded config values.private static final org.apache.logging.log4j.Logger
private final com.electronwill.nightconfig.core.UnmodifiableConfig
Stores theModConfigSpec.ValueSpec
s, (ab)using the hierarchical structure ofConfig
.private final com.electronwill.nightconfig.core.UnmodifiableConfig
Stores theModConfigSpec.ConfigValue
s, (ab)using the hierarchical structure ofConfig
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptConfig
(@Nullable IConfigSpec.ILoadedConfig config) Updates the spec's data to a config.void
void
correct
(com.electronwill.nightconfig.core.CommentedConfig config) Corrects a config.int
correct
(com.electronwill.nightconfig.core.CommentedConfig config, com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener listener) int
correct
(com.electronwill.nightconfig.core.CommentedConfig config, com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener listener, @Nullable com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener commentListener) 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) config
will be downcast toCommentedConfig
ifdryRun
isfalse
and a modification needs to be made.private void
forEachValue
(Iterable<Object> configValues, Consumer<ModConfigSpec.ConfigValue<?>> consumer) getLevelComment
(List<String> path) getLevelTranslationKey
(List<String> path) com.electronwill.nightconfig.core.UnmodifiableConfig
getSpec()
com.electronwill.nightconfig.core.UnmodifiableConfig
boolean
isCorrect
(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig config) Checks that a config is correct.boolean
isEmpty()
Returnstrue
if this spec is empty.boolean
isLoaded()
void
resetCaches
(ModConfigSpec.RestartType restartType) void
save()
Saves the current config values to the config file, and fires the config reloading event.private boolean
stringsMatchNormalizingNewLines
(@Nullable String string1, @Nullable String string2) void
validateSpec
(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.ValueSpec
s, (ab)using the hierarchical structure ofConfig
. -
values
private final com.electronwill.nightconfig.core.UnmodifiableConfig valuesStores theModConfigSpec.ConfigValue
s, (ab)using the hierarchical structure ofConfig
. -
loadedConfig
The currently loaded config values. -
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER -
LINE_JOINER
private static final com.google.common.base.Joiner LINE_JOINER -
DOT_JOINER
private static final com.google.common.base.Joiner DOT_JOINER -
DOT_SPLITTER
private static final com.google.common.base.Splitter DOT_SPLITTER
-
-
Constructor Details
-
ModConfigSpec
-
-
Method Details
-
isEmpty
public boolean isEmpty()Description copied from interface:IConfigSpec
Returnstrue
if this spec is empty.- Specified by:
isEmpty
in interfaceIConfigSpec
-
getLevelComment
-
getLevelTranslationKey
-
acceptConfig
Description copied from interface:IConfigSpec
Updates 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:
acceptConfig
in interfaceIConfigSpec
-
validateSpec
Description copied from interface:IConfigSpec
Validate this specification in the context of the givenconfig
.- Specified by:
validateSpec
in 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:IConfigSpec
Checks 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:
isCorrect
in interfaceIConfigSpec
-
correct
public void correct(com.electronwill.nightconfig.core.CommentedConfig config) Description copied from interface:IConfigSpec
Corrects 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:
correct
in 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 @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 @Nullable com.electronwill.nightconfig.core.ConfigSpec.CorrectionListener commentListener, boolean dryRun) config
will be downcast toCommentedConfig
ifdryRun
isfalse
and a modification needs to be made. -
stringsMatchNormalizingNewLines
-
split
-