Interface Config

All Known Implementing Classes:
ConfigImpl

@NonExtendable public interface Config
A registered config: a tree of groups and typed values, stored in one file.

Declare one with a ConfigBuilder, keeping the value handles in static fields:


 public final class MyModConfig {
     private static final ConfigBuilder BUILDER = Config.builder("mymod", ConfigScope.CLIENT);

     public static final ConfigValue<Boolean> SHOW_HUD = BUILDER.bool("showHud", true)
             .comment("Draws the overlay.").build();

     static { BUILDER.push("rendering"); }
     public static final ConfigValue<Integer> PARTICLES = BUILDER.intValue("particles", 32)
             .range(0, 256).slider().enabledWhen(SHOW_HUD).build();
     static { BUILDER.pop(); }

     public static final Config CONFIG = BUILDER.build();
 }
 
or from an annotated class with ConfigObject. Building registers the config and loads its file; the config screen, commands, hot reloading and (for synced scopes) server sync then work without more code.
  • Method Details

    • builder

      static ConfigBuilder builder(String modId, ConfigScope scope)
      Starts declaring a config named after its scope (mymod:client).
    • get

      static Optional<Config> get(net.minecraft.resources.ResourceLocation id)
      A registered config by its id (mymod:client).
    • all

      static List<Config> all()
      Every registered config, in registration order.
    • forMod

      static List<Config> forMod(String modId)
      A mod's registered configs, in registration order.
    • id

      net.minecraft.resources.ResourceLocation id()
      <modid>:<name>.
    • modId

      default String modId()
    • name

      default String name()
    • scope

      ConfigScope scope()
    • format

      ConfigFormat format()
    • root

      ConfigGroup root()
    • title

      net.minecraft.network.chat.Component title()
      The config's title: config.<modid>.<name>.title, falling back to the mod id and name.
    • theme

      ConfigTheme theme()
      How the config's screen looks: its own theme, or the mod's.
    • comment

      List<String> comment()
      The file's comment lines.
    • version

      int version()
      The file version values are migrated to; 0 when the config isn't versioned.
    • editPermission

      int editPermission()
      The permission level (0 to 4) a player needs to change a synced config from a client.
    • filePath

      @Nullable @Nullable Path filePath()
      The config file, or null while it has none (a ConfigScope.WORLD config with no server running).
    • isLoaded

      boolean isLoaded()
      Whether the values come from the file (or a server) rather than being defaults waiting for a world.
    • isRemote

      boolean isRemote()
      Whether this client currently shows a server's values: the config is synced and the client is connected to a remote server. Local changes aren't saved meanwhile, and the client's own values come back on disconnecting.
    • isRestartPending

      default boolean isRestartPending()
      Whether a ConfigScope.STARTUP config has saved changes that apply after a restart.
    • save

      void save()
      Writes the current values to the file. Does nothing while the config has no file or is remote.
    • reload

      void reload()
      Reads the file again, notifying listeners of whatever changed.
    • resetAll

      void resetAll()
      Sets every value back to its default, in memory; save() writes it.
    • find

      Optional<ConfigValue<?>> find(String path)
      The value at a dotted path, like "rendering.particles".
    • values

      default Stream<ConfigValue<?>> values()
      Every value, depth first.
    • presets

      Map<String,ConfigPreset> presets()
      The presets declared on the builder, by name.
    • applyPreset

      void applyPreset(ConfigPreset preset)
      Sets a preset's values, in memory; save() writes them.
    • addListener

      void addListener(Config.ChangeListener listener)
      Called with the values that changed, whenever any do, on the thread that changed them.
    • removeListener

      boolean removeListener(Config.ChangeListener listener)