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 [2020/02/02 02:28] – draylar | tutorial:keybinds [2020/06/13 13:22] – shedaniel | ||
---|---|---|---|
Line 6: | Line 6: | ||
Adding a key-bind is easy. You'll need to: | Adding a key-bind is easy. You'll need to: | ||
- | * create a FabricKeyBinding | + | * create a KeyBinding |
* register your key | * register your key | ||
* react to the key being pressed | * react to the key being pressed | ||
Line 13: | Line 13: | ||
==== Creating your Keybind ==== | ==== Creating your Keybind ==== | ||
- | 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> | <code java> | ||
- | private static | + | private static |
</ | </ | ||
Line 22: | Line 22: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | keyBinding = FabricKeyBinding.Builder.create( | + | keyBinding = new KeyBinding( |
- | | + | "key.examplemod.spook", |
- | InputUtil.Type.KEYSYM, | + | InputUtil.Type.KEYSYM, |
- | GLFW.GLFW_KEY_R, | + | GLFW.GLFW_KEY_R, |
- | "Wiki Keybinds" | + | "category.examplemod.test" |
- | ).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' | ==== Configuring your Keybind' | ||
- | If you opt to use a custom keybind category, you'll need to add it. | + | |
- | <code java> | + | Fabric will automatically register |
- | KeyBindingRegistry.INSTANCE.addCategory(String categoryName); | + | |
- | </ | + | |
- | ' | + | |
==== Registering your Keybind ==== | ==== Registering your Keybind ==== | ||
- | To register your keybinding, register using the **KeybindingRegistry**, **in the client mod initializer**: | + | To register your keybinding, register using the **KeyBindingHelper**, **in the client mod initializer**: |
<code java> | <code java> | ||
- | KeyBindingRegistry.INSTANCE.register(keyBinding); | + | KeyBindingHelper.registerKeyBinding(keyBinding); |
</ | </ | ||
| | ||
Line 52: | Line 48: | ||
==== Responding to your Keybind ==== | ==== Responding to your Keybind ==== | ||
- | |||
Unfortunately, | Unfortunately, | ||
<code java> | <code java> | ||
- | ClientTickCallback.EVENT.register(e -> | + | ClientTickCallback.EVENT.register(client |
- | { | + | |
- | | + | |
}); | }); | ||
</ | </ | ||
| | ||
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