DynamicHUD Dev Guide
DownloadNeed Support?
  • Dynamic HUD
  • Import using Gradle
  • Integrating DynamicHUD
    • Integrating DynamicHUD
    • Adding Widgets
    • Adding your own WidgetRenderer
    • Passing AbstractMoveableScreen instance
    • Changing default key bind
    • Changing save and load file
    • Registering Custom Widgets
  • Widget
    • Widget class
    • How to create a custom widget
    • Widget Renderer
    • WidgetData
    • DynamicValueRegistry
    • Scaling
  • Screens
    • AbstractMoveableScreen
  • ContextMenu
    • ContextMenu class
    • Using context menu
    • Option<T> class
      • Color Option
      • Boolean Option
      • Double Option
      • Runnable Option
      • Enum Option
      • List Option
      • SubMenu Option
Powered by GitBook
On this page
  • Overview
  • Usage
  • Example
  • Class Details
  • Notes

Was this helpful?

  1. Widget

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.

Global Registries are shared across all mods, so there is a chance of duplicate keys which are overwritten.

Example

Local Registry

DynamicValueRegistry dvr = new DynamicValueRegistry("mod_id");
dvr.registerLocal("ABC", /*Your Supplier*/);
Supplier<?> result = dvr.get("ABC");

Global registry

DynamicValueRegistry.registerGlobal("ABC", /*Your Supplier*/);
Supplier<?> result = DynamicValueRegistry.getGlobal("ABC");


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.

PreviousWidgetDataNextScaling

Last updated 1 year ago

Was this helpful?