Interface DynamicKeyRegistry

All Known Subinterfaces:
ServerSynchronizedDynamicKeyRegistry
All Known Implementing Classes:
DynamicKeyRegistryImpl, NetworkedDynamicKeyRegistry

public interface DynamicKeyRegistry
Registry for dynamically created keybinds at runtime. This interface provides the core API for managing dynamic keybinds in the mod. Implementations maintain a record of all keybinds and their associated actions, allowing third-party mods to create, retrieve, and remove keybinds on-the-fly.

Thread Safety: Implementations must be thread-safe as keybinds may be registered/unregistered from different threads.

Example Usage:

 
 DynamicKeyRegistry registry = DynamicKeyRegistryProvider.getRegistry();
 CompoundTag actionData = new CompoundTag();
 actionData.putString("target", "someValue");
 
 KeyMapping keyMapping = registry.registerDynamicKey(
   "mymod:key_id",
   GLFW.GLFW_KEY_K,
   "mymod",
   Optional.of(new DynamicKeybindAction("mymod:action_id", actionData))
 );
 
 
See Also:
  • Method Details

    • registerDynamicKey

      net.minecraft.client.KeyMapping registerDynamicKey(String id, int keyCode, String category, Optional<DynamicKeybindAction> action)
      Register a new dynamic key at runtime.
      Parameters:
      id - unique identifier for the keybind (e.g., "mymod:key_name")
      keyCode - the GLFW key code (e.g., GLFW.GLFW_KEY_K)
      category - the keybind category for menu organization
      action - the action to trigger when pressed (optional)
      Returns:
      the registered KeyMapping
      Throws:
      IllegalArgumentException - if the ID already exists or keyCode is invalid
    • unregisterDynamicKey

      void unregisterDynamicKey(net.minecraft.client.KeyMapping keyBinding)
      Unregister an existing dynamic key.
      Parameters:
      keyBinding - the key binding to unregister
    • unregisterDynamicKey

      default boolean unregisterDynamicKey(String id)
      Unregister an existing dynamic key by ID.
      Parameters:
      id - keybind identifier
      Returns:
      true when a keybind with the given ID existed and was removed
    • getAllDynamicKeys

      Collection<net.minecraft.client.KeyMapping> getAllDynamicKeys()
      Get all currently registered dynamic keys.
      Returns:
      immutable collection of all dynamic key bindings
    • getKeyBindById

      net.minecraft.client.KeyMapping getKeyBindById(String id)
      Get a specific keybind by its ID.
      Parameters:
      id - the keybind identifier
      Returns:
      the KeyMapping, or null if not found
    • getKeyBindAction

      Optional<DynamicKeybindAction> getKeyBindAction(net.minecraft.client.KeyMapping keyBinding)
      Get the action associated with a keybind.
      Parameters:
      keyBinding - the key mapping to query
      Returns:
      the action, or empty if not set