Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with Mouse and Keyboard actions crashing client on launch. #40

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/main/java/net/aoba/mixin/KeyboardMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.aoba.Aoba;
import net.aoba.AobaClient;
import net.aoba.event.events.KeyDownEvent;
import net.minecraft.client.Keyboard;

Expand All @@ -34,11 +35,14 @@ public class KeyboardMixin {
@Inject(at = {@At("HEAD")}, method = {"onKey(JIIII)V" }, cancellable = true)
private void OnKeyDown(long window, int key, int scancode,
int action, int modifiers, CallbackInfo ci) {
if(action == GLFW.GLFW_PRESS) {
KeyDownEvent event = new KeyDownEvent(window, key, scancode, action, modifiers);
Aoba.getInstance().eventManager.Fire(event);
if(event.IsCancelled()) {
ci.cancel();
AobaClient aoba = Aoba.getInstance();
if(aoba != null && aoba.eventManager != null) {
if(action == GLFW.GLFW_PRESS) {
KeyDownEvent event = new KeyDownEvent(window, key, scancode, action, modifiers);
Aoba.getInstance().eventManager.Fire(event);
if(event.IsCancelled()) {
ci.cancel();
}
}
}
}
Expand Down
50 changes: 28 additions & 22 deletions src/main/java/net/aoba/mixin/MouseMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,43 @@ public class MouseMixin {

@Inject(at = { @At("HEAD") }, method = { "onMouseButton(JIII)V" }, cancellable = true)
private void onMouseButton(long window, int button, int action, int mods, CallbackInfo ci) {
switch (button) {
case GLFW.GLFW_MOUSE_BUTTON_LEFT:
if (action == 1) {
LeftMouseDownEvent event = new LeftMouseDownEvent(x, y);
Aoba.getInstance().eventManager.Fire(event);
AobaClient aoba = Aoba.getInstance();
if(aoba != null && aoba.eventManager != null) {
switch (button) {
case GLFW.GLFW_MOUSE_BUTTON_LEFT:
if (action == 1) {
LeftMouseDownEvent event = new LeftMouseDownEvent(x, y);
aoba.eventManager.Fire(event);

if (event.IsCancelled()) {
ci.cancel();
}
} else {
LeftMouseUpEvent event = new LeftMouseUpEvent(x, y);
Aoba.getInstance().eventManager.Fire(event);
if (event.IsCancelled()) {
ci.cancel();
}
} else {
LeftMouseUpEvent event = new LeftMouseUpEvent(x, y);
aoba.eventManager.Fire(event);

if (event.IsCancelled()) {
ci.cancel();
if (event.IsCancelled()) {
ci.cancel();
}
}
}
break;
case GLFW.GLFW_MOUSE_BUTTON_MIDDLE:
break;
case GLFW.GLFW_MOUSE_BUTTON_MIDDLE:

break;
break;
}
}
}

@Inject(at = { @At("HEAD") }, method = { "onMouseScroll(JDD)V" }, cancellable = true)
private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci) {
MouseScrollEvent event = new MouseScrollEvent(horizontal, vertical);
Aoba.getInstance().eventManager.Fire(event);
AobaClient aoba = Aoba.getInstance();
if(aoba != null && aoba.eventManager != null) {
MouseScrollEvent event = new MouseScrollEvent(horizontal, vertical);
aoba.eventManager.Fire(event);

if (event.IsCancelled()) {
ci.cancel();
if (event.IsCancelled()) {
ci.cancel();
}
}
}

Expand All @@ -84,7 +90,7 @@ private void onLockCursor(CallbackInfo ci) {
@Inject(at = { @At("HEAD") }, method = { "onCursorPos(JDD)V" }, cancellable = true)
private void onCursorPos(long window, double x, double y, CallbackInfo ci) {
AobaClient aoba = Aoba.getInstance();
if(aoba.eventManager != null) {
if(aoba != null && aoba.eventManager != null) {
MouseMoveEvent event = new MouseMoveEvent(x, y);
aoba.eventManager.Fire(event);

Expand Down
Loading