Package dev.munebase.dynamickeybinds
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 Summary
Modifier and TypeMethodDescriptionCollection<net.minecraft.client.KeyMapping>Get all currently registered dynamic keys.getKeyBindAction(net.minecraft.client.KeyMapping keyBinding) Get the action associated with a keybind.net.minecraft.client.KeyMappinggetKeyBindById(String id) Get a specific keybind by its ID.net.minecraft.client.KeyMappingregisterDynamicKey(String id, int keyCode, String category, Optional<DynamicKeybindAction> action) Register a new dynamic key at runtime.default booleanUnregister an existing dynamic key by ID.voidunregisterDynamicKey(net.minecraft.client.KeyMapping keyBinding) Unregister an existing dynamic key.
-
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 organizationaction- 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
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
Get a specific keybind by its ID.- Parameters:
id- the keybind identifier- Returns:
- the KeyMapping, or null if not found
-
getKeyBindAction
Get the action associated with a keybind.- Parameters:
keyBinding- the key mapping to query- Returns:
- the action, or empty if not set
-