tutorial:keybinds
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:keybinds [2023/12/27 13:14] – ↷ Links adapted because of a move operation 2601:188:cb7c:25a0:19fa:9122:4e5a:fad1 | tutorial:keybinds [2025/12/12 16:57] (current) – fix half-finished mojmapping cassiancc | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| Adding a key-bind is easy. You'll need to: | Adding a key-bind is easy. You'll need to: | ||
| * open or create a Client [[documentation: | * open or create a Client [[documentation: | ||
| - | * create a KeyBinding | + | * create a KeyMapping.Category object |
| + | * create a KeyMapping | ||
| * react to the key being pressed | * react to the key being pressed | ||
| - | See [[https:// | + | See [[https:// |
| ==== Preparing an Entrypoint ==== | ==== Preparing an Entrypoint ==== | ||
| Line 41: | Line 42: | ||
| ==== Creating your Keybind ==== | ==== Creating your Keybind ==== | ||
| - | Declare | + | Declare these in an area of your preference: |
| <code java> | <code java> | ||
| - | private static | + | private static |
| + | private static final KeyMapping.Category CATEGORY = KeyMapping.Category.register(ResourceLocation.fromNamespaceAndPath(" | ||
| </ | </ | ||
| - | FabricKeyBinding | + | KeyBindingHelper |
| <code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
| - | keyBinding = KeyBindingHelper.registerKeyBinding(new | + | keyBinding = KeyBindingHelper.registerKeyBinding(new |
| - | " | + | |
| - | | + | InputConstants.Type.KEYSYM, |
| - | GLFW.GLFW_KEY_R, | + | |
| - | " | + | CATEGORY |
| )); | )); | ||
| </ | </ | ||
| + | |||
| + | On versions older than 1.21.9, you would substitute your KeyMapping.Category for the translation key of the keybinding' | ||
| Sticky keys can also be created with '' | Sticky keys can also be created with '' | ||
| Line 71: | Line 75: | ||
| ClientTickEvents.END_CLIENT_TICK.register(client -> { | ClientTickEvents.END_CLIENT_TICK.register(client -> { | ||
| - | | + | while (keyBinding.consumeClick()) { |
| - | client.player.sendMessage(Text.literal(" | + | |
| - | } | + | |
| }); | }); | ||
| </ | </ | ||
| Line 81: | Line 85: | ||
| ClientTickEvents.END_CLIENT_TICK.register(client -> { | ClientTickEvents.END_CLIENT_TICK.register(client -> { | ||
| - | | + | while (keyBinding.consumeClick()) { |
| - | client.player.sendMessage(new LiteralText("Key 1 was pressed!" | + | |
| - | } | + | |
| }); | }); | ||
| </ | </ | ||
| | | ||
tutorial/keybinds.1703682854.txt.gz · Last modified: 2023/12/27 13:14 by 2601:188:cb7c:25a0:19fa:9122:4e5a:fad1