77 */
88package net .wurstclient .hacks ;
99
10- import net .minecraft .client .KeyMapping ;
1110import net .minecraft .client .player .LocalPlayer ;
1211import net .minecraft .world .entity .player .Abilities ;
1312import net .minecraft .world .phys .Vec3 ;
2322@ SearchTags ({"creative flight" , "CreativeFly" , "creative fly" })
2423public final class CreativeFlightHack extends Hack implements UpdateListener
2524{
25+ private static final double DESCENT_SPEED = -0.15 ;
26+
2627 private final CheckboxSetting antiKick = new CheckboxSetting ("Anti-Kick" ,
2728 "Makes you fall a little bit every now and then to prevent you from getting kicked." ,
2829 false );
@@ -31,16 +32,22 @@ public final class CreativeFlightHack extends Hack implements UpdateListener
3132 new SliderSetting ("Anti-Kick Interval" ,
3233 "How often Anti-Kick should prevent you from getting kicked.\n "
3334 + "Most servers will kick you after 80 ticks." ,
34- 30 , 5 , 80 , 1 , SliderSetting .ValueDisplay .INTEGER
35+ 70 , 5 , 80 , 1 , SliderSetting .ValueDisplay .INTEGER
3536 .withSuffix (" ticks" ).withLabel (1 , "1 tick" ));
3637
3738 private final SliderSetting antiKickDistance = new SliderSetting (
3839 "Anti-Kick Distance" ,
3940 "How far Anti-Kick should make you fall.\n "
4041 + "Most servers require at least 0.032m to stop you from getting kicked." ,
41- 0.07 , 0.01 , 0.2 , 0.001 , ValueDisplay .DECIMAL .withSuffix ("m" ));
42+ 0.035 , 0.01 , 0.2 , 0.001 , ValueDisplay .DECIMAL .withSuffix ("m" ));
43+
44+ private final CheckboxSetting startFlyingImmediately = new CheckboxSetting (
45+ "Start flying immediately" ,
46+ "Automatically enables CreativeFlight as soon as the hack is turned on, instead of waiting for the usual double-jump." ,
47+ true );
4248
4349 private int tickCounter = 0 ;
50+ private boolean suppressedSneakKey ;
4451
4552 public CreativeFlightHack ()
4653 {
@@ -49,16 +56,23 @@ public CreativeFlightHack()
4956 addSetting (antiKick );
5057 addSetting (antiKickInterval );
5158 addSetting (antiKickDistance );
59+ addSetting (startFlyingImmediately );
5260 }
5361
5462 @ Override
5563 protected void onEnable ()
5664 {
5765 tickCounter = 0 ;
66+ suppressedSneakKey = false ;
5867
5968 WURST .getHax ().jetpackHack .setEnabled (false );
6069 WURST .getHax ().flightHack .setEnabled (false );
6170
71+ Abilities abilities = MC .player .getAbilities ();
72+ abilities .mayfly = true ;
73+ if (startFlyingImmediately .isChecked ())
74+ abilities .flying = true ;
75+
6276 EVENTS .add (UpdateListener .class , this );
6377 }
6478
@@ -74,7 +88,7 @@ protected void onDisable()
7488 abilities .flying = creative && !player .onGround ();
7589 abilities .mayfly = creative ;
7690
77- restoreKeyPresses ();
91+ restoreSneakKey ();
7892 }
7993
8094 @ Override
@@ -83,49 +97,71 @@ public void onUpdate()
8397 Abilities abilities = MC .player .getAbilities ();
8498 abilities .mayfly = true ;
8599
100+ handleSmoothDescent (abilities );
101+
86102 if (antiKick .isChecked () && abilities .flying )
87103 doAntiKick ();
88104 }
89105
106+ private void handleSmoothDescent (Abilities abilities )
107+ {
108+ IKeyMapping sneakKey = IKeyMapping .get (MC .options .keyShift );
109+ boolean sneakDown = sneakKey .isActuallyDown ();
110+
111+ if (!abilities .flying || !sneakDown )
112+ {
113+ if (suppressedSneakKey )
114+ restoreSneakKey ();
115+
116+ return ;
117+ }
118+
119+ sneakKey .setDown (false );
120+ suppressedSneakKey = true ;
121+
122+ if (IKeyMapping .get (MC .options .keyJump ).isActuallyDown ())
123+ return ;
124+
125+ Vec3 velocity = MC .player .getDeltaMovement ();
126+ MC .player .setDeltaMovement (velocity .x , DESCENT_SPEED , velocity .z );
127+ }
128+
90129 private void doAntiKick ()
91130 {
92- if (tickCounter > antiKickInterval .getValueI () + 2 )
131+ if (IKeyMapping .get (MC .options .keyJump ).isActuallyDown ()
132+ || IKeyMapping .get (MC .options .keyShift ).isActuallyDown ())
133+ return ;
134+
135+ if (tickCounter > antiKickInterval .getValueI () + 1 )
93136 tickCounter = 0 ;
94137
95138 switch (tickCounter )
96139 {
97140 case 0 ->
98141 {
99- if (MC .options .keyShift .isDown () && !MC .options .keyJump .isDown ())
100- tickCounter = 3 ;
142+ Vec3 velocity = MC .player .getDeltaMovement ();
143+ if (velocity .y <= -antiKickDistance .getValue ())
144+ tickCounter = 2 ;
101145 else
102- setMotionY (-antiKickDistance .getValue ());
146+ addMotionY (-antiKickDistance .getValue ());
103147 }
104148
105- case 1 -> setMotionY (antiKickDistance .getValue ());
106-
107- case 2 -> setMotionY (0 );
108-
109- case 3 -> restoreKeyPresses ();
149+ case 1 -> addMotionY (antiKickDistance .getValue ());
110150 }
111151
112152 tickCounter ++;
113153 }
114154
115- private void setMotionY (double motionY )
155+ private void addMotionY (double motionY )
116156 {
117- MC .options .keyShift .setDown (false );
118- MC .options .keyJump .setDown (false );
119-
120157 Vec3 velocity = MC .player .getDeltaMovement ();
121- MC .player .setDeltaMovement (velocity .x , motionY , velocity .z );
158+ MC .player .setDeltaMovement (velocity .x , velocity .y + motionY ,
159+ velocity .z );
122160 }
123161
124- private void restoreKeyPresses ()
162+ private void restoreSneakKey ()
125163 {
126- KeyMapping [] keys = {MC .options .keyJump , MC .options .keyShift };
127-
128- for (KeyMapping key : keys )
129- IKeyMapping .get (key ).resetPressedState ();
164+ IKeyMapping .get (MC .options .keyShift ).resetPressedState ();
165+ suppressedSneakKey = false ;
130166 }
131167}
0 commit comments