114 lines
4.2 KiB
Java
114 lines
4.2 KiB
Java
package dev.pfaff.thinksame.mixin;
|
|
|
|
import net.minecraft.client.MinecraftClient;
|
|
import net.minecraft.client.Mouse;
|
|
import net.minecraft.client.gui.screen.Screen;
|
|
import net.minecraft.client.options.KeyBinding;
|
|
import net.minecraft.client.util.GlfwUtil;
|
|
import net.minecraft.client.util.InputUtil;
|
|
import org.spongepowered.asm.mixin.Final;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Overwrite;
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
|
|
// TODO: modify injection to not overwrite whole method.
|
|
@Mixin(Mouse.class)
|
|
public abstract class MouseMixin {
|
|
@Shadow @Final private MinecraftClient client;
|
|
|
|
@Shadow private int field_1796;
|
|
|
|
@Shadow private int activeButton;
|
|
|
|
@Shadow private double glfwTime;
|
|
|
|
@Shadow private boolean cursorLocked;
|
|
|
|
@Shadow public abstract void lockCursor();
|
|
|
|
@Shadow private double x;
|
|
|
|
@Shadow private double y;
|
|
|
|
@Shadow private boolean leftButtonClicked;
|
|
|
|
@Shadow private boolean middleButtonClicked;
|
|
|
|
@Shadow private boolean rightButtonClicked;
|
|
|
|
@SuppressWarnings("OverwriteAuthorRequired")
|
|
@Overwrite
|
|
private void onMouseButton(long window, int button, int action, int mods) {
|
|
if (window == this.client.getWindow().getHandle()) {
|
|
boolean bl = action == 1;
|
|
// if (MinecraftClient.IS_SYSTEM_MAC && button == 0) {
|
|
// if (bl) {
|
|
// if ((mods & 2) == 2) {
|
|
// button = 1;
|
|
// ++this.controlLeftTicks;
|
|
// }
|
|
// } else if (this.controlLeftTicks > 0) {
|
|
// button = 1;
|
|
// --this.controlLeftTicks;
|
|
// }
|
|
// }
|
|
|
|
if (bl) {
|
|
if (this.client.options.touchscreen && this.field_1796++ > 0) {
|
|
return;
|
|
}
|
|
|
|
this.activeButton = button;
|
|
this.glfwTime = GlfwUtil.getTime();
|
|
} else if (this.activeButton != -1) {
|
|
if (this.client.options.touchscreen && --this.field_1796 > 0) {
|
|
return;
|
|
}
|
|
|
|
this.activeButton = -1;
|
|
}
|
|
|
|
boolean[] bls = new boolean[]{false};
|
|
if (this.client.overlay == null) {
|
|
if (this.client.currentScreen == null) {
|
|
if (!this.cursorLocked && bl) {
|
|
this.lockCursor();
|
|
}
|
|
} else {
|
|
double d = this.x * (double)this.client.getWindow().getScaledWidth() / (double)this.client.getWindow().getWidth();
|
|
double e = this.y * (double)this.client.getWindow().getScaledHeight() / (double)this.client.getWindow().getHeight();
|
|
if (bl) {
|
|
Screen.wrapScreenError(() -> {
|
|
bls[0] = this.client.currentScreen.mouseClicked(d, e, button);
|
|
}, "mouseClicked event handler", this.client.currentScreen.getClass().getCanonicalName());
|
|
} else {
|
|
Screen.wrapScreenError(() -> {
|
|
bls[0] = this.client.currentScreen.mouseReleased(d, e, button);
|
|
}, "mouseReleased event handler", this.client.currentScreen.getClass().getCanonicalName());
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!bls[0] && (this.client.currentScreen == null || this.client.currentScreen.passEvents) && this.client.overlay == null) {
|
|
if (button == 0) {
|
|
this.leftButtonClicked = bl;
|
|
} else if (button == 2) {
|
|
this.middleButtonClicked = bl;
|
|
} else if (button == 1) {
|
|
this.rightButtonClicked = bl;
|
|
}
|
|
|
|
KeyBinding.setKeyPressed(InputUtil.Type.MOUSE.createFromCode(button), bl);
|
|
if (bl) {
|
|
if (this.client.player.isSpectator() && button == 2) {
|
|
this.client.inGameHud.getSpectatorHud().useSelectedCommand();
|
|
} else {
|
|
KeyBinding.onKeyPressed(InputUtil.Type.MOUSE.createFromCode(button));
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|