Skip to content

Commit e217024

Browse files
committed
Revert accidental ElytraFly deletion in #224
This reverts commit 3ea55a6.
1 parent d674f37 commit e217024

File tree

1 file changed

+157
-0
lines changed
  • src/main/kotlin/com/lambda/module/modules/movement

1 file changed

+157
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.module.modules.movement
19+
20+
import com.lambda.config.AutomationConfig.Companion.setDefaultAutomationConfig
21+
import com.lambda.config.applyEdits
22+
import com.lambda.context.SafeContext
23+
import com.lambda.event.events.ClientEvent
24+
import com.lambda.event.events.MovementEvent
25+
import com.lambda.event.events.PacketEvent
26+
import com.lambda.event.events.TickEvent
27+
import com.lambda.event.listener.SafeListener.Companion.listen
28+
import com.lambda.interaction.managers.rotating.IRotationRequest.Companion.rotationRequest
29+
import com.lambda.module.Module
30+
import com.lambda.module.modules.movement.BetterFirework.canOpenElytra
31+
import com.lambda.module.modules.movement.BetterFirework.canTakeoff
32+
import com.lambda.module.tag.ModuleTag
33+
import com.lambda.threading.runSafe
34+
import com.lambda.util.extension.isElytraFlying
35+
import com.lambda.util.player.MovementUtils.addSpeed
36+
import net.minecraft.entity.Entity
37+
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
38+
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
39+
import net.minecraft.sound.SoundEvents
40+
41+
object ElytraFly : Module(
42+
name = "ElytraFly",
43+
description = "Allows you to fly with an elytra",
44+
tag = ModuleTag.MOVEMENT,
45+
) {
46+
@JvmStatic val mode by setting("Mode", FlyMode.Bounce)
47+
48+
//ToDo: Implement these commented out settings
49+
private val takeoff by setting("Takeoff", true, "Automatically jumps and initiates gliding") { mode == FlyMode.Bounce }
50+
private val autoPitch by setting("Auto Pitch", true, "Automatically pitches the players rotation down to bounce at faster speeds") { mode == FlyMode.Bounce }
51+
private val pitch by setting("Pitch", 80, 0..90, 1) { autoPitch && mode == FlyMode.Bounce }
52+
private val jump by setting("Jump", true, "Automatically jumps") { mode == FlyMode.Bounce }
53+
private val flagPause by setting("Flag Pause", 20, 0..100, 1, "How long to pause if the server flags you for a movement check") { mode == FlyMode.Bounce }
54+
// private val passObstacles by setting("Pass Obstacles", true, "Automatically paths around obstacles using baritone") { mode == FlyMode.Bounce }
55+
56+
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 }
58+
59+
private val mute by setting("Mute Elytra", false, "Mutes the elytra sound when gliding")
60+
61+
var jumpThisTick = false
62+
var previouslyFlying: Boolean? = null
63+
var glidePause = 0
64+
65+
init {
66+
setDefaultAutomationConfig {
67+
applyEdits {
68+
hideAllGroupsExcept(inventoryConfig)
69+
}
70+
}
71+
72+
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()
87+
}
88+
89+
listen<TickEvent.Post> {
90+
if (glidePause > 0) glidePause--
91+
}
92+
93+
listen<PacketEvent.Receive.Post> { event ->
94+
if (event.packet !is PlayerPositionLookS2CPacket) return@listen
95+
if (mode == FlyMode.Bounce && player.isGliding) {
96+
glidePause = flagPause
97+
}
98+
}
99+
100+
listen<MovementEvent.InputUpdate> { event ->
101+
if (mode == FlyMode.Bounce && ((player.isGliding && jump) || jumpThisTick)) {
102+
event.input.jump()
103+
jumpThisTick = false
104+
}
105+
}
106+
107+
listen<MovementEvent.Player.Pre> {
108+
if (player.isElytraFlying && !player.isUsingItem) {
109+
addSpeed(boostSpeed)
110+
}
111+
}
112+
113+
listen<ClientEvent.Sound> { event ->
114+
if (!mute) return@listen
115+
if (event.sound.id != SoundEvents.ITEM_ELYTRA_FLYING.id) return@listen
116+
event.cancel()
117+
}
118+
}
119+
120+
private fun SafeContext.startFlyPacket() =
121+
connection.sendPacket(ClientCommandC2SPacket(player, ClientCommandC2SPacket.Mode.START_FALL_FLYING))
122+
123+
@JvmStatic
124+
fun isGliding(): Boolean? = runSafe {
125+
val original: Boolean = player.getFlag(Entity.GLIDING_FLAG_INDEX)
126+
if (previouslyFlying == null) {
127+
previouslyFlying = original
128+
return@runSafe original
129+
}
130+
return if (isEnabled && mode == FlyMode.Bounce && previouslyFlying == true && glidePause <= 0) true
131+
else {
132+
previouslyFlying = original
133+
original
134+
}
135+
}
136+
137+
@JvmStatic
138+
fun boostRocket() = runSafe {
139+
if (mode == FlyMode.Bounce) return@runSafe
140+
val vec = player.rotationVector
141+
val velocity = player.velocity
142+
143+
val d = 1.5 * rocketSpeed
144+
val e = 0.1 * rocketSpeed
145+
146+
player.velocity = velocity.add(
147+
vec.x * e + (vec.x * d - velocity.x) * 0.5,
148+
vec.y * e + (vec.y * d - velocity.y) * 0.5,
149+
vec.z * e + (vec.z * d - velocity.z) * 0.5
150+
)
151+
}
152+
153+
enum class FlyMode {
154+
Bounce,
155+
Enhanced
156+
}
157+
}

0 commit comments

Comments
 (0)