77import org .spongepowered .asm .mixin .injection .At ;
88import org .spongepowered .asm .mixin .injection .Inject ;
99import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
10+ import net .minecraft .client .util .Window ;
1011
1112@ Mixin (MinecraftClient .class )
1213public class MinecraftClientMixin {
1314 private MinecraftClient client ;
1415 private double eventDeltaWheel ;
16+ private boolean mixinConfigured ;
1517
16- @ Inject (at = @ At ("RETURN" ), method = "init " )
18+ @ Inject (at = @ At ("RETURN" ), method = "openScreen " )
1719 private void init (CallbackInfo info ) {
18- this .client = MinecraftClient .getInstance ();
19- this .eventDeltaWheel = 0.0D ;
20- // Override MC scroll callback with our own
21- GLFW .glfwSetScrollCallback (this .client .window .getHandle (), this ::onMouseScroll );
20+ if (!mixinConfigured ) {
21+ this .client = MinecraftClient .getInstance ();
22+ this .eventDeltaWheel = 0.0D ;
23+ // Override MC scroll callback with our own
24+ GLFW .glfwSetScrollCallback (this .client .getWindow ().getHandle (), this ::onMouseScroll );
25+ }
26+ mixinConfigured = true ;
2227 }
2328
2429 private void onMouseScroll (long window , double xoffset , double yoffset ) {
2530 // TODO: implement these as minecraft settings?
2631 boolean translateHorizontalScroll = true ;
2732 double horizontalScrollSensitivity = 1.0D ;
2833
29- if (window == MinecraftClient .getInstance ().window .getHandle ()) {
34+ if (window == MinecraftClient .getInstance ().getWindow () .getHandle ()) {
3035 double delta ;
3136
3237 if (translateHorizontalScroll ) {
@@ -42,11 +47,13 @@ private void onMouseScroll(long window, double xoffset, double yoffset) {
4247 }
4348
4449 if (this .client .overlay == null ) {
50+ Window clientWindow = MinecraftClient .getInstance ().getWindow ();
51+
4552 if (this .client .currentScreen != null ) {
46- double xposition = this .client .mouse .getX () * (double ) this . client . window .getScaledWidth ()
47- / (double ) this . client . window .getWidth ();
48- double yposition = this .client .mouse .getY () * (double ) this . client . window .getScaledHeight ()
49- / (double ) this . client . window .getHeight ();
53+ double xposition = this .client .mouse .getX () * (double ) clientWindow .getScaledWidth ()
54+ / (double ) clientWindow .getWidth ();
55+ double yposition = this .client .mouse .getY () * (double ) clientWindow .getScaledHeight ()
56+ / (double ) clientWindow .getHeight ();
5057 this .client .currentScreen .mouseScrolled (xposition , yposition , delta );
5158 } else if (this .client .player != null ) {
5259 if (this .eventDeltaWheel != 0.0D && Math .signum (delta ) != Math .signum (this .eventDeltaWheel )) {
@@ -61,13 +68,13 @@ private void onMouseScroll(long window, double xoffset, double yoffset) {
6168
6269 this .eventDeltaWheel -= (double ) currentWheelDelta ;
6370 if (this .client .player .isSpectator ()) {
64- if (this .client .inGameHud .getSpectatorWidget ().method_1980 ()) {
65- this .client .inGameHud .getSpectatorWidget ().method_1976 ((double ) (-currentWheelDelta ));
71+ if (this .client .inGameHud .getSpectatorHud ().isOpen ()) {
72+ this .client .inGameHud .getSpectatorHud ().cycleSlot ((double ) (-currentWheelDelta ));
6673 } else {
67- float float_2 = MathHelper .clamp (
74+ float j = MathHelper .clamp (
6875 this .client .player .abilities .getFlySpeed () + currentWheelDelta * 0.005F , 0.0F ,
6976 0.2F );
70- this .client .player .abilities .setFlySpeed (float_2 );
77+ this .client .player .abilities .setFlySpeed (j );
7178 }
7279 } else {
7380 this .client .player .inventory .scrollInHotbar ((double ) currentWheelDelta );
0 commit comments