Class ConfigObject<T>

java.lang.Object
net.ixdarklord.coolcatcore.api.config.annotation.ConfigObject<T>
Type Parameters:
T - the class declaring the entries

public final class ConfigObject<T> extends Object
A config declared as a plain class: every non-static, non-transient field becomes an entry, with the field's initial value as its default, and nested objects become groups. The fields always hold the current values, so the mod reads them directly:

 @ConfigEntry.Comment("MyMod's client settings")
 public class MyClientConfig {
     @ConfigEntry.Comment("Draws the overlay.")
     public boolean showHud = true;

     @ConfigEntry.Range(min = 0, max = 256) @ConfigEntry.Slider
     public int particles = 32;

     public Rendering rendering = new Rendering();

     public static class Rendering {
         @ConfigEntry.Color public int tint = 0xFF8800;
         public List<String> hiddenItems = List.of("minecraft:barrier");
     }
 }

 public static final ConfigObject<MyClientConfig> CONFIG = ConfigObject.register("mymod", ConfigScope.CLIENT, new MyClientConfig());
 if (CONFIG.get().showHud) ...
 
Supported field types: boolean, int, long, float, double (and their boxes), String, enums,
invalid reference
net.minecraft.resources.Identifier
, and Lists of those. Assign new lists rather than changing them in place: the lists held are immutable.
  • Method Details

    • register

      public static <T> ConfigObject<T> register(String modId, ConfigScope scope, T instance)
      Registers the instance's fields as a config named after the scope.
    • register

      public static <T> ConfigObject<T> register(ConfigBuilder builder, T instance)
      Registers the instance's fields with a builder whose settings (name, format, version...) are already set.
      Throws:
      IllegalArgumentException - when a field's type isn't supported
    • get

      public T get()
      The instance whose fields hold the current values.
    • config

      public Config config()
    • save

      public void save()
      Takes values assigned to the fields by code, then writes the file. Invalid field values are put back to the config's values.