|
7 | 7 | import com.mojang.blaze3d.platform.InputConstants; |
8 | 8 | import net.minecraft.client.KeyMapping; |
9 | 9 | import net.minecraft.client.Minecraft; |
10 | | -import net.minecraft.client.gui.components.AbstractTextAreaWidget; |
11 | | -import net.minecraft.client.gui.components.EditBox; |
12 | | -import net.minecraft.client.gui.components.MultilineTextField; |
13 | 10 | import net.minecraft.resources.Identifier; |
14 | 11 | import net.minecraft.util.Util; |
15 | 12 | import net.neoforged.api.distmarker.Dist; |
16 | 13 | import net.neoforged.bus.api.SubscribeEvent; |
17 | 14 | import net.neoforged.fml.common.EventBusSubscriber; |
| 15 | +import net.neoforged.neoforge.client.event.ClientTickEvent; |
18 | 16 | import net.neoforged.neoforge.client.event.InputEvent; |
19 | 17 | import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; |
20 | 18 | import net.neoforged.neoforge.client.settings.KeyConflictContext; |
@@ -52,39 +50,31 @@ public static void onKeyInput(InputEvent.Key event) { |
52 | 50 | } |
53 | 51 |
|
54 | 52 | @SubscribeEvent |
55 | | - public static void mute(InputEvent.Key event) { |
| 53 | + public static void switchMute(InputEvent.Key event) { |
56 | 54 | var screen = Minecraft.getInstance().screen; |
57 | 55 | if (screen != null) { |
58 | 56 | return; |
59 | 57 | } |
60 | | - var cfg = ChannelClientConfig.get(); |
61 | | - if (event.getKey() == PTT.getKey().getValue() && modifierMatch(event.getModifiers(), PTT.getKeyModifier().codes())) { |
62 | | - if (event.getAction() == InputConstants.PRESS || event.getAction() == InputConstants.REPEAT) { |
63 | | - switch (cfg.trigger) { |
64 | | - case PUSH_TO_TALK -> ChannelClientConfig.write(c -> c.onAir = true); |
65 | | - case SWITCH -> { |
66 | | - if (Util.getMillis() - lastSwitch >= 100) { |
67 | | - ChannelClientConfig.write(c -> c.onAir = !c.onAir); |
68 | | - lastSwitch = Util.getMillis(); |
69 | | - } |
70 | | - } |
71 | | - default -> { |
72 | | - } |
73 | | - } |
74 | | - } else { |
75 | | - if (cfg.trigger == Trigger.PUSH_TO_TALK) { |
76 | | - ChannelClientConfig.write(c -> c.onAir = false); |
77 | | - } |
| 58 | + if (ChannelClientConfig.get().trigger != Trigger.SWITCH) { |
| 59 | + return; |
| 60 | + } |
| 61 | + if (PTT.consumeClick()) { |
| 62 | + if (Util.getMillis() - lastSwitch >= 100) { |
| 63 | + ChannelClientConfig.write(c -> c.onAir = !c.onAir); |
| 64 | + lastSwitch = Util.getMillis(); |
78 | 65 | } |
79 | 66 | } |
80 | 67 | } |
81 | 68 |
|
82 | | - public static boolean modifierMatch(int combined, InputConstants.Key[] modifiers) { |
83 | | - for (var m : modifiers) { |
84 | | - if (combined == m.getValue()) { |
85 | | - return true; |
86 | | - } |
| 69 | + @SubscribeEvent |
| 70 | + public static void pushMute(ClientTickEvent.Pre event) { |
| 71 | + var cfg = ChannelClientConfig.get(); |
| 72 | + if (cfg.trigger != Trigger.PUSH_TO_TALK) { |
| 73 | + return; |
| 74 | + } |
| 75 | + boolean toWrite = PTT.isDown(); |
| 76 | + if (toWrite != cfg.onAir) { |
| 77 | + ChannelClientConfig.write(c -> c.onAir = toWrite); |
87 | 78 | } |
88 | | - return combined == 0; |
89 | 79 | } |
90 | 80 | } |
0 commit comments