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:keyformat.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, throwsIllegalStateExceptionif not found.
Set
registryIDcorrectly in widgets (e.g.,DynamicValueRegistry.GLOBAL_IDfor global keys). Mismatches causenullvalues.It is suggested to use
modid:keyfor global keys to avoid conflicts.
Exception Thrown:
IllegalStateExceptionfromgetByIdSafeif registry ID is missing.Exception Thrown:
IllegalArgumentExceptionfromgetValueifregistryIDorkeyis empty.
Last updated
Was this helpful?