Class CommonDynamicKeyCommands

java.lang.Object
dev.munebase.dynamickeybinds.command.CommonDynamicKeyCommands

public final class CommonDynamicKeyCommands extends Object
Common command logic for dynamic keybinds that works across all loaders. This handles add/list/remove operations independent of the mod loader.
  • Field Details

  • Method Details

    • addKeybind

      public static net.minecraft.client.KeyMapping addKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action, Consumer<String> onError)
      Adds a dynamic keybind to the registry with an action.
      Parameters:
      id - Unique identifier for the keybind
      keyCode - GLFW key code
      category - Category for organizing in the keybinds menu
      action - the action to execute when key is pressed (optional)
      onError - Called with error message if registration fails
      Returns:
      The registered KeyMapping, or null if registration failed
    • listKeybinds

      public static List<String> listKeybinds()
      Lists all currently registered dynamic keybinds.
      Returns:
      List of keybind names
    • formatListOutput

      public static List<String> formatListOutput()
      Formats user-facing lines for the `list` command output.
      Returns:
      display lines in render order
    • formatAddRequestMessage

      public static String formatAddRequestMessage(String id)
      User-facing add request message.
      Parameters:
      id - keybind id
      Returns:
      formatted message
    • formatNetworkingNotInitializedMessage

      public static String formatNetworkingNotInitializedMessage()
      User-facing networking not initialized message.
      Returns:
      formatted message
    • formatRemoveRequestMessage

      public static String formatRemoveRequestMessage(String id)
      User-facing remove request message.
      Parameters:
      id - keybind id
      Returns:
      formatted message
    • createDefaultDebugAction

      public static Optional<DynamicKeybindAction> createDefaultDebugAction(String id, net.minecraft.nbt.CompoundTag data)
      Builds the default debug action payload used when no explicit action is provided.
      Parameters:
      id - keybind id
      Returns:
      optional action for default handler
    • listResultCode

      public static int listResultCode(List<String> lines)
      Computes Brigadier result for list output lines.
      Parameters:
      lines - list output lines
      Returns:
      0 when empty-state message is displayed; otherwise key count
    • removeKeybind

      public static net.minecraft.client.KeyMapping removeKeybind(String id, Consumer<String> onError)
      Removes a dynamic keybind from the registry.
      Parameters:
      id - Identifier of the keybind to remove
      onError - Called with error message if removal fails
      Returns:
      The removed KeyMapping, or null if not found
    • executeAdd

      public static int executeAdd(String id, int keyCode, String category, Optional<DynamicKeybindAction> action, Consumer<String> onError, Consumer<String> onSuccess)
      Shared command execution helper for add operations.
      Parameters:
      id - keybind identifier
      keyCode - GLFW key code
      category - keybind category
      action - action payload
      onError - receives user-facing error message
      onSuccess - receives user-facing success message
      Returns:
      command result code
    • executeRemove

      public static int executeRemove(String id, Consumer<String> onError, Consumer<String> onSuccess)
      Shared command execution helper for remove operations.
      Parameters:
      id - keybind identifier
      onError - receives user-facing error message
      onSuccess - receives user-facing success message
      Returns:
      command result code
    • executeList

      public static int executeList(Consumer<String> sendLine)
      Shared command execution helper for list operations.
      Parameters:
      sendLine - line sender callback
      Returns:
      command result code
    • extractKeycodeFromKeyMapping

      public static int extractKeycodeFromKeyMapping(net.minecraft.client.KeyMapping keyMapping)
      Extracts keycode from a KeyMapping.
      Parameters:
      keyMapping - The keymapping to extract from
      Returns:
      The GLFW key code, or 0 if extraction fails