55
66package meteordevelopment .meteorclient .systems .modules .movement ;
77
8- import meteordevelopment .meteorclient .MeteorClient ;
9- import meteordevelopment .meteorclient .events .entity .player .PlayerTickMovementEvent ;
8+ import meteordevelopment .meteorclient .events .game .OpenScreenEvent ;
109import meteordevelopment .meteorclient .events .meteor .KeyEvent ;
10+ import meteordevelopment .meteorclient .events .meteor .MouseButtonEvent ;
1111import meteordevelopment .meteorclient .events .render .Render3DEvent ;
1212import meteordevelopment .meteorclient .gui .WidgetScreen ;
1313import meteordevelopment .meteorclient .mixin .CreativeInventoryScreenAccessor ;
14- import meteordevelopment .meteorclient .mixin .KeyBindingAccessor ;
1514import meteordevelopment .meteorclient .settings .*;
1615import meteordevelopment .meteorclient .systems .modules .Categories ;
1716import meteordevelopment .meteorclient .systems .modules .Module ;
17+ import meteordevelopment .meteorclient .systems .modules .Modules ;
18+ import meteordevelopment .meteorclient .systems .modules .render .Freecam ;
1819import meteordevelopment .meteorclient .utils .misc .input .Input ;
1920import meteordevelopment .meteorclient .utils .misc .input .KeyAction ;
2021import meteordevelopment .orbit .EventHandler ;
22+ import meteordevelopment .orbit .EventPriority ;
2123import net .minecraft .client .gui .screen .ChatScreen ;
2224import net .minecraft .client .gui .screen .ingame .*;
2325import net .minecraft .client .option .KeyBinding ;
24- import net .minecraft .client .util .InputUtil ;
2526import net .minecraft .item .ItemGroups ;
2627import net .minecraft .util .math .MathHelper ;
2728
@@ -43,22 +44,22 @@ public enum Screens {
4344 .build ()
4445 );
4546
46- private final Setting <Boolean > jump = sgGeneral .add (new BoolSetting .Builder ()
47+ public final Setting <Boolean > jump = sgGeneral .add (new BoolSetting .Builder ()
4748 .name ("jump" )
4849 .description ("Allows you to jump while in GUIs." )
4950 .defaultValue (true )
5051 .onChanged (aBoolean -> {
51- if (isActive () && !aBoolean ) set ( mc .options .jumpKey , false );
52+ if (isActive () && !aBoolean ) mc .options .jumpKey . setPressed ( false );
5253 })
5354 .build ()
5455 );
5556
56- private final Setting <Boolean > sneak = sgGeneral .add (new BoolSetting .Builder ()
57+ public final Setting <Boolean > sneak = sgGeneral .add (new BoolSetting .Builder ()
5758 .name ("sneak" )
5859 .description ("Allows you to sneak while in GUIs." )
5960 .defaultValue (true )
6061 .onChanged (aBoolean -> {
61- if (isActive () && !aBoolean ) set ( mc .options .sneakKey , false );
62+ if (isActive () && !aBoolean ) mc .options .sneakKey . setPressed ( false );
6263 })
6364 .build ()
6465 );
@@ -68,7 +69,7 @@ public enum Screens {
6869 .description ("Allows you to sprint while in GUIs." )
6970 .defaultValue (true )
7071 .onChanged (aBoolean -> {
71- if (isActive () && !aBoolean ) set ( mc .options .sprintKey , false );
72+ if (isActive () && !aBoolean ) mc .options .sprintKey . setPressed ( false );
7273 })
7374 .build ()
7475 );
@@ -94,14 +95,14 @@ public GUIMove() {
9495
9596 @ Override
9697 public void onDeactivate () {
97- set ( mc .options .forwardKey , false );
98- set ( mc .options .backKey , false );
99- set ( mc .options .leftKey , false );
100- set ( mc .options .rightKey , false );
101-
102- if (jump .get ()) set ( mc .options .jumpKey , false );
103- if (sneak .get ()) set ( mc .options .sneakKey , false );
104- if (sprint .get ()) set ( mc .options .sprintKey , false );
98+ mc .options .forwardKey . setPressed ( false );
99+ mc .options .backKey . setPressed ( false );
100+ mc .options .leftKey . setPressed ( false );
101+ mc .options .rightKey . setPressed ( false );
102+
103+ if (jump .get ()) mc .options .jumpKey . setPressed ( false );
104+ if (sneak .get ()) mc .options .sneakKey . setPressed ( false );
105+ if (sprint .get ()) mc .options .sprintKey . setPressed ( false );
105106 }
106107
107108 public boolean disableSpace () {
@@ -111,20 +112,29 @@ public boolean disableArrows() {
111112 return isActive () && arrowsRotate .get ();
112113 }
113114
114- @ EventHandler
115- private void onPlayerMoveEvent (PlayerTickMovementEvent event ) {
115+ private void onInput (int key , KeyAction action , boolean mouse ) {
116116 if (skip ()) return ;
117117 if (screens .get () == Screens .GUI && !(mc .currentScreen instanceof WidgetScreen )) return ;
118118 if (screens .get () == Screens .Inventory && mc .currentScreen instanceof WidgetScreen ) return ;
119119
120- set (mc .options .forwardKey , Input .isPressed (mc .options .forwardKey ));
121- set (mc .options .backKey , Input .isPressed (mc .options .backKey ));
122- set (mc .options .leftKey , Input .isPressed (mc .options .leftKey ));
123- set (mc .options .rightKey , Input .isPressed (mc .options .rightKey ));
120+ pass (mc .options .forwardKey , key , action , mouse );
121+ pass (mc .options .backKey , key , action , mouse );
122+ pass (mc .options .leftKey , key , action , mouse );
123+ pass (mc .options .rightKey , key , action , mouse );
124+
125+ if (jump .get ()) pass (mc .options .jumpKey , key , action , mouse );
126+ if (sneak .get ()) pass (mc .options .sneakKey , key , action , mouse );
127+ if (sprint .get ()) pass (mc .options .sprintKey , key , action , mouse );
128+ }
124129
125- if (jump .get ()) set (mc .options .jumpKey , Input .isPressed (mc .options .jumpKey ));
126- if (sneak .get ()) set (mc .options .sneakKey , Input .isPressed (mc .options .sneakKey ));
127- if (sprint .get ()) set (mc .options .sprintKey , Input .isPressed (mc .options .sprintKey ));
130+ @ EventHandler
131+ private void onKey (KeyEvent event ) {
132+ onInput (event .key , event .action , false );
133+ }
134+
135+ @ EventHandler
136+ private void onButton (MouseButtonEvent event ) {
137+ onInput (event .button , event .action , true );
128138 }
129139
130140 @ EventHandler
@@ -135,31 +145,40 @@ private void onRender3D(Render3DEvent event) {
135145
136146 float rotationDelta = Math .min ((float ) (rotateSpeed .get () * event .frameTime * 20f ), 100 );
137147
148+ Freecam freecam = Modules .get ().get (Freecam .class );
149+
138150 if (arrowsRotate .get ()) {
139- float yaw = mc .player .getYaw ();
140- float pitch = mc .player .getPitch ();
151+ if (!freecam .isActive ()) {
152+ float yaw = mc .player .getYaw ();
153+ float pitch = mc .player .getPitch ();
154+
155+ if (Input .isKeyPressed (GLFW_KEY_LEFT )) yaw -= rotationDelta ;
156+ if (Input .isKeyPressed (GLFW_KEY_RIGHT )) yaw += rotationDelta ;
157+ if (Input .isKeyPressed (GLFW_KEY_UP )) pitch -= rotationDelta ;
158+ if (Input .isKeyPressed (GLFW_KEY_DOWN )) pitch += rotationDelta ;
141159
142- if (Input .isKeyPressed (GLFW_KEY_LEFT )) yaw -= rotationDelta ;
143- if (Input .isKeyPressed (GLFW_KEY_RIGHT )) yaw += rotationDelta ;
144- if (Input .isKeyPressed (GLFW_KEY_UP )) pitch -= rotationDelta ;
145- if (Input .isKeyPressed (GLFW_KEY_DOWN )) pitch += rotationDelta ;
160+ pitch = MathHelper .clamp (pitch , -90 , 90 );
146161
162+ mc .player .setYaw (yaw );
163+ mc .player .setPitch (pitch );
164+ } else {
165+ double dy = 0 , dx = 0 ;
147166
148- pitch = MathHelper .clamp (pitch , -90 , 90 );
167+ if (Input .isKeyPressed (GLFW_KEY_LEFT )) dy = -rotationDelta ;
168+ if (Input .isKeyPressed (GLFW_KEY_RIGHT )) dy = rotationDelta ;
169+ if (Input .isKeyPressed (GLFW_KEY_UP )) dx = -rotationDelta ;
170+ if (Input .isKeyPressed (GLFW_KEY_DOWN )) dx = rotationDelta ;
149171
150- mc . player . setYaw ( yaw );
151- mc . player . setPitch ( pitch );
172+ freecam . changeLookDirection ( dy , dx );
173+ }
152174 }
153175 }
154176
155- private void set (KeyBinding bind , boolean pressed ) {
156- boolean wasPressed = bind .isPressed ();
157- bind .setPressed (pressed );
158-
159- InputUtil .Key key = ((KeyBindingAccessor ) bind ).getKey ();
160- if (wasPressed != pressed && key .getCategory () == InputUtil .Type .KEYSYM ) {
161- MeteorClient .EVENT_BUS .post (KeyEvent .get (key .getCode (), 0 , pressed ? KeyAction .Press : KeyAction .Release ));
162- }
177+ private void pass (KeyBinding bind , int key , KeyAction action , boolean mouse ) {
178+ if (!mouse && !bind .matchesKey (key , 0 )) return ;
179+ if (mouse && !bind .matchesMouse (key )) return ;
180+ if (action == KeyAction .Press ) bind .setPressed (true );
181+ if (action == KeyAction .Release ) bind .setPressed (false );
163182 }
164183
165184 public boolean skip () {
0 commit comments