Interface IConfigSpec

All Known Implementing Classes:
ModConfigSpec

public interface IConfigSpec
A config spec is responsible for interpreting (loading, correcting) raw CommentedConfigs 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
    Modifier and Type
    Interface
    Description
    static interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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
    Returns true if this spec is empty.
    void
    Validate this specification in the context of the given config.
  • Method Details

    • isEmpty

      boolean isEmpty()
      Returns true if this spec is empty.
    • validateSpec

      void validateSpec(ModConfig config)
      Validate this specification in the context of the given config.
      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 returns false, a backup is made (except for initial creation) then the config is fed through correct(com.electronwill.nightconfig.core.CommentedConfig).
    • correct

      void correct(com.electronwill.nightconfig.core.CommentedConfig config)
      Corrects a config. Only called if isCorrect(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig) returned false.

      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

      void acceptConfig(@Nullable @Nullable IConfigSpec.ILoadedConfig config)
      Updates the spec's data to a config. This is called on loading and on reloading. The config is guaranteed to be valid according to isCorrect(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig).