Class CommonDynamicKeyCommands
java.lang.Object
dev.munebase.dynamickeybinds.command.CommonDynamicKeyCommands
Common command logic for dynamic keybinds that works across all loaders.
This handles add/list/remove operations independent of the mod loader.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic net.minecraft.client.KeyMappingaddKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action, Consumer<String> onError) Adds a dynamic keybind to the registry with an action.static Optional<DynamicKeybindAction>createDefaultDebugAction(String id, net.minecraft.nbt.CompoundTag data) Builds the default debug action payload used when no explicit action is provided.static intexecuteAdd(String id, int keyCode, String category, Optional<DynamicKeybindAction> action, Consumer<String> onError, Consumer<String> onSuccess) Shared command execution helper for add operations.static intexecuteList(Consumer<String> sendLine) Shared command execution helper for list operations.static intShared command execution helper for remove operations.static intextractKeycodeFromKeyMapping(net.minecraft.client.KeyMapping keyMapping) Extracts keycode from a KeyMapping.static StringUser-facing add request message.Formats user-facing lines for the `list` command output.static StringUser-facing networking not initialized message.static StringUser-facing remove request message.Lists all currently registered dynamic keybinds.static intlistResultCode(List<String> lines) Computes Brigadier result for list output lines.static net.minecraft.client.KeyMappingremoveKeybind(String id, Consumer<String> onError) Removes a dynamic keybind from the registry.
-
Field Details
-
DEFAULT_HANDLER_ACTION_ID
- See Also:
-
-
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 keybindkeyCode- GLFW key codecategory- Category for organizing in the keybinds menuaction- 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
Lists all currently registered dynamic keybinds.- Returns:
- List of keybind names
-
formatListOutput
Formats user-facing lines for the `list` command output.- Returns:
- display lines in render order
-
formatAddRequestMessage
User-facing add request message.- Parameters:
id- keybind id- Returns:
- formatted message
-
formatNetworkingNotInitializedMessage
User-facing networking not initialized message.- Returns:
- formatted message
-
formatRemoveRequestMessage
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
Computes Brigadier result for list output lines.- Parameters:
lines- list output lines- Returns:
- 0 when empty-state message is displayed; otherwise key count
-
removeKeybind
Removes a dynamic keybind from the registry.- Parameters:
id- Identifier of the keybind to removeonError- 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 identifierkeyCode- GLFW key codecategory- keybind categoryaction- action payloadonError- receives user-facing error messageonSuccess- receives user-facing success message- Returns:
- command result code
-
executeRemove
Shared command execution helper for remove operations.- Parameters:
id- keybind identifieronError- receives user-facing error messageonSuccess- receives user-facing success message- Returns:
- command result code
-
executeList
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
-