|
23 | 23 | import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; |
24 | 24 | import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
25 | 25 | import net.minecraft.client.Keyboard; |
| 26 | +import net.minecraft.client.input.CharInput; |
| 27 | +import net.minecraft.client.input.KeyInput; |
26 | 28 | import net.minecraft.client.option.KeyBinding; |
27 | 29 | import net.minecraft.client.util.InputUtil; |
28 | 30 | import org.spongepowered.asm.mixin.Mixin; |
29 | 31 | import org.spongepowered.asm.mixin.injection.At; |
30 | 32 | import org.spongepowered.asm.mixin.injection.Inject; |
31 | 33 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
32 | 34 |
|
| 35 | +/** |
| 36 | + * Mixin to intercept keyboard input events. |
| 37 | + * |
| 38 | + * Note: In 1.21.11, onKey/onChar methods were refactored to use KeyInput/CharInput records. |
| 39 | + * - onKey(long window, int action, KeyInput input) where KeyInput has key, scancode, modifiers |
| 40 | + * - onChar(long window, CharInput input) where CharInput has codepoint, modifiers |
| 41 | + */ |
33 | 42 | @Mixin(Keyboard.class) |
34 | 43 | public class KeyboardMixin { |
35 | 44 | @WrapMethod(method = "onKey") |
36 | | - private void onKey(long window, int key, int scancode, int action, int modifiers, Operation<Void> original) { |
37 | | - EventFlow.post(new KeyboardEvent.Press(key, scancode, action, modifiers)); |
38 | | - original.call(window, key, scancode, action, modifiers); |
| 45 | + private void onKey(long window, int action, KeyInput input, Operation<Void> original) { |
| 46 | + EventFlow.post(new KeyboardEvent.Press(input.key(), input.scancode(), action, input.modifiers())); |
| 47 | + original.call(window, action, input); |
39 | 48 | } |
40 | 49 |
|
41 | 50 | @Inject(method = "onKey", at = @At("RETURN")) |
42 | | - private void onKeyTail(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) { |
| 51 | + private void onKeyTail(long window, int action, KeyInput input, CallbackInfo ci) { |
| 52 | + int key = input.key(); |
43 | 53 | if (!InventoryMove.getShouldMove() || !InventoryMove.isKeyMovementRelated(key)) return; |
44 | | - InputUtil.Key fromCode = InputUtil.fromKeyCode(key, scancode); |
| 54 | + InputUtil.Key fromCode = InputUtil.fromKeyCode(input); |
45 | 55 | KeyBinding.setKeyPressed(fromCode, action != 0); |
46 | 56 | } |
47 | 57 |
|
48 | 58 | @WrapMethod(method = "onChar") |
49 | | - private void onChar(long window, int codePoint, int modifiers, Operation<Void> original) { |
50 | | - char[] chars = Character.toChars(codePoint); |
| 59 | + private void onChar(long window, CharInput input, Operation<Void> original) { |
| 60 | + char[] chars = Character.toChars(input.codepoint()); |
51 | 61 |
|
52 | 62 | for (char c : chars) |
53 | 63 | EventFlow.post(new KeyboardEvent.Char(c)); |
54 | 64 |
|
55 | | - original.call(window, codePoint, modifiers); |
| 65 | + original.call(window, input); |
56 | 66 | } |
57 | 67 | } |
0 commit comments