Class ConfigObject<T>
java.lang.Object
net.ixdarklord.coolcatcore.api.config.annotation.ConfigObject<T>
- Type Parameters:
T- the class declaring the entries
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, ResourceLocation, and Lists of those. Assign new
lists rather than changing them in place: the lists held are immutable.-
Method Summary
Modifier and TypeMethodDescriptionconfig()get()The instance whose fields hold the current values.static <T> ConfigObject<T>register(String modId, ConfigScope scope, T instance) Registers the instance's fields as a config named after the scope.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.voidsave()Takes values assigned to the fields by code, then writes the file.
-
Method Details
-
register
Registers the instance's fields as a config named after the scope. -
register
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
The instance whose fields hold the current values. -
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.
-