Class ModConfigSpec

java.lang.Object
net.neoforged.neoforge.common.ModConfigSpec
All Implemented Interfaces:
IConfigSpec

public class ModConfigSpec extends Object implements IConfigSpec
  • Field Details

    • levelComments

      private final Map<List<String>,String> levelComments
      Stores the comments for intermediate levels.
    • levelTranslationKeys

      private final Map<List<String>,String> levelTranslationKeys
      Stores the translation keys for intermediate levels.
    • spec

      private final com.electronwill.nightconfig.core.UnmodifiableConfig spec
      Stores the ModConfigSpec.ValueSpecs, (ab)using the hierarchical structure of Config.
    • values

      private final com.electronwill.nightconfig.core.UnmodifiableConfig values
      Stores the ModConfigSpec.ConfigValues, (ab)using the hierarchical structure of Config.
    • loadedConfig

      @Nullable private @Nullable IConfigSpec.ILoadedConfig 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

      private ModConfigSpec(com.electronwill.nightconfig.core.UnmodifiableConfig spec, com.electronwill.nightconfig.core.UnmodifiableConfig values, Map<List<String>,String> levelComments, Map<List<String>,String> levelTranslationKeys)
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Description copied from interface: IConfigSpec
      Returns true if this spec is empty.
      Specified by:
      isEmpty in interface IConfigSpec
    • getLevelComment

      public String getLevelComment(List<String> path)
    • getLevelTranslationKey

      public String getLevelTranslationKey(List<String> path)
    • acceptConfig

      public void acceptConfig(@Nullable @Nullable IConfigSpec.ILoadedConfig config)
      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 to IConfigSpec.isCorrect(com.electronwill.nightconfig.core.UnmodifiableCommentedConfig).
      Specified by:
      acceptConfig in interface IConfigSpec
    • validateSpec

      public void validateSpec(ModConfig config)
      Description copied from interface: IConfigSpec
      Validate this specification in the context of the given config.
      Specified by:
      validateSpec in interface IConfigSpec
      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

      @Internal public void resetCaches(ModConfigSpec.RestartType restartType)
    • 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 returns false, a backup is made (except for initial creation) then the config is fed through IConfigSpec.correct(com.electronwill.nightconfig.core.CommentedConfig).
      Specified by:
      isCorrect in interface IConfigSpec
    • correct

      public void correct(com.electronwill.nightconfig.core.CommentedConfig config)
      Description copied from interface: IConfigSpec
      Corrects a config. Only called if IConfigSpec.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 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 interface IConfigSpec
    • 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 to CommentedConfig if dryRun is false and a modification needs to be made.
    • stringsMatchNormalizingNewLines

      private boolean stringsMatchNormalizingNewLines(@Nullable @Nullable String string1, @Nullable @Nullable String string2)
    • split

      private static List<String> split(String path)