DynamicValueRegistry
The DynamicValueRegistry
manages dynamic values for widgets in DynamicHUD, supporting global (shared across mods) and local (mod-specific) registries. Use it to register Supplier
instances for real-time data (e.g., FPS, player names) in the init
method of your DynamicHudIntegration
. This is what allows widgets to get and share dynamic values.
Usage
Local Registry: Create with
DynamicValueRegistry(String modId)
orDynamicValueRegistry(String modId, String registryId)
. Register withregisterLocal(String key, Supplier<?> supplier)
.Global Registry: Use
registerGlobal(String key, Supplier<?> supplier)
withmodid:key
format.Retrieve Values: Use
get(String key)
for local orgetValue(String registryID, String key)
for specific registries.
Example
DynamicValueRegistry dvr = new DynamicValueRegistry("mymod");
dvr.registerLocal("abc", () -> "Hello!");
Supplier<?> result = dvr.get("abc");
Key Methods
registerGlobal(String key, Supplier<?> supplier)
: Adds a supplier to the global registry.registerLocal(String key, Supplier<?> supplier)
: Adds a supplier to the local registry.get(String key)
: Retrieves a local supplier.getValue(String registryID, String key)
: Gets a supplier by registry ID and key.getByIdSafe(String registryId)
: Gets a registry instance, throwsIllegalStateException
if not found.
Set
registryID
correctly in widgets (e.g.,DynamicValueRegistry.GLOBAL_ID
for global keys). Mismatches causenull
values.It is suggested to use
modid:key
for global keys to avoid conflicts.
Exception Thrown:
IllegalStateException
fromgetByIdSafe
if registry ID is missing.Exception Thrown:
IllegalArgumentException
fromgetValue
ifregistryID
orkey
is empty.
Last updated
Was this helpful?