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) or DynamicValueRegistry(String modId, String registryId). Register with registerLocal(String key, Supplier<?> supplier).

  • Global Registry: Use registerGlobal(String key, Supplier<?> supplier) with modid:key format.

  • Retrieve Values: Use get(String key) for local or getValue(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, throws IllegalStateException if not found.

Last updated

Was this helpful?