Interface IConfigSpec
- All Known Implementing Classes:
ModConfigSpec
CommentedConfig
s from NightConfig.
NeoForge provides ModConfigSpec
for the most common cases.
Thread-safety
The Config
objects themselves are thread-safe, but mod config code should not be assumed to be thread-safe in general.
FML will guard event dispatches behind a lock when necessary.
A spec can safely mutate Config
objects, but should let FML fire events and saving the file by calling IConfigSpec.ILoadedConfig.save()
.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptConfig
(@Nullable IConfigSpec.ILoadedConfig config) Updates the spec's data to a config.void
correct
(com.electronwill.nightconfig.core.CommentedConfig config) Corrects a config.boolean
isCorrect
(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig config) Checks that a config is correct.boolean
isEmpty()
Returnstrue
if this spec is empty.void
validateSpec
(ModConfig config) Validate this specification in the context of the givenconfig
.
-
Method Details
-
isEmpty
boolean isEmpty()Returnstrue
if this spec is empty. -
validateSpec
Validate this specification in the context of the givenconfig
.- Parameters:
config
- the configuration this spec is used by
-
isCorrect
boolean isCorrect(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig config) Checks that a config is correct. If this function returnsfalse
, a backup is made (except for initial creation) then the config is fed throughcorrect(com.electronwill.nightconfig.core.CommentedConfig)
. -
correct
void correct(com.electronwill.nightconfig.core.CommentedConfig config) Corrects a config. Only called ifisCorrect(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
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.
-
acceptConfig
Updates the spec's data to a config. This is called on loading and on reloading. The config is guaranteed to be valid according toisCorrect(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig)
.
-