22
33import dev .journey .PathSeeker .PathSeeker ;
44import dev .journey .PathSeeker .modules .exploration .TrailFollower ;
5+ import dev .journey .PathSeeker .modules .utility .Firework ;
6+ import meteordevelopment .meteorclient .systems .modules .Modules ;
57import meteordevelopment .meteorclient .events .world .TickEvent ;
68import meteordevelopment .meteorclient .settings .*;
79import meteordevelopment .meteorclient .systems .modules .Module ;
1315import net .minecraft .util .Hand ;
1416
1517public class AFKVanillaFly extends Module {
18+ private long lastRocketUse = 0 ;
19+ private boolean launched = false ;
20+ private boolean manuallyEnabled = false ;
21+ private double yTarget = -1 ;
22+ private float targetPitch = 0 ;
23+
24+ public AFKVanillaFly () {
25+ super (PathSeeker .Automation , "AFKVanillaFly" , "Maintains a level Y-flight with fireworks and smooth pitch control." );
26+ }
27+
28+ private final SettingGroup sgGeneral = settings .getDefaultGroup ();
29+
1630 private final SettingGroup sgGeneral = settings .getDefaultGroup ();
1731 private final Setting <AutoFireworkMode > fireworkMode = sgGeneral .add (new EnumSetting .Builder <AutoFireworkMode >()
1832 .name ("Auto Firework Mode" )
@@ -46,14 +60,25 @@ public AFKVanillaFly() {
4660
4761 @ Override
4862 public void onActivate () {
63+ manuallyEnabled = true ; // Track manual activation
4964 launched = false ;
5065 yTarget = -1 ;
5166
67+ Firework firework = Modules .get ().get (Firework .class );
68+ if (!firework .isActive ()) firework .toggle ();
69+
5270 if (mc .player == null || !mc .player .isFallFlying ()) {
5371 info ("You must be flying before enabling AFKVanillaFly." );
5472 }
5573 }
5674
75+ @ Override
76+ public void onDeactivate () {
77+ manuallyEnabled = false ; // Reset manual flag
78+ Firework firework = Modules .get ().get (Firework .class );
79+ if (firework .isActive ()) firework .toggle ();
80+ }
81+
5782 public void tickFlyLogic () {
5883 if (mc .player == null ) return ;
5984
@@ -83,19 +108,15 @@ public void tickFlyLogic() {
83108 targetPitch = 0f ;
84109 }
85110
111+ // pitch fix
112+ targetPitch = Math .max (-30f , Math .min (30f , targetPitch ));
113+
86114 float currentPitch = mc .player .getPitch ();
87115 mc .player .setPitch (currentPitch + (targetPitch - currentPitch ) * 0.1f );
88116
89- if (fireworkMode .get () == AutoFireworkMode .TIMED_DELAY ) {
90- if (System .currentTimeMillis () - lastRocketUse > fireworkDelay .get ()) {
91- tryUseFirework ();
92- }
93- } else if (fireworkMode .get () == AutoFireworkMode .VELOCITY ) {
94- double speed = Math .sqrt (Math .pow (mc .player .getVelocity ().x , 2 ) + Math .pow (mc .player .getVelocity ().z , 2 ));
95- if (speed < velocityThreshold .get ()) {
96- tryUseFirework ();
97- }
98- }
117+ Firework firework = Modules .get ().get (Firework .class );
118+ if (!firework .isActive ()) firework .toggle ();
119+
99120 } else {
100121 // Just jumped or crashed out of flight
101122 TrailFollower trailFollower = Modules .get ().get (TrailFollower .class );
@@ -106,54 +127,31 @@ public void tickFlyLogic() {
106127 if (!launched ) {
107128 mc .player .jump ();
108129 launched = true ;
109- } else if (System .currentTimeMillis () - lastRocketUse > 1000 ) {
110- tryUseFirework ();
111130 }
112131 yTarget = -1 ;
113132 }
114133 }
115134
116135 @ EventHandler
117136 private void onTick (TickEvent .Pre event ) {
118- tickFlyLogic ();
119- }
120-
121- public void resetYLock () {
122- yTarget = -1 ;
123- launched = false ;
124- }
125-
126- private void tryUseFirework () {
127- FindItemResult hotbar = InvUtils .findInHotbar (Items .FIREWORK_ROCKET );
128- if (!hotbar .found ()) {
129- FindItemResult inv = InvUtils .find (Items .FIREWORK_ROCKET );
130- if (inv .found ()) {
131- int hotbarSlot = findEmptyHotbarSlot ();
132- if (hotbarSlot != -1 ) {
133- InvUtils .move ().from (inv .slot ()).to (hotbarSlot );
134- } else {
135- info ("No empty hotbar slot available." );
136- return ;
137- }
138- } else {
139- info ("No fireworks in inventory." );
140- return ;
141- }
137+ TrailFollower trailFollower = Modules .get ().get (TrailFollower .class );
138+ Firework firework = Modules .get ().get (Firework .class );
139+
140+ boolean shouldAutoEnable = trailFollower .isActive ()
141+ && trailFollower .flightMode .get () == TrailFollower .FlightMode .VANILLA
142+ && mc .world != null
143+ && mc .world .getRegistryKey ().getValue ().getPath ().equals ("overworld" );
144+ if (shouldAutoEnable && !this .isActive () && !manuallyEnabled ) {
145+ this .toggle (); // Auto enable
146+ if (!firework .isActive ()) firework .toggle ();
142147 }
143-
144- // Use false so elytra isn't required
145- dev .journey .PathSeeker .utils .PathSeekerUtil .firework (mc , false );
146- mc .player .swingHand (Hand .MAIN_HAND );
147- lastRocketUse = System .currentTimeMillis ();
148- }
149-
150- private int findEmptyHotbarSlot () {
151- for (int i = 0 ; i < 9 ; i ++) {
152- if (mc .player .getInventory ().getStack (i ).isEmpty ()) return i ;
148+ if (!shouldAutoEnable && !manuallyEnabled && this .isActive ()) {
149+ this .toggle (); // Auto disable
150+ if (firework .isActive ()) firework .toggle ();
153151 }
154- return - 1 ;
152+ if ( this . isActive ()) tickFlyLogic () ;
155153 }
156-
154+ }
157155 public enum AutoFireworkMode {
158156 VELOCITY ,
159157 TIMED_DELAY
0 commit comments