Skip to content

Property Definition and State Management

JohnSmith474 edited this page Jun 15, 2026 · 9 revisions

Config Overhauled utilizes a fluent builder pattern to define properties, assign constraints, and allocate baseline values prior to system registration.

Structural Allocation

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 via ConfigRegistry.getOrCreateManager(modId). Serves as the authoritative root.

  • Category: Allocated via ConfigManager::define(id). Establishes the primary structural classification.

  • Group: Allocated via Category::define(id). Serves as the direct registration container for properties.

Property Construction Sequence

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();

Serialization and Data Types

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.

Validation Constraints

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.

Data Type Assignment Matrix

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.

Memory Management and State Mutation

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.

Clone this wiki locally