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 ;
75import meteordevelopment .meteorclient .events .world .TickEvent ;
86import meteordevelopment .meteorclient .systems .modules .Module ;
97import meteordevelopment .orbit .EventHandler ;
10- import meteordevelopment .meteorclient .utils .player .InvUtils ; // delegated to Firework module
8+ import meteordevelopment .meteorclient .utils .player .InvUtils ;
119import meteordevelopment .meteorclient .utils .player .FindItemResult ;
1210import meteordevelopment .meteorclient .settings .*;
1311import net .minecraft .item .Items ;
1412import net .minecraft .util .Hand ;
13+ import net .minecraft .network .packet .c2s .play .PlayerInteractItemC2SPacket ;
14+
1515
1616public class AFKVanillaFly extends Module {
1717 private long lastRocketUse = 0 ;
1818 private boolean launched = false ;
19- private boolean manuallyEnabled = false ;
2019 private double yTarget = -1 ;
2120 private float targetPitch = 0 ;
2221
@@ -26,34 +25,47 @@ public AFKVanillaFly() {
2625
2726 private final SettingGroup sgGeneral = settings .getDefaultGroup ();
2827
28+ public enum AutoFireworkMode {
29+ VELOCITY ,
30+ TIMED_DELAY
31+ }
32+
33+ private final Setting <AutoFireworkMode > fireworkMode = sgGeneral .add (new EnumSetting .Builder <AutoFireworkMode >()
34+ .name ("Auto Firework Mode" )
35+ .description ("Choose between velocity-based or timed firework usage." )
36+ .defaultValue (AutoFireworkMode .VELOCITY )
37+ .build ()
38+ );
39+
40+ private final Setting <Integer > fireworkDelay = sgGeneral .add (new IntSetting .Builder ()
41+ .name ("Timed Delay (ms)" )
42+ .description ("How long to wait between fireworks when using Timed Delay." )
43+ .defaultValue (3000 )
44+ .sliderRange (0 , 6000 )
45+ .visible (() -> fireworkMode .get () == AutoFireworkMode .TIMED_DELAY )
46+ .build ()
47+ );
48+
49+ private final Setting <Double > velocityThreshold = sgGeneral .add (new DoubleSetting .Builder ()
50+ .name ("Velocity Threshold" )
51+ .description ("Use a firework if your horizontal speed is below this value." )
52+ .defaultValue (0.7 )
53+ .sliderRange (0.1 , 2.0 )
54+ .visible (() -> fireworkMode .get () == AutoFireworkMode .VELOCITY )
55+ .build ()
56+ );
57+
2958 @ Override
3059 public void onActivate () {
31- // will activate every time now
32- TrailFollower trailFollower = Modules .get ().get (TrailFollower .class );
33- boolean isAuto = trailFollower .isActive ()
34- && trailFollower .flightMode .get () == TrailFollower .FlightMode .VANILLA
35- && mc .world != null
36- && mc .world .getRegistryKey ().getValue ().getPath ().equals ("overworld" );
37- manuallyEnabled = true ; // Track manual activation
3860 launched = false ;
3961 yTarget = -1 ;
4062
41- Firework firework = Modules .get ().get (Firework .class );
42- if (!firework .isActive ()) firework .toggle ();
43-
4463 if (mc .player == null || !mc .player .isFallFlying ()) {
4564 info ("You must be flying before enabling AFKVanillaFly." );
46-
4765 }
4866 }
4967
50- @ Override
51- public void onDeactivate () {
52- manuallyEnabled = false ; // Reset manual flag
53- Firework firework = Modules .get ().get (Firework .class );
54- if (firework .isActive ()) firework .toggle ();
55- }
56-
68+ // this method is now then default logic, it did not need to be called in TrailFollower
5769 public void tickFlyLogic () {
5870 if (mc .player == null ) return ;
5971
@@ -65,13 +77,15 @@ public void tickFlyLogic() {
6577 launched = true ;
6678 }
6779
68- double yDiff = currentY - yTarget ;
69-
70- if (Math .abs (yDiff ) > 10.0 ) {
71- yTarget = currentY ;
80+ // will prevent from flying straight down into the ground - adjust y range if player moves vertical
81+ double yDiffFromLock = currentY - yTarget ;
82+ if (Math .abs (yDiffFromLock ) > 10.0 ) {
83+ yTarget = currentY ; // reset the current y-level to maintain
7284 info ("Y-lock reset due to altitude deviation." );
7385 }
7486
87+ double yDiff = currentY - yTarget ;
88+
7589 if (Math .abs (yDiff ) > 10.0 ) {
7690 targetPitch = (float ) (-Math .atan2 (yDiff , 100 ) * (180 / Math .PI ));
7791 } else if (yDiff > 2.0 ) {
@@ -82,48 +96,74 @@ public void tickFlyLogic() {
8296 targetPitch = 0f ;
8397 }
8498
85- // pitch fix
86- targetPitch = Math .max (-30f , Math .min (30f , targetPitch ));
87-
8899 float currentPitch = mc .player .getPitch ();
89- mc .player .setPitch (currentPitch + (targetPitch - currentPitch ) * 0.1f );
90-
91- Firework firework = Modules .get ().get (Firework .class );
92- if (!firework .isActive ()) firework .toggle ();
93-
94- } else {
95- // Just jumped or crashed out of flight
96- TrailFollower trailFollower = Modules .get ().get (TrailFollower .class );
97- if (trailFollower .isActive () && trailFollower .flightMode .get () == TrailFollower .FlightMode .VANILLA ) {
98- trailFollower .toggle ();
99- info ("You stopped flying. TrailFollower was disabled." );
100+ float pitchDiff = targetPitch - currentPitch ;
101+ mc .player .setPitch (currentPitch + pitchDiff * 0.1f );
102+
103+ if (fireworkMode .get () == AutoFireworkMode .TIMED_DELAY ) {
104+ if (System .currentTimeMillis () - lastRocketUse > fireworkDelay .get ()) {
105+ tryUseFirework ();
106+ }
107+ } else if (fireworkMode .get () == AutoFireworkMode .VELOCITY ) {
108+ double horizontalSpeed = Math .sqrt (Math .pow (mc .player .getVelocity ().x , 2 ) + Math .pow (mc .player .getVelocity ().z , 2 ));
109+ if (horizontalSpeed < velocityThreshold .get ()) {
110+ tryUseFirework ();
111+ }
100112 }
113+ //need this for initiate flying check if on ground, will configure in the future (won't affect grim fly since not being used)
114+ } else {
101115 if (!launched ) {
102116 mc .player .jump ();
103117 launched = true ;
118+ } else if (System .currentTimeMillis () - lastRocketUse > 1000 ) {
119+ tryUseFirework ();
104120 }
105121 yTarget = -1 ;
106122 }
107123 }
108124
125+
126+ public void resetYLock () {
127+ yTarget = -1 ;
128+ launched = false ;
129+ }
130+
131+
109132 @ EventHandler
110133 private void onTick (TickEvent .Pre event ) {
111- if (mc .player == null || mc .world == null ) return ;
112- TrailFollower trailFollower = Modules .get ().get (TrailFollower .class );
113- Firework firework = Modules .get ().get (Firework .class );
114-
115- boolean shouldAutoEnable = trailFollower .isActive ()
116- && trailFollower .flightMode .get () == TrailFollower .FlightMode .VANILLA
117- && mc .world != null
118- && mc .world .getRegistryKey ().getValue ().getPath ().equals ("overworld" );
119- if (shouldAutoEnable && !this .isActive () && !manuallyEnabled ) {
120- this .toggle (); // Auto enable
121- if (!firework .isActive ()) firework .toggle ();
134+ tickFlyLogic ();
135+ }
136+
137+
138+ private void tryUseFirework () {
139+ FindItemResult hotbar = InvUtils .findInHotbar (Items .FIREWORK_ROCKET );
140+ if (!hotbar .found ()) {
141+ FindItemResult inv = InvUtils .find (Items .FIREWORK_ROCKET );
142+ if (inv .found ()) {
143+ int hotbarSlot = findEmptyHotbarSlot ();
144+ if (hotbarSlot != -1 ) {
145+ InvUtils .move ().from (inv .slot ()).to (hotbarSlot );
146+ } else {
147+ info ("No empty hotbar slot available to move fireworks." );
148+ return ;
149+ }
150+ } else {
151+ info ("No fireworks found in hotbar or inventory." );
152+ return ;
153+ }
122154 }
123- if (!shouldAutoEnable && !manuallyEnabled && this .isActive ()) {
124- this .toggle (); // Auto disable
125- if (firework .isActive ()) firework .toggle ();
155+
156+ if (mc .player .getMainHandStack ().isOf (Items .FIREWORK_ROCKET )) {
157+ mc .interactionManager .interactItem (mc .player , Hand .MAIN_HAND );
158+ }
159+
160+ lastRocketUse = System .currentTimeMillis ();
161+ }
162+
163+ private int findEmptyHotbarSlot () {
164+ for (int i = 0 ; i < 9 ; i ++) {
165+ if (mc .player .getInventory ().getStack (i ).isEmpty ()) return i ;
126166 }
127- if ( this . isActive ()) tickFlyLogic () ;
167+ return - 1 ;
128168 }
129- }
169+ }
0 commit comments