DynamicValueRegistry
Overview
The DynamicValueRegistry
class is designed to manage dynamic values for widgets, providing both a global and local registry of suppliers for these values.
Usage
To utilize a local registry, instantiate the DynamicValueRegistry
class with a unique identifier, typically the mod ID. Register suppliers globally or locally as needed and retrieve them using the corresponding keys.
Example
Local Registry
Global registry
Class Details
Fields
globalRegistry
: A static map holding the global registry of suppliers.localRegistry
: A map holding the local registry of suppliers.
Constructor
DynamicValueRegistry(String modId)
Initializes a new instance of the DynamicValueRegistry
class for the specified mod ID.
Methods
registerGlobal(String key, Supplier<?> supplier)
Registers a supplier in the global registry under the specified key.
getGlobal(String key)
Retrieves a supplier from the global registry using the specified key.
registerLocal(String key, Supplier<?> supplier)
Registers a supplier in the local registry under the specified key.
get(String key)
Retrieves a supplier from the local registry, falling back to the global registry if not found.
setLocalRegistry(Map<String, Supplier<?>> map)
Sets the local registry to the provided map of suppliers.
Notes
The
modId
parameter in the constructor does not need to be the actual mod ID; it can be any unique identifier string.The
get
method first attempts to retrieve a supplier from the local registry before checking the global registry.
Last updated
Was this helpful?