@@ -24,6 +24,7 @@ import com.lambda.module.Module
2424import com.lambda.module.tag.ModuleTag
2525import com.lambda.threading.runSafe
2626import net.minecraft.client.network.ClientPlayerEntity
27+ import net.minecraft.entity.effect.StatusEffects
2728import net.minecraft.item.ItemStack
2829import net.minecraft.item.Items
2930import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
@@ -47,15 +48,25 @@ object BetterFirework : Module(
4748 private var clientSwing by setting(" Swing" , true , " Swing hand client side" )
4849 private var silentUse by setting(" Silent" , true , " Silent use fireworks from the inventory" , visibility = { middleClick })
4950
50- private var openDelay = 0
51+ private var takeoffState = TakeoffState . NONE
5152
5253 init {
5354 listen<TickEvent .Pre > {
54- // Try opening the elytra after a delay after jumping
55- if (openDelay > 0 ) {
56- openDelay--
57- if (openDelay == 0 ) {
58- tryTakeoff()
55+ when (takeoffState) {
56+ TakeoffState .NONE -> {
57+ // Nothing to do
58+ }
59+ TakeoffState .JUMPING -> {
60+ player.jump()
61+ takeoffState = TakeoffState .START_FLYING
62+ }
63+ TakeoffState .START_FLYING -> {
64+ if (player.canOpenElytra) {
65+ player.startGliding()
66+ connection.sendPacket(ClientCommandC2SPacket (player, ClientCommandC2SPacket .Mode .START_FALL_FLYING ))
67+ }
68+ startFirework(silentUse)
69+ takeoffState = TakeoffState .NONE
5970 }
6071 }
6172 }
@@ -77,7 +88,13 @@ object BetterFirework : Module(
7788 return false
7889 }
7990 mc.itemUseCooldown + = 4
80- return tryTakeoff() || fireworkInteractCancel
91+ val cancelInteract = player.canTakeoff || fireworkInteractCancel
92+ if (player.canTakeoff) {
93+ takeoffState = TakeoffState .JUMPING
94+ } else if (player.canOpenElytra) {
95+ takeoffState = TakeoffState .START_FLYING
96+ }
97+ return cancelInteract
8198 } ? : false
8299
83100 /* *
@@ -89,40 +106,23 @@ object BetterFirework : Module(
89106 if (mc.crosshairTarget?.type == HitResult .Type .BLOCK && ! middleClickCancel) {
90107 return false
91108 }
92- if (player.isGliding) {
109+ if (takeoffState != TakeoffState .NONE ) {
110+ return false // Prevent using multiple times
111+ }
112+ if (player.canOpenElytra || player.isGliding) {
93113 // If already gliding use another firework
94- startFirework(silentUse)
95- } else {
96- tryTakeoff()
114+ takeoffState = TakeoffState . START_FLYING
115+ } else if (player.canTakeoff) {
116+ takeoffState = TakeoffState . JUMPING
97117 }
98118 return true
99119 } ? : false // Edouardo: :3333333
100120
101- /* *
102- * This function prepares takeoff from standing or falling.
103- * If the player is standing on ground it jumps to prepare for takeoff and return true.
104- * If the player is falling it opens the elytra, uses a firework and return true.
105- * Otherwise, return false and does nothing.
106- */
107- fun SafeContext.tryTakeoff (): Boolean {
108- if (player.isOnGround) {
109- player.jump()
110- openDelay = 1 ; // Magic number, works on 2b so we GUCCI
111- return true
112- }
113-
114- if (canOpenElytra(player)) {
115- connection.sendPacket(ClientCommandC2SPacket (player, ClientCommandC2SPacket .Mode .START_FALL_FLYING ))
116- startFirework(silentUse)
117- return true
118- }
121+ val ClientPlayerEntity .canTakeoff: Boolean
122+ get() = isOnGround || canOpenElytra
119123
120- return false
121- }
122-
123- fun canOpenElytra (player : ClientPlayerEntity ): Boolean {
124- return ! player.abilities.flying && ! player.hasVehicle() && ! player.isClimbing && player.checkGliding()
125- }
124+ val ClientPlayerEntity .canOpenElytra: Boolean
125+ get() = ! abilities.flying && ! isClimbing && ! isGliding && ! isTouchingWater && ! isOnGround && ! hasVehicle() && ! hasStatusEffect(StatusEffects .LEVITATION )
126126
127127 fun SafeContext.sendSwing () {
128128 if (clientSwing) {
@@ -184,4 +184,10 @@ object BetterFirework : Module(
184184 }
185185 return - 1
186186 }
187+
188+ enum class TakeoffState {
189+ NONE ,
190+ JUMPING ,
191+ START_FLYING
192+ }
187193}
0 commit comments