mirror of
https://github.com/neoforged/NeoForge.git
synced 2026-10-12 02:19:42 +00:00
Co-Authored-By: Dennis C <[email protected]> Co-Authored-By: RogueLogix <[email protected]>
128 lines
6.8 KiB
Diff
128 lines
6.8 KiB
Diff
--- a/net/minecraft/client/MouseHandler.java
|
|
+++ b/net/minecraft/client/MouseHandler.java
|
|
@@ -77,6 +_,8 @@
|
|
this.activeButton = null;
|
|
}
|
|
|
|
+ if (net.neoforged.neoforge.client.ClientHooks.onMouseButtonPre(rawButtonInfo, action)) return;
|
|
+ boolean screenHandled = false;
|
|
if (this.minecraft.gui.overlay() == null) {
|
|
if (pressed
|
|
&& this.minecraft
|
|
@@ -105,10 +_,14 @@
|
|
&& currentTime - this.lastClick.time() < 250L
|
|
&& this.lastClick.screen() == screen
|
|
&& this.lastClickButton == event.button();
|
|
- if (screen.mouseClicked(event, doubleClick)) {
|
|
+ screenHandled = net.neoforged.neoforge.client.ClientHooks.onScreenMouseClickedPre(screen, event, doubleClick);
|
|
+ if (!screenHandled) {
|
|
+ screenHandled = screen.mouseClicked(event, doubleClick);
|
|
+ screenHandled = net.neoforged.neoforge.client.ClientHooks.onScreenMouseClickedPost(screen, event, doubleClick, screenHandled);
|
|
+ }
|
|
+ if (screenHandled) {
|
|
this.lastClick = new MouseHandler.LastClick(currentTime, screen);
|
|
this.lastClickButton = buttonInfo.button();
|
|
- return;
|
|
}
|
|
} catch (Throwable t) {
|
|
CrashReport report = CrashReport.forThrowable(t, "mouseClicked event handler");
|
|
@@ -120,8 +_,10 @@
|
|
}
|
|
} else {
|
|
try {
|
|
- if (screen.mouseReleased(event)) {
|
|
- return;
|
|
+ screenHandled = net.neoforged.neoforge.client.ClientHooks.onScreenMouseReleasedPre(screen, event);
|
|
+ if (!screenHandled) {
|
|
+ screenHandled = screen.mouseReleased(event);
|
|
+ screenHandled = net.neoforged.neoforge.client.ClientHooks.onScreenMouseReleasedPost(screen, event, screenHandled);
|
|
}
|
|
} catch (Throwable t) {
|
|
CrashReport report = CrashReport.forThrowable(t, "mouseReleased event handler");
|
|
@@ -135,6 +_,10 @@
|
|
}
|
|
}
|
|
|
|
+ // Neo: we patch out the returns in the screen handler code to fire the mouse button post event
|
|
+ // therefore we add a boolean to check whether the screen handled the click and if not we let
|
|
+ // vanilla's fallback handle it
|
|
+ if (!screenHandled) {
|
|
if (this.minecraft.gui.screen() == null && this.minecraft.gui.overlay() == null) {
|
|
if (buttonInfo.button() == 0) {
|
|
this.isLeftPressed = pressed;
|
|
@@ -150,6 +_,8 @@
|
|
KeyMapping.click(mouseKey);
|
|
}
|
|
}
|
|
+ }
|
|
+ net.neoforged.neoforge.client.ClientHooks.onMouseButtonPost(rawButtonInfo, action);
|
|
}
|
|
}
|
|
|
|
@@ -201,7 +_,11 @@
|
|
if (this.minecraft.gui.screen() != null) {
|
|
double xm = this.getScaledXPos(this.minecraft.getWindow());
|
|
double ym = this.getScaledYPos(this.minecraft.getWindow());
|
|
- this.minecraft.gui.screen().mouseScrolled(xm, ym, scaledXOffset, scaledYOffset);
|
|
+ if (!net.neoforged.neoforge.client.ClientHooks.onScreenMouseScrollPre(this, this.minecraft.gui.screen(), scaledXOffset, scaledYOffset)) {
|
|
+ if (!this.minecraft.gui.screen().mouseScrolled(xm, ym, scaledXOffset, scaledYOffset)) {
|
|
+ net.neoforged.neoforge.client.ClientHooks.onScreenMouseScrollPost(this, this.minecraft.gui.screen(), scaledXOffset, scaledYOffset);
|
|
+ }
|
|
+ }
|
|
this.minecraft.gui.screen().afterMouseAction();
|
|
} else if (this.minecraft.player != null) {
|
|
Vector2i wheelXY = this.scrollWheelHandler.onMouseScroll(scaledXOffset, scaledYOffset);
|
|
@@ -210,6 +_,7 @@
|
|
}
|
|
|
|
int wheel = wheelXY.y == 0 ? -wheelXY.x : wheelXY.y;
|
|
+ if (net.neoforged.neoforge.client.ClientHooks.onMouseScroll(this, scaledXOffset, scaledYOffset)) return;
|
|
if (this.minecraft.player.isSpectator()) {
|
|
if (this.minecraft.gui.hud.getSpectatorGui().isMenuActive()) {
|
|
this.minecraft.gui.hud.getSpectatorGui().onMouseScrolled(-wheel);
|
|
@@ -316,7 +_,12 @@
|
|
double dy = getScaledYPos(window, this.accumulatedDY);
|
|
|
|
try {
|
|
- screen.mouseDragged(new MouseButtonEvent(xm, ym, this.activeButton), dx, dy);
|
|
+ MouseButtonEvent mouseButtonEvent = new MouseButtonEvent(xm, ym, this.activeButton);
|
|
+ if (!net.neoforged.neoforge.client.ClientHooks.onScreenMouseDragPre(screen, mouseButtonEvent, dx, dy)) {
|
|
+ if (!screen.mouseDragged(new MouseButtonEvent(xm, ym, this.activeButton), dx, dy)) {
|
|
+ net.neoforged.neoforge.client.ClientHooks.onScreenMouseDragPost(screen, mouseButtonEvent, dx, dy);
|
|
+ }
|
|
+ }
|
|
} catch (Throwable t) {
|
|
CrashReport report = CrashReport.forThrowable(t, "mouseDragged event handler");
|
|
screen.fillCrashDetails(report);
|
|
@@ -355,12 +_,13 @@
|
|
}
|
|
|
|
private void turnPlayer(double mousea) {
|
|
- double ss = this.minecraft.options.sensitivity().get() * 0.6F + 0.2F;
|
|
+ var event = net.neoforged.neoforge.client.ClientHooks.getTurnPlayerValues(this.minecraft.options.sensitivity().get(), this.minecraft.options.smoothCamera);
|
|
+ double ss = event.getMouseSensitivity() * 0.6F + 0.2F;
|
|
double sensitivityMod = ss * ss * ss;
|
|
double sens = sensitivityMod * 8.0;
|
|
double xo;
|
|
double yo;
|
|
- if (this.minecraft.options.smoothCamera) {
|
|
+ if (event.getCinematicCameraEnabled()) {
|
|
double dx = this.smoothTurnX.getNewDeltaValue(this.accumulatedDX * sens, mousea * sens);
|
|
double dy = this.smoothTurnY.getNewDeltaValue(this.accumulatedDY * sens, mousea * sens);
|
|
xo = dx;
|
|
@@ -401,6 +_,14 @@
|
|
|
|
public double ypos() {
|
|
return this.ypos;
|
|
+ }
|
|
+
|
|
+ public double getXVelocity() {
|
|
+ return this.accumulatedDX;
|
|
+ }
|
|
+
|
|
+ public double getYVelocity() {
|
|
+ return this.accumulatedDY;
|
|
}
|
|
|
|
public void setIgnoreFirstMove() {
|