@@ -29,21 +29,33 @@ import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotat
2929import com.lambda.module.Module
3030import com.lambda.module.modules.movement.BetterFirework.canOpenElytra
3131import com.lambda.module.modules.movement.BetterFirework.canTakeoff
32+ import com.lambda.module.modules.movement.BetterFirework.startFirework
3233import com.lambda.module.tag.ModuleTag
3334import com.lambda.threading.runSafe
35+ import com.lambda.util.Timer
3436import com.lambda.util.extension.isElytraFlying
3537import com.lambda.util.player.MovementUtils.addSpeed
38+ import com.lambda.util.player.SlotUtils.hotbarAndInventoryStacks
39+ import com.lambda.util.player.SlotUtils.hotbarStacks
40+ import com.lambda.util.player.hasFirework
41+ import com.lambda.interaction.material.StackSelection.Companion.selectStack
42+ import net.minecraft.component.DataComponentTypes
3643import net.minecraft.entity.Entity
44+ import net.minecraft.item.ItemStack
45+ import net.minecraft.item.Items
3746import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
3847import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
3948import net.minecraft.sound.SoundEvents
49+ import net.minecraft.util.math.Vec3d
50+ import kotlin.time.Duration.Companion.seconds
4051
4152object ElytraFly : Module(
4253 name = " ElytraFly" ,
4354 description = " Allows you to fly with an elytra" ,
4455 tag = ModuleTag .MOVEMENT ,
4556) {
4657 @JvmStatic val mode by setting(" Mode" , FlyMode .Bounce )
58+ private val inventory by setting(" Inventory" , true , " Allow using fireworks from the players inventory" )
4759
4860 // ToDo: Implement these commented out settings
4961 private val takeoff by setting(" Takeoff" , true , " Automatically jumps and initiates gliding" ) { mode == FlyMode .Bounce }
@@ -54,13 +66,16 @@ object ElytraFly : Module(
5466// private val passObstacles by setting("Pass Obstacles", true, "Automatically paths around obstacles using baritone") { mode == FlyMode.Bounce }
5567
5668 private val boostSpeed by setting(" Boost" , 0.00 , 0.0 .. 0.5 , 0.005 , description = " Speed to add when flying" )
57- private val rocketSpeed by setting(" Rocket Speed" , 0.0 , 0.0 .. 2.0 , description = " Speed multiplier that the rocket gives you" ) { mode == FlyMode .Enhanced }
69+ private val rocketSpeed by setting(" Rocket Speed" , 0.0 , 0.0 .. 2.0 , description = " Speed multiplier that the rocket gives you" ) { mode == FlyMode .Enhanced }
5870
5971 private val mute by setting(" Mute Elytra" , false , " Mutes the elytra sound when gliding" )
6072
61- var jumpThisTick = false
62- var previouslyFlying: Boolean? = null
63- var glidePause = 0
73+ private var jumpThisTick = false
74+ private var previouslyFlying: Boolean? = null
75+ private var glidePause = 0
76+ private var flipFlop = false
77+ private var lastDuration = 1.0
78+ private val fireworkTimer = Timer ()
6479
6580 init {
6681 setDefaultAutomationConfig {
@@ -70,20 +85,8 @@ object ElytraFly : Module(
7085 }
7186
7287 listen<TickEvent .Pre > {
73- if (mode != FlyMode .Bounce ) return @listen
74- if (autoPitch) rotationRequest { pitch(pitch.toFloat()) }.submit()
75-
76- if (! player.isGliding) {
77- if (takeoff && player.canTakeoff) {
78- if (player.canOpenElytra) {
79- player.startGliding()
80- startFlyPacket()
81- } else jumpThisTick = true
82- }
83- return @listen
84- }
85-
86- startFlyPacket()
88+ if (mode == FlyMode .GrimControl ) onTickGrimControl()
89+ else if (mode == FlyMode .Bounce ) onTickBounce()
8790 }
8891
8992 listen<TickEvent .Post > {
@@ -117,6 +120,59 @@ object ElytraFly : Module(
117120 }
118121 }
119122
123+ private fun SafeContext.onTickGrimControl () {
124+ if (! player.isGliding) return
125+ if (fireworkTimer.timePassed(lastDuration.seconds)) {
126+ findFirework()?.let {
127+ lastDuration = (it.get(DataComponentTypes .FIREWORKS )?.flightDuration ? : 1 ) * 0.5 + 0.5
128+ startFirework(inventory)
129+ fireworkTimer.reset()
130+ }
131+ }
132+
133+ var vec = Vec3d .ZERO
134+ val yaw = player.yaw
135+ if (mc.options.forwardKey.isPressed) vec = vec.add(Vec3d .fromPolar(0f , yaw))
136+ if (mc.options.backKey.isPressed) vec = vec.add(Vec3d .fromPolar(0f , yaw + 180f ))
137+ if (mc.options.leftKey.isPressed) vec = vec.add(Vec3d .fromPolar(0f , yaw - 90f ))
138+ if (mc.options.rightKey.isPressed) vec = vec.add(Vec3d .fromPolar(0f , yaw + 90f ))
139+ if (mc.options.jumpKey.isPressed) vec = vec.add(Vec3d (0.0 , 1.0 , 0.0 ))
140+ if (mc.options.sneakKey.isPressed) vec = vec.add(Vec3d (0.0 , - 1.0 , 0.0 ))
141+ if (vec.lengthSquared() < 1e- 4 && player.hasFirework) {
142+ if (flipFlop) {
143+ flipFlop = false
144+ rotationRequest { rotation(0f , 0f ) }
145+ } else {
146+ flipFlop = true
147+ rotationRequest { rotation(180f , 0f ) }
148+ }
149+ } else {
150+ val rot = vec.yawAndPitch
151+ rotationRequest { rotation(rot.y, rot.x) }
152+ }.submit()
153+ }
154+
155+ private fun SafeContext.findFirework (): ItemStack ? {
156+ val stack = selectStack(count = 1 ) { isItem(Items .FIREWORK_ROCKET ) }
157+ return stack.bestItemMatch(player.hotbarStacks) ? : if (inventory) stack.bestItemMatch(player.hotbarAndInventoryStacks) else null
158+ }
159+
160+ private fun SafeContext.onTickBounce () {
161+ if (autoPitch) rotationRequest { pitch(pitch.toFloat()) }.submit()
162+
163+ if (! player.isGliding) {
164+ if (takeoff && player.canTakeoff) {
165+ if (player.canOpenElytra) {
166+ player.startGliding()
167+ startFlyPacket()
168+ } else jumpThisTick = true
169+ }
170+ return
171+ }
172+
173+ startFlyPacket()
174+ }
175+
120176 private fun SafeContext.startFlyPacket () =
121177 connection.sendPacket(ClientCommandC2SPacket (player, ClientCommandC2SPacket .Mode .START_FALL_FLYING ))
122178
@@ -136,12 +192,11 @@ object ElytraFly : Module(
136192
137193 @JvmStatic
138194 fun boostRocket () = runSafe {
139- if (mode == FlyMode .Bounce ) return @runSafe
140195 val vec = player.rotationVector
141196 val velocity = player.velocity
142197
143- val d = 1.5 * rocketSpeed
144- val e = 0.1 * rocketSpeed
198+ val d = 1.5 * if (mode == FlyMode . Enhanced ) rocketSpeed else 1.0
199+ val e = 0.1 * if (mode == FlyMode . Enhanced ) rocketSpeed else 1.0
145200
146201 player.velocity = velocity.add(
147202 vec.x * e + (vec.x * d - velocity.x) * 0.5 ,
@@ -152,6 +207,7 @@ object ElytraFly : Module(
152207
153208 enum class FlyMode {
154209 Bounce ,
155- Enhanced
210+ Enhanced ,
211+ GrimControl
156212 }
157213}
0 commit comments