tutorial:keybinds
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:keybinds [2019/04/06 21:04] – draylar | tutorial:keybinds [2020/02/02 02:28] – draylar | ||
---|---|---|---|
Line 15: | Line 15: | ||
Fabric API has a **FabricKeyBinding** object, which makes it easier to create your own **KeyBinding**. Declare one of these in an area of your preference: | Fabric API has a **FabricKeyBinding** object, which makes it easier to create your own **KeyBinding**. Declare one of these in an area of your preference: | ||
- | | + | <code java> |
+ | private static FabricKeyBinding keyBinding; | ||
+ | </ | ||
FabricKeyBinding has a Builder for initialization. It takes in an Identifier, InputUtil.Type, | FabricKeyBinding has a Builder for initialization. It takes in an Identifier, InputUtil.Type, | ||
- | | + | <code java [enable_line_numbers=" |
- | new Identifier(" | + | keyBinding = FabricKeyBinding.Builder.create( |
- | InputUtil.Type.KEY_KEYBOARD, | + | new Identifier(" |
+ | InputUtil.Type.KEYSYM, | ||
GLFW.GLFW_KEY_R, | GLFW.GLFW_KEY_R, | ||
"Wiki Keybinds" | "Wiki Keybinds" | ||
- | | + | ).build(); |
+ | </ | ||
| | ||
GLFW.GLFW_KEY_R can be replaced with whatever key you want the binding to default to. The category is related to how the keybinding is grouped in the settings page. | GLFW.GLFW_KEY_R can be replaced with whatever key you want the binding to default to. The category is related to how the keybinding is grouped in the settings page. | ||
+ | |||
+ | ==== Configuring your Keybind' | ||
+ | If you opt to use a custom keybind category, you'll need to add it. | ||
+ | <code java> | ||
+ | KeyBindingRegistry.INSTANCE.addCategory(String categoryName); | ||
+ | </ | ||
+ | ' | ||
==== Registering your Keybind ==== | ==== Registering your Keybind ==== | ||
- | To register your keybinding, | + | To register your keybinding, |
- | | + | <code java> |
+ | KeyBindingRegistry.INSTANCE.register(keyBinding); | ||
+ | </ | ||
| | ||
If you log in to your game now, you will see your key binding in the settings page. | If you log in to your game now, you will see your key binding in the settings page. | ||
Line 43: | Line 56: | ||
Unfortunately, | Unfortunately, | ||
- | | + | <code java> |
- | { | + | ClientTickCallback.EVENT.register(e -> |
+ | { | ||
if(keyBinding.isPressed()) System.out.println(" | if(keyBinding.isPressed()) System.out.println(" | ||
- | | + | }); |
+ | </ | ||
| | ||
Keep note that this is entirely client-side. To have the server respond to a keybind, you'll need to send a custom packet and have the server handle it separately. | Keep note that this is entirely client-side. To have the server respond to a keybind, you'll need to send a custom packet and have the server handle it separately. |
tutorial/keybinds.txt · Last modified: 2023/12/27 13:14 by 2601:188:cb7c:25a0:19fa:9122:4e5a:fad1