-
Notifications
You must be signed in to change notification settings - Fork 0
Property Definition and State Management
Config Overhauled utilizes a fluent builder pattern to define properties, assign constraints, and allocate baseline values prior to system registration.
Property definition mandates the prior allocation of a centralized configuration manager and the establishment of structural boundaries.
// Initializes the centralized configuration manager for the specified mod ID.
public static final ConfigManager CONFIG = ConfigRegistry.getOrCreateManager("examplemod");
// Defines a top-level classification category for the GUI and file structure.
public static final Category EXAMPLE_CATEGORY = CONFIG.define("example_category");
// Defines a structural subdivision within the category.
public static final Group EXAMPLE_GROUP = EXAMPLE_CATEGORY.define("example_group");-
ConfigManager: Instantiated viaConfigRegistry.getOrCreateManager(modId). Serves as the authoritative root. -
Category: Allocated viaConfigManager::define(id). Establishes the primary structural classification. -
Group: Allocated viaCategory::define(id). Serves as the direct registration container for properties.
Properties are instantiated through a chained definition sequence originating from a Group instance. The sequence enforces phase requirements before the property is finalized and bound to memory
// Initiates sequence with the registry identifier
public static final Property<Boolean> EXAMPLE_PROPERTY = EXAMPLE_GROUP.define("example_property")
// Phase 1: Scope assignment (clientSide(), globalSide(), levelSide())
.globalSide()
// Phase 2: Data type mapping and baseline state allocation
.asBoolean(true)
// Phase 3: Metadata injection (Optional)
.withComment("Description injected into the .TOML file.")
// Phase 4: Sequence termination and registry binding
.register();Property states map to and from external formats via Mojang Codec implementations. Fundamental data types map natively via built-in builder terminals (asBoolean, asInteger, asDouble, asString). Custom complex data types necessitate the injection of a discrete Codec<T> instance during the definition phase to govern disk serialization and network payload encoding.
Numerical properties support explicit boundary validation. The builder sequence accepts defined lower and upper limits. The configuration manager enforces internal state correction if external data payloads, network synchronizations, or localized disk modifications exceed these bound constraints.
The phase 2 definition step dictates the generic parameter of the finalized property instance. The following matrix maps builder terminals to their respective Property generic resolutions.
| Builder Terminal | Generic Resolution Property<T>
|
Notes |
|---|---|---|
asBoolean() |
Property<Boolean> |
|
asInteger() |
Property<Integer> |
Supports lower and upper validation constraints. |
asDouble() |
Property<Double> |
Supports lower and upper validation constraints. |
asFloat() |
Property<Float> |
Supports lower and upper validation constraints. |
asLong() |
Property<Long> |
Supports lower and upper validation constraints. |
asRGBColor() |
Property<Integer> |
Encodes 24-bit RGB color state as a primitive integer. |
asARGBColor() |
Property<Integer> |
Encodes 32-bit ARGB color state as a primitive integer. |
asString() |
Property<String> |
|
asEnum() |
Property<E extends Enum<E>> |
Requires explicit Codec<E> binding. |
asList() |
Property<List<E>> |
Requires explicit Codec<E> binding for list elements. |
asBlock() |
Property<Block> |
Binds to structural Block registry references. |
asItem() |
Property<Item> |
Binds to Item registry references. |
asBlocks() |
Property<List<Block>> |
Binds to a uniform list of Block registry references. |
asItems() |
Property<List<Item>> |
Binds to a uniform list of Item registry references. |
The active memory state operates via direct accessors on the allocated Property<T> instance.
-
get(): Retrieves the current active runtime value. -
set(T newValue): Overrides the active memory state. Executing a state mutation through this method automatically overwrites the corresponding disk definition and initiates the lifecycle broadcast pipeline to connected listeners. -
defaultValue(): Retrieves the initial allocation state assigned during builder instantiation, ignoring network overrides or localized disk loads.