|
21 | 21 | import com.lambda.event.events.MouseEvent; |
22 | 22 | import com.lambda.module.modules.render.Zoom; |
23 | 23 | import com.lambda.util.math.Vec2d; |
| 24 | +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; |
| 25 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
24 | 26 | import net.minecraft.client.Mouse; |
25 | 27 | import net.minecraft.client.option.GameOptions; |
26 | 28 | import net.minecraft.client.option.SimpleOption; |
27 | 29 | import org.spongepowered.asm.mixin.Mixin; |
28 | 30 | import org.spongepowered.asm.mixin.Shadow; |
29 | 31 | import org.spongepowered.asm.mixin.injection.At; |
30 | | -import org.spongepowered.asm.mixin.injection.Inject; |
31 | 32 | import org.spongepowered.asm.mixin.injection.Redirect; |
32 | | -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
33 | 33 |
|
34 | 34 | @Mixin(Mouse.class) |
35 | 35 | public class MouseMixin { |
36 | 36 | @Shadow private double x; |
37 | 37 |
|
38 | 38 | @Shadow private double y; |
39 | 39 |
|
40 | | - @Inject(method = "onMouseButton(JIII)V", at = @At("HEAD"), cancellable = true) |
41 | | - private void onMouseButton(long window, int button, int action, int mods, CallbackInfo ci) { |
42 | | - Vec2d position = new Vec2d(x, y); |
43 | | - |
44 | | - if (EventFlow.post(new MouseEvent.Click(button, action, mods, position)).isCanceled()) { |
45 | | - ci.cancel(); |
46 | | - } |
| 40 | + @WrapMethod(method = "onMouseButton(JIII)V") |
| 41 | + private void onMouseButton(long window, int button, int action, int mods, Operation<Void> original) { |
| 42 | + if (!EventFlow.post(new MouseEvent.Click(button, action, mods)).isCanceled()) |
| 43 | + original.call(window, button, action, mods); |
47 | 44 | } |
48 | 45 |
|
49 | | - @Inject(method = "onMouseScroll(JDD)V", at = @At("HEAD"), cancellable = true) |
50 | | - private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci) { |
| 46 | + @WrapMethod(method = "onMouseScroll(JDD)V") |
| 47 | + private void onMouseScroll(long window, double horizontal, double vertical, Operation<Void> original) { |
51 | 48 | Vec2d delta = new Vec2d(horizontal, vertical); |
52 | 49 |
|
53 | | - if (EventFlow.post(new MouseEvent.Scroll(delta)).isCanceled()) { |
54 | | - ci.cancel(); |
55 | | - } |
| 50 | + if (!EventFlow.post(new MouseEvent.Scroll(delta)).isCanceled()) |
| 51 | + original.call(window, horizontal, vertical); |
56 | 52 | } |
57 | 53 |
|
58 | | - @Inject(method = "onCursorPos(JDD)V", at = @At("HEAD"), cancellable = true) |
59 | | - private void onCursorPos(long window, double x, double y, CallbackInfo ci) { |
| 54 | + @WrapMethod(method = "onCursorPos(JDD)V") |
| 55 | + private void onCursorPos(long window, double x, double y, Operation<Void> original) { |
60 | 56 | if (x + y == this.x + this.y) return; |
61 | 57 |
|
62 | 58 | Vec2d position = new Vec2d(x, y); |
63 | 59 |
|
64 | | - if (EventFlow.post(new MouseEvent.Move(position)).isCanceled()) { |
65 | | - ci.cancel(); |
66 | | - } |
| 60 | + if (!EventFlow.post(new MouseEvent.Move(position)).isCanceled()) |
| 61 | + original.call(window, x, y); |
67 | 62 | } |
68 | 63 |
|
69 | 64 | @Redirect(method = "updateMouse", at = @At(value = "FIELD", target = "Lnet/minecraft/client/option/GameOptions;smoothCameraEnabled:Z")) |
|
0 commit comments