Skip to content

Commit ee0fbdd

Browse files
committed
Update KeyEvent and MouseButtonEvent (now MouseClickEvent) to account for the new input changes
1 parent cc19351 commit ee0fbdd

File tree

22 files changed

+132
-151
lines changed

22 files changed

+132
-151
lines changed

src/main/java/meteordevelopment/meteorclient/MeteorClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import meteordevelopment.meteorclient.addons.MeteorAddon;
1010
import meteordevelopment.meteorclient.events.game.OpenScreenEvent;
1111
import meteordevelopment.meteorclient.events.meteor.KeyEvent;
12-
import meteordevelopment.meteorclient.events.meteor.MouseButtonEvent;
12+
import meteordevelopment.meteorclient.events.meteor.MouseClickEvent;
1313
import meteordevelopment.meteorclient.events.world.TickEvent;
1414
import meteordevelopment.meteorclient.gui.GuiThemes;
1515
import meteordevelopment.meteorclient.gui.WidgetScreen;
@@ -156,14 +156,14 @@ private void onTick(TickEvent.Post event) {
156156

157157
@EventHandler
158158
private void onKey(KeyEvent event) {
159-
if (event.action == KeyAction.Press && KeyBinds.OPEN_GUI.matchesKey(event.arg)) {
159+
if (event.action == KeyAction.Press && KeyBinds.OPEN_GUI.matchesKey(event.input)) {
160160
toggleGui();
161161
}
162162
}
163163

164164
@EventHandler
165-
private void onMouseButton(MouseButtonEvent event) {
166-
if (event.action == KeyAction.Press && KeyBinds.OPEN_GUI.matchesMouse(event.arg)) {
165+
private void onMouseClick(MouseClickEvent event) {
166+
if (event.action == KeyAction.Press && KeyBinds.OPEN_GUI.matchesMouse(event.click)) {
167167
toggleGui();
168168
}
169169
}

src/main/java/meteordevelopment/meteorclient/commands/commands/SpectateCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import meteordevelopment.meteorclient.commands.Command;
1111
import meteordevelopment.meteorclient.commands.arguments.PlayerArgumentType;
1212
import meteordevelopment.meteorclient.events.meteor.KeyEvent;
13-
import meteordevelopment.meteorclient.events.meteor.MouseButtonEvent;
13+
import meteordevelopment.meteorclient.events.meteor.MouseClickEvent;
1414
import meteordevelopment.meteorclient.utils.misc.input.Input;
1515
import meteordevelopment.orbit.EventHandler;
1616
import net.minecraft.command.CommandSource;
@@ -50,7 +50,7 @@ private void onKey(KeyEvent event) {
5050
}
5151

5252
@EventHandler
53-
private void onMouse(MouseButtonEvent event) {
53+
private void onMouse(MouseClickEvent event) {
5454
if (Input.isPressed(mc.options.sneakKey)) {
5555
mc.setCameraEntity(mc.player);
5656
event.cancel();

src/main/java/meteordevelopment/meteorclient/events/meteor/KeyEvent.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@
1212
public class KeyEvent extends Cancellable {
1313
private static final KeyEvent INSTANCE = new KeyEvent();
1414

15-
public int key, modifiers;
15+
public KeyInput input;
1616
public KeyAction action;
17-
public KeyInput arg;
1817

19-
// todo clean this up
20-
public static KeyEvent get(KeyInput arg, int key, int modifiers, KeyAction action) {
18+
public static KeyEvent get(KeyInput keyInput, KeyAction action) {
2119
INSTANCE.setCancelled(false);
22-
INSTANCE.arg = arg;
23-
INSTANCE.key = key;
24-
INSTANCE.modifiers = modifiers;
20+
INSTANCE.input = keyInput;
2521
INSTANCE.action = action;
2622
return INSTANCE;
2723
}

src/main/java/meteordevelopment/meteorclient/events/meteor/MouseButtonEvent.java renamed to src/main/java/meteordevelopment/meteorclient/events/meteor/MouseClickEvent.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
import meteordevelopment.meteorclient.events.Cancellable;
99
import meteordevelopment.meteorclient.utils.misc.input.KeyAction;
1010
import net.minecraft.client.gui.Click;
11+
import net.minecraft.client.input.MouseInput;
1112

12-
public class MouseButtonEvent extends Cancellable {
13-
private static final MouseButtonEvent INSTANCE = new MouseButtonEvent();
13+
public class MouseClickEvent extends Cancellable {
14+
private static final MouseClickEvent INSTANCE = new MouseClickEvent();
1415

15-
public int button;
16+
public MouseInput input;
17+
public Click click;
1618
public KeyAction action;
17-
public Click arg;
1819

19-
// todo cleanup
20-
public static MouseButtonEvent get(Click arg, int button, KeyAction action) {
20+
public static MouseClickEvent get(MouseInput mouseInput, Click click, KeyAction action) {
2121
INSTANCE.setCancelled(false);
22-
INSTANCE.arg = arg;
23-
INSTANCE.button = button;
22+
INSTANCE.input = mouseInput;
23+
INSTANCE.click = click;
2424
INSTANCE.action = action;
2525
return INSTANCE;
2626
}

src/main/java/meteordevelopment/meteorclient/mixin/KeyboardMixin.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ public abstract class KeyboardMixin {
3030
@Shadow @Final private MinecraftClient client;
3131

3232
@Inject(method = "onKey", at = @At("HEAD"), cancellable = true)
33-
public void onKey(long window, int action, KeyInput arg, CallbackInfo ci) {
34-
int modifiers = arg.modifiers();
35-
if (arg.key() != GLFW.GLFW_KEY_UNKNOWN) {
33+
public void onKey(long window, int action, KeyInput keyEvent, CallbackInfo ci) {
34+
int modifiers = keyEvent.modifiers();
35+
if (keyEvent.key() != GLFW.GLFW_KEY_UNKNOWN) {
3636
// on Linux/X11 the modifier is not active when the key is pressed and still active when the key is released
3737
// https://github.com/glfw/glfw/issues/1630
3838
if (action == GLFW.GLFW_PRESS) {
39-
modifiers |= Input.getModifier(arg.key());
39+
modifiers |= Input.getModifier(keyEvent.key());
4040
} else if (action == GLFW.GLFW_RELEASE) {
41-
modifiers &= ~Input.getModifier(arg.key());
41+
modifiers &= ~Input.getModifier(keyEvent.key());
4242
}
4343

4444
if (client.currentScreen instanceof WidgetScreen && action == GLFW.GLFW_REPEAT) {
45-
((WidgetScreen) client.currentScreen).keyRepeated(arg.key(), modifiers);
45+
((WidgetScreen) client.currentScreen).keyRepeated(keyEvent.key(), modifiers);
4646
}
4747

4848
if (GuiKeyEvents.canUseKeys) {
49-
Input.setKeyState(arg.key(), action != GLFW.GLFW_RELEASE);
50-
if (MeteorClient.EVENT_BUS.post(KeyEvent.get(arg, arg.key(), modifiers, KeyAction.get(action))).isCancelled()) ci.cancel();
49+
Input.setKeyState(keyEvent.key(), action != GLFW.GLFW_RELEASE);
50+
if (MeteorClient.EVENT_BUS.post(KeyEvent.get(keyEvent, KeyAction.get(action))).isCancelled()) ci.cancel();
5151
}
5252
}
5353
}

src/main/java/meteordevelopment/meteorclient/mixin/MouseMixin.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
package meteordevelopment.meteorclient.mixin;
77

88
import meteordevelopment.meteorclient.MeteorClient;
9-
import meteordevelopment.meteorclient.events.meteor.MouseButtonEvent;
9+
import meteordevelopment.meteorclient.events.meteor.MouseClickEvent;
1010
import meteordevelopment.meteorclient.events.meteor.MouseScrollEvent;
1111
import meteordevelopment.meteorclient.utils.misc.input.Input;
1212
import meteordevelopment.meteorclient.utils.misc.input.KeyAction;
@@ -37,10 +37,11 @@ public abstract class MouseMixin {
3737
private MinecraftClient client;
3838

3939
@Inject(method = "onMouseButton", at = @At("HEAD"), cancellable = true)
40-
private void onMouseButton(long window, MouseInput arg, int action, CallbackInfo ci) {
41-
Input.setButtonState(arg.button(), action != GLFW_RELEASE);
40+
private void onMouseButton(long window, MouseInput mouseInput, int action, CallbackInfo ci) {
41+
Input.setButtonState(mouseInput.button(), action != GLFW_RELEASE);
4242

43-
if (MeteorClient.EVENT_BUS.post(MouseButtonEvent.get(new Click(getScaledX(client.getWindow()), getScaledY(client.getWindow()), arg), arg.button(), KeyAction.get(action))).isCancelled()) ci.cancel();
43+
Click click = new Click(getScaledX(client.getWindow()), getScaledY(client.getWindow()), mouseInput);
44+
if (MeteorClient.EVENT_BUS.post(MouseClickEvent.get(mouseInput, click, KeyAction.get(action))).isCancelled()) ci.cancel();
4445
}
4546

4647
@Inject(method = "onMouseScroll", at = @At("HEAD"), cancellable = true)

src/main/java/meteordevelopment/meteorclient/settings/KeybindSetting.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import meteordevelopment.meteorclient.MeteorClient;
99
import meteordevelopment.meteorclient.events.meteor.KeyEvent;
10-
import meteordevelopment.meteorclient.events.meteor.MouseButtonEvent;
10+
import meteordevelopment.meteorclient.events.meteor.MouseClickEvent;
1111
import meteordevelopment.meteorclient.gui.widgets.WKeybind;
1212
import meteordevelopment.meteorclient.utils.misc.Keybind;
1313
import meteordevelopment.meteorclient.utils.misc.input.KeyAction;
@@ -32,25 +32,25 @@ public KeybindSetting(String name, String description, Keybind defaultValue, Con
3232
@EventHandler(priority = EventPriority.HIGHEST)
3333
private void onKeyBinding(KeyEvent event) {
3434
if (widget == null) return;
35-
if (event.action == KeyAction.Press && event.key == GLFW.GLFW_KEY_ESCAPE && widget.onClear()) event.cancel();
36-
else if (event.action == KeyAction.Release && widget.onAction(true, event.key, event.modifiers)) event.cancel();
35+
if (event.action == KeyAction.Press && event.input.key() == GLFW.GLFW_KEY_ESCAPE && widget.onClear()) event.cancel();
36+
else if (event.action == KeyAction.Release && widget.onAction(true, event.input.key(), event.input.modifiers())) event.cancel();
3737
}
3838

3939
@EventHandler(priority = EventPriority.HIGHEST)
40-
private void onMouseButtonBinding(MouseButtonEvent event) {
41-
if (event.action == KeyAction.Press && widget != null && widget.onAction(false, event.button, 0)) event.cancel();
40+
private void onMouseClickBinding(MouseClickEvent event) {
41+
if (event.action == KeyAction.Press && widget != null && widget.onAction(false, event.input.button(), 0)) event.cancel();
4242
}
4343

4444
@EventHandler(priority = EventPriority.HIGH)
4545
private void onKey(KeyEvent event) {
46-
if (event.action == KeyAction.Release && get().matches(true, event.key, event.modifiers) && (module == null || module.isActive()) && action != null) {
46+
if (event.action == KeyAction.Release && get().matches(event.input) && (module == null || module.isActive()) && action != null) {
4747
action.run();
4848
}
4949
}
5050

5151
@EventHandler(priority = EventPriority.HIGH)
52-
private void onMouseButton(MouseButtonEvent event) {
53-
if (event.action == KeyAction.Release && get().matches(false, event.button, 0) && (module == null || module.isActive()) && action != null) {
52+
private void onMouseClick(MouseClickEvent event) {
53+
if (event.action == KeyAction.Release && get().matches(event.input) && (module == null || module.isActive()) && action != null) {
5454
action.run();
5555
}
5656
}

src/main/java/meteordevelopment/meteorclient/systems/macros/Macros.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import meteordevelopment.meteorclient.MeteorClient;
99
import meteordevelopment.meteorclient.events.meteor.KeyEvent;
10-
import meteordevelopment.meteorclient.events.meteor.MouseButtonEvent;
10+
import meteordevelopment.meteorclient.events.meteor.MouseClickEvent;
1111
import meteordevelopment.meteorclient.systems.System;
1212
import meteordevelopment.meteorclient.systems.Systems;
1313
import meteordevelopment.meteorclient.utils.misc.NbtUtils;
@@ -62,16 +62,16 @@ private void onKey(KeyEvent event) {
6262
if (event.action == KeyAction.Release) return;
6363

6464
for (Macro macro : macros) {
65-
if (macro.onAction(true, event.key, event.modifiers)) return;
65+
if (macro.onAction(true, event.input.key(), event.input.modifiers())) return;
6666
}
6767
}
6868

6969
@EventHandler(priority = EventPriority.HIGH)
70-
private void onButton(MouseButtonEvent event) {
70+
private void onMouse(MouseClickEvent event) {
7171
if (event.action == KeyAction.Release) return;
7272

7373
for (Macro macro : macros) {
74-
if (macro.onAction(false, event.button, 0)) return;
74+
if (macro.onAction(false, event.input.button(), 0)) return;
7575
}
7676
}
7777

src/main/java/meteordevelopment/meteorclient/systems/modules/Modules.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import meteordevelopment.meteorclient.events.meteor.ActiveModulesChangedEvent;
1414
import meteordevelopment.meteorclient.events.meteor.KeyEvent;
1515
import meteordevelopment.meteorclient.events.meteor.ModuleBindChangedEvent;
16-
import meteordevelopment.meteorclient.events.meteor.MouseButtonEvent;
16+
import meteordevelopment.meteorclient.events.meteor.MouseClickEvent;
1717
import meteordevelopment.meteorclient.pathing.BaritoneUtils;
1818
import meteordevelopment.meteorclient.settings.Setting;
1919
import meteordevelopment.meteorclient.settings.SettingGroup;
@@ -222,12 +222,12 @@ public boolean isBinding() {
222222

223223
@EventHandler(priority = EventPriority.HIGHEST)
224224
private void onKeyBinding(KeyEvent event) {
225-
if (event.action == KeyAction.Release && onBinding(true, event.key, event.modifiers)) event.cancel();
225+
if (event.action == KeyAction.Release && onBinding(true, event.input.key(), event.input.modifiers())) event.cancel();
226226
}
227227

228228
@EventHandler(priority = EventPriority.HIGHEST)
229-
private void onButtonBinding(MouseButtonEvent event) {
230-
if (event.action == KeyAction.Release && onBinding(false, event.button, 0)) event.cancel();
229+
private void onButtonBinding(MouseClickEvent event) {
230+
if (event.action == KeyAction.Release && onBinding(false, event.input.button(), 0)) event.cancel();
231231
}
232232

233233
private boolean onBinding(boolean isKey, int value, int modifiers) {
@@ -259,13 +259,13 @@ else if (value == GLFW.GLFW_KEY_ESCAPE) {
259259
@EventHandler(priority = EventPriority.HIGH)
260260
private void onKey(KeyEvent event) {
261261
if (event.action == KeyAction.Repeat) return;
262-
onAction(true, event.key, event.modifiers, event.action == KeyAction.Press);
262+
onAction(true, event.input.key(), event.input.modifiers(), event.action == KeyAction.Press);
263263
}
264264

265265
@EventHandler(priority = EventPriority.HIGH)
266-
private void onMouseButton(MouseButtonEvent event) {
266+
private void onMouseClick(MouseClickEvent event) {
267267
if (event.action == KeyAction.Repeat) return;
268-
onAction(false, event.button, 0, event.action == KeyAction.Press);
268+
onAction(false, event.input.button(), 0, event.action == KeyAction.Press);
269269
}
270270

271271
private void onAction(boolean isKey, int value, int modifiers, boolean isPress) {

src/main/java/meteordevelopment/meteorclient/systems/modules/combat/Burrow.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private void onTick(TickEvent.Pre event) {
165165
if (!shouldBurrow && instant.get()) blockPos.set(mc.player.getBlockPos());
166166

167167
if (shouldBurrow) {
168-
if (rotate.get())
168+
if (rotate.get())
169169
Rotations.rotate(Rotations.getYaw(mc.player.getBlockPos()), Rotations.getPitch(mc.player.getBlockPos()), 50, this::burrow);
170170
else burrow();
171171

@@ -176,7 +176,7 @@ private void onTick(TickEvent.Pre event) {
176176
@EventHandler
177177
private void onKey(KeyEvent event) {
178178
if (instant.get() && !shouldBurrow) {
179-
if (event.action == KeyAction.Press && mc.options.jumpKey.matchesKey(event.arg)) {
179+
if (event.action == KeyAction.Press && mc.options.jumpKey.matchesKey(event.input)) {
180180
shouldBurrow = true;
181181
}
182182
blockPos.set(mc.player.getBlockPos());

0 commit comments

Comments
 (0)