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; commands, hot reloading and (for synced scopes) server sync then work without more code, and so do the config screens of Glazed Menu (or Configured), when a player has it.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Called with the values that changed, whenever any do, on the thread that changed them.
    static List<Config>
    all()
    Every registered config, in registration order.
    void
    Sets a preset's values, in memory; save() writes them.
    builder(String modId, ConfigScope scope)
    Starts declaring a config named after its scope (mymod:client).
    The file's comment lines.
    net.minecraft.server.permissions.Permission
    Who may change a synced config from a client.
    @Nullable Path
    The config file, or null while it has none (a client config on a dedicated server).
    find(String path)
    The value at a dotted path, like "rendering.particles".
     
    static List<Config>
    forMod(String modId)
    A mod's registered configs, in registration order.
    get(net.minecraft.resources.Identifier id)
    A registered config by its id (mymod:client).
    net.minecraft.resources.Identifier
    id()
    <modid>:<name>.
    boolean
    Whether the values come from the file (or a server) rather than being defaults with no file.
    boolean
    Whether this client currently shows a server's values: the config is synced and the client is connected to a remote server.
    default boolean
    Whether a ConfigScope.STARTUP config has saved changes that apply after a restart.
    default String
     
    default String
     
    The presets declared on the builder, by name.
    void
    Reads the file again, notifying listeners of whatever changed.
    boolean
     
    void
    Sets every value back to its default, in memory; save() writes it.
     
    void
    Writes the current values to the file.
     
    How the config's screen looks: its own theme, or the mod's.
    net.minecraft.network.chat.Component
    The config's title: config.<modid>.<name>.title, falling back to the mod id and name.
    default Stream<ConfigValue<?>>
    Every value, depth first.
    int
    The file version values are migrated to; 0 when the config isn't versioned.
  • 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.Identifier 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.Identifier 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

      net.minecraft.server.permissions.Permission editPermission()
      Who may change a synced config from a client.
    • filePath

      @Nullable @Nullable Path filePath()
      The config file, or null while it has none (a client config on a dedicated server).
    • isLoaded

      boolean isLoaded()
      Whether the values come from the file (or a server) rather than being defaults with no file.
    • 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)