Class ConfigFile

java.lang.Object
codechicken.lib.config.ConfigFile

public final class ConfigFile extends Object
Builder to parse a Config.

Each config begins with a root ConfigCategory which can then have nested ConfigCategory's, ConfigValue's and ConfigValueList's.

Created by covers1624 on 27/4/22.

  • Constructor Details

    • ConfigFile

      public ConfigFile(String rootName)
      Construct a new Config with the given rootName.

      The rootName is used when creating translation keys for a given tag. It is recommended that you use your ModID for this, or a ResourceLocation like string.

      Parameters:
      rootName - The root name for the returned config. Usually your ModID.
  • Method Details

    • path

      public ConfigFile path(Path path)
      Specifies the Path for this config file.

      Usually this will be Path.of("./config/mymod.cfg")

      This method will automatically detect the ConfigSerializer to use based on the File extension of the Path. // TODO document builtin supported formats.

      Parameters:
      path - The path to the config file.
      Returns:
      The same ConfigFile.
    • serializer

      public ConfigFile serializer(ConfigSerializer serializer)
      Manually set the ConfigSerializer to use.

      This can be used in the case that the file extension is not sufficient to detect which format is in use, or to support additional formats not currently supported.

      Parameters:
      serializer - The serializer.
      Returns:
      The same ConfigFile.
    • load

      public ConfigCategory load()
      Perform loading the config into a ConfigCategory.

      This is the root tag in your Config.

      This may be empty depending on if the file existed, or there was an erorr loding the file.

      Returns:
      The loaded ConfigCategory.