@@ -7,8 +7,8 @@ import com.lambda.client.event.events.PacketEvent
77import com.lambda.client.event.events.PlayerMoveEvent
88import com.lambda.client.event.events.PlayerTravelEvent
99import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket
10- import com.lambda.client.mixin.extension.tickLength
11- import com.lambda.client.mixin.extension.timer
10+ import com.lambda.client.manager.managers.TimerManager.modifyTimer
11+ import com.lambda.client.manager.managers.TimerManager.resetTimer
1212import com.lambda.client.module.Category
1313import com.lambda.client.module.Module
1414import com.lambda.client.module.modules.player.ViewLock
@@ -41,29 +41,29 @@ object ElytraFlight2b2t : Module(
4141 category = Category .MOVEMENT ,
4242 modulePriority = 1000
4343) {
44- private val takeoffTimerSpeed by setting(" Takeoff Timer Tick Length" , 395.0f , 100.0f .. 1000.0f , 1 .0f ,
44+ private val takeoffTimerSpeed by setting(" Takeoff Timer Tick Length" , 395.0f , 100.0f .. 1000.0f , 5 .0f ,
4545 description = " How long each timer tick is during redeploy (ms). Lower length = faster timer. " +
46- " Try increasing this if experiencing elytra timeout or rubberbands. This value is multiplied by 2 when setting timer" )
46+ " Try increasing this if experiencing elytra timeout or rubberbands. This value is multiplied by 2 when setting timer" , unit = " ms " )
4747 private val baritoneBlockagePathing by setting(" Baritone Blockage Pathing" , true ,
4848 description = " Use baritone to path around blockages on the highway." )
4949 private val baritonePathForwardBlocks by setting(" Baritone Path Distance" , 20 , 1 .. 50 , 1 ,
5050 visibility = { baritoneBlockagePathing })
51- private val baritoneEndDelayMs by setting(" Baritone End Pathing Delay Ms " , 500 , 0 .. 2000 , 50 ,
52- visibility = { baritoneBlockagePathing })
53- private val baritoneStartDelayMs by setting(" Baritone Start Delay Ms " , 500 , 0 .. 2000 , 50 ,
54- visibility = { baritoneBlockagePathing })
51+ private val baritoneEndDelayMs by setting(" Baritone End Pathing Delay" , 500 , 0 .. 2000 , 50 ,
52+ visibility = { baritoneBlockagePathing }, unit = " ms " )
53+ private val baritoneStartDelayMs by setting(" Baritone Start Delay" , 500 , 0 .. 2000 , 50 ,
54+ visibility = { baritoneBlockagePathing }, unit = " ms " )
5555 private val midairFallFly by setting(" Mid-flight Packet Deploy" , true ,
5656 description = " Uses packets to redeploy when mid-flight." )
5757 private val autoFlyForward by setting(" Auto Fly Forward" , true ,
5858 description = " Automatically move forward when flying." )
5959 private val rubberBandDetectionTime by setting(" Rubberband Detection Time" , 1110 , 0 .. 2000 , 10 ,
60- description = " Time period (ms) between which to detect rubberband teleports. Lower period = more sensitive." )
61- private val enableBoost by setting(" Enable boost " , true ,
60+ description = " Time period (ms) between which to detect rubberband teleports. Lower period = more sensitive." , unit = " ms " )
61+ private val enableBoost by setting(" Enable Boost " , true ,
6262 description = " Enable boost during mid-air flight." )
63- private val boostDelayTicks by setting(" Boost delay ticks " , 11 , 1 .. 200 , 1 ,
64- visibility = { enableBoost },
63+ private val boostDelayTicks by setting(" Boost Delay " , 11 , 1 .. 200 , 1 ,
64+ visibility = { enableBoost }, unit = " ticks " ,
6565 description = " Number of ticks to wait before beginning boost" )
66- private val boostSpeedIncrease by setting(" Boost speed increase " , 0.65 , 0.0 .. 2.0 , 0.01 ,
66+ private val boostSpeedIncrease by setting(" Boost Speed Increase " , 0.65 , 0.0 .. 2.0 , 0.01 ,
6767 visibility = { enableBoost },
6868 description = " Boost speed increase per tick (blocks per second / 2)" )
6969 private val initialFlightSpeed by setting(" Initial Flight Speed" , 39.5 , 35.0 .. 80.0 , 0.01 ,
@@ -77,62 +77,63 @@ object ElytraFlight2b2t : Module(
7777 private val autoViewLockManage by setting(" Auto ViewLock Manage" , true ,
7878 description = " Automatically configures and toggles viewlock for straight flight on highways." )
7979
80- private const val takeOffYVelocity: Double = - 0.16976 // magic number - do not question
81- private const val magicPitch = - 2.52f
80+ private const val TAKE_OFF_Y_VELOCITY = - 0.16976 // magic number - do not question
81+ private const val MAGIC_PITCH = - 2.52f
82+ private const val JUMP_DELAY = 10
83+
8284 private var currentState = State .PAUSED
85+ private var isFlying = false
86+ private var isBaritoning = false
87+
8388 private var timer = TickTimer (TimeUnit .TICKS )
84- private var currentFlightSpeed: Double = 40.2
85- private var shouldStartBoosting: Boolean = false ;
89+ private var lastSPacketPlayerPosLook = Long .MIN_VALUE
90+ private var lastRubberband = Long .MIN_VALUE
91+ private var baritoneStartTime = 0L
92+ private var baritoneEndPathingTime = 0L
93+
94+ private var shouldStartBoosting = false
8695 private var elytraIsEquipped = false
87- private var elytraDurability = 0
88- private var wasInLiquid: Boolean = false
89- private var isFlying: Boolean = false
96+ private var wasInLiquid = false
9097 private var isStandingStill = false
91- private var lastSPacketPlayerPosLook : Long = Long . MIN_VALUE
92- private var lastRubberband : Long = Long . MIN_VALUE
93- private var startedFlying : Boolean = false
94- private var stoppedFlying : Boolean = false
95- private var nextBlockMoveLoaded : Boolean = true
98+ private var startedFlying = false
99+ private var stoppedFlying = false
100+ private var nextBlockMoveLoaded = true
101+
102+ private var elytraDurability = 0
96103 private var flyTickCount = 0
97- private var flyPlayerLastPos: Vec3d = Vec3d .ZERO
98104 private var flyBlockedTickCount = 0
99- private var isBaritoning: Boolean = false
100- private var baritoneStartTime: Long = 0L
101- private var baritoneEndPathingTime: Long = 0L
102- private var beforePathingPlayerPitchYaw= Vec2f .ZERO
105+ private var currentFlightSpeed = 40.2
106+
107+ private var flyPlayerLastPos = Vec3d .ZERO
108+ private var beforePathingPlayerPitchYaw = Vec2f .ZERO
109+ private var motionPrev = Vec2f (0.0f , 0.0f )
110+
103111 private var scheduleBaritoneJob: Job ? = null
104- private var motionPrev: Vec2f = Vec2f (0.0f , 0.0f )
105- private const val jumpDelay: Int = 10
106112
107113 enum class State {
108114 FLYING , TAKEOFF , PAUSED , WALKING
109115 }
110116
111- override fun getHudInfo (): String {
112- return currentState.name
113- }
117+ override fun getHudInfo () = currentState.name
114118
115119 init {
116-
117120 onEnable {
118121 currentState = State .PAUSED
119122 timer.reset()
120123 shouldStartBoosting = false
121124 lastRubberband = Long .MIN_VALUE
122- if (autoViewLockManage)
123- configureViewLock()
125+ if (autoViewLockManage) configureViewLock()
124126 }
125127
126128 onDisable {
127129 currentState = State .PAUSED
128130 resetFlightSpeed()
129131 BaritoneUtils .cancelEverything()
130132 shouldStartBoosting = false
131- mc.timer.tickLength = 50.0f
133+ resetTimer()
132134 wasInLiquid = false
133135 isFlying = false
134- if (autoViewLockManage)
135- ViewLock .disable()
136+ if (autoViewLockManage) ViewLock .disable()
136137 }
137138
138139 safeListener<ConnectionEvent .Disconnect > {
@@ -167,8 +168,8 @@ object ElytraFlight2b2t : Module(
167168 // delay takeoff if we were pathing
168169 if (isBaritoning) {
169170 baritoneEndPathingTime = System .currentTimeMillis()
170- mc. player.rotationPitch = beforePathingPlayerPitchYaw.x
171- mc. player.rotationYaw = beforePathingPlayerPitchYaw.y
171+ player.rotationPitch = beforePathingPlayerPitchYaw.x
172+ player.rotationYaw = beforePathingPlayerPitchYaw.y
172173 isBaritoning = false
173174 return @safeListener
174175 }
@@ -177,24 +178,24 @@ object ElytraFlight2b2t : Module(
177178 }
178179 State .TAKEOFF -> {
179180 if (autoViewLockManage && ViewLock .isDisabled) ViewLock .enable()
180- mc.timer.tickLength = 50.0f
181+ resetTimer()
181182 shouldStartBoosting = false
182183 resetFlightSpeed()
183- if (baritoneBlockagePathing && player.onGround && timer.tick(jumpDelay .toLong())) player.jump()
184- if ((withinRange(mc. player.motionY, takeOffYVelocity, 0.05 )) && ! mc. player.isElytraFlying) {
184+ if (baritoneBlockagePathing && player.onGround && timer.tick(JUMP_DELAY .toLong())) player.jump()
185+ if ((withinRange(player.motionY)) && ! player.isElytraFlying) {
185186 timer.reset()
186187 currentState = State .FLYING
187- } else if (midairFallFly && mc. player.isElytraFlying) {
188+ } else if (midairFallFly && player.isElytraFlying) {
188189 connection.sendPacket(CPacketPlayer (true ))
189190 }
190191 }
191192 State .FLYING -> {
192193 if (autoViewLockManage && ViewLock .isDisabled) ViewLock .enable()
193- if (! mc. player.isElytraFlying && flyTickCount++ > 30 ) {
194+ if (! player.isElytraFlying && flyTickCount++ > 30 ) {
194195 pathForward()
195196 currentState = State .WALKING
196197 } else flyTickCount = 0
197- val playerCurrentPos = mc. player.positionVector
198+ val playerCurrentPos = player.positionVector
198199 if (! avoidUnloaded || (avoidUnloaded && nextBlockMoveLoaded)) {
199200 if (playerCurrentPos.distanceTo(flyPlayerLastPos) < 2.0 ) {
200201 if (flyBlockedTickCount++ > 20 ) {
@@ -207,7 +208,9 @@ object ElytraFlight2b2t : Module(
207208 if (! enableBoost) return @safeListener
208209 if (shouldStartBoosting) {
209210 if (avoidUnloaded) {
210- if (nextBlockMoveLoaded && isFlying) setFlightSpeed(currentFlightSpeed + boostSpeedIncrease)
211+ if (nextBlockMoveLoaded && isFlying) {
212+ setFlightSpeed(currentFlightSpeed + boostSpeedIncrease)
213+ }
211214 } else setFlightSpeed(currentFlightSpeed + boostSpeedIncrease)
212215 } else if (timer.tick(boostDelayTicks, true )) shouldStartBoosting = true
213216 }
@@ -220,7 +223,7 @@ object ElytraFlight2b2t : Module(
220223 if (System .currentTimeMillis() - lastSPacketPlayerPosLook < rubberBandDetectionTime.toLong()) {
221224 resetFlightSpeed()
222225 shouldStartBoosting = false
223- mc.timer.tickLength = 50.0f
226+ resetTimer()
224227 wasInLiquid = false
225228 isFlying = false
226229 currentState = if (baritoneBlockagePathing) {
@@ -233,16 +236,15 @@ object ElytraFlight2b2t : Module(
233236 }
234237
235238 safeListener<PacketEvent .Send > {
236- if (avoidUnloaded && ! nextBlockMoveLoaded && it.packet is CPacketPlayer )
237- it.cancel()
239+ if (avoidUnloaded && ! nextBlockMoveLoaded && it.packet is CPacketPlayer ) it.cancel()
238240 }
239241
240242 safeListener<PlayerTravelEvent > {
241243 stateUpdate()
242244 if (currentState == State .FLYING && elytraIsEquipped && elytraDurability > 1 ) {
243245 if (stoppedFlying) setFlightSpeed(currentFlightSpeed / redeploySpeedDecreaseFactor)
244246 if (isFlying) {
245- mc.timer.tickLength = 50.0f
247+ resetTimer()
246248 player.isSprinting = false
247249 } else takeoff(it)
248250 }
@@ -253,14 +255,14 @@ object ElytraFlight2b2t : Module(
253255 safeListener<PlayerMoveEvent > {
254256 if (currentState == State .FLYING ) {
255257 if (avoidUnloaded) {
256- if (nextBlockMoveLoaded && ! mc. world.isBlockLoaded(BlockPos (mc. player.posX + it.x, mc. player.posY, mc. player.posZ + it.z), false )) {
258+ if (nextBlockMoveLoaded && ! world.isBlockLoaded(BlockPos (player.posX + it.x, player.posY, player.posZ + it.z), false )) {
257259 nextBlockMoveLoaded = false
258260 motionPrev = Vec2f (it.x.toFloat(), it.z.toFloat())
259261 setSpeed(0.0 )
260262 player.motionY = 0.0
261263 return @safeListener
262264 } else if (! nextBlockMoveLoaded) {
263- if (! mc. world.isBlockLoaded(BlockPos (mc. player.posX + motionPrev.x, 1.0 , mc. player.posZ + motionPrev.y), false )) {
265+ if (! world.isBlockLoaded(BlockPos (player.posX + motionPrev.x, 1.0 , player.posZ + motionPrev.y), false )) {
264266 setSpeed(0.0 )
265267 player.motionY = 0.0
266268 return @safeListener
@@ -274,19 +276,17 @@ object ElytraFlight2b2t : Module(
274276 }
275277
276278 safeListener<InputUpdateEvent > {
277- if (autoFlyForward && (currentState == State .FLYING || currentState == State .TAKEOFF ) && ! mc. player.onGround) {
279+ if (autoFlyForward && (currentState == State .FLYING || currentState == State .TAKEOFF ) && ! player.onGround) {
278280 it.movementInput.moveStrafe = 0.0f
279281 it.movementInput.moveForward = 1.0f
280282 }
281283 }
282284 }
283285
284- private fun withinRange (num : Double , target : Double , range : Double ): Boolean {
285- return (num >= target - range && num <= target + range)
286- }
286+ private fun withinRange (motion : Double ) = motion >= TAKE_OFF_Y_VELOCITY - 0.05 && motion <= TAKE_OFF_Y_VELOCITY + 0.05
287287
288288 private fun resetFlightSpeed () {
289- setFlightSpeed(this . initialFlightSpeed)
289+ setFlightSpeed(initialFlightSpeed)
290290 }
291291
292292 private fun setFlightSpeed (speed : Double ) {
@@ -299,9 +299,9 @@ object ElytraFlight2b2t : Module(
299299 elytraIsEquipped = armorSlot.item == Items .ELYTRA
300300
301301 /* Elytra Durability Check */
302- if (elytraIsEquipped) {
303- elytraDurability = armorSlot.maxDamage - armorSlot.itemDamage
304- } else elytraDurability = 0
302+ elytraDurability = if (elytraIsEquipped) {
303+ armorSlot.maxDamage - armorSlot.itemDamage
304+ } else 0
305305
306306 /* wasInLiquid check */
307307 if (player.isInWater || player.isInLava) {
@@ -324,25 +324,27 @@ object ElytraFlight2b2t : Module(
324324 val timerSpeed = takeoffTimerSpeed
325325 val height = 0.1
326326 val closeToGround = player.posY <= world.getGroundPos(player).y + height && ! wasInLiquid && ! mc.isSingleplayer
327+
327328 if (player.motionY >= - 0.02 ) return
328329 if (closeToGround) {
329- mc.timer.tickLength = 50.0f
330+ resetTimer()
330331 return
331332 }
332333 if (! wasInLiquid && ! mc.isSingleplayer) {
333334 event.cancel()
334335 player.setVelocity(0.0 , - 0.02 , 0.0 )
335336 }
336- if (! mc.isSingleplayer) mc.timer.tickLength = timerSpeed * 2.0f
337+
338+ if (! mc.isSingleplayer) modifyTimer(timerSpeed * 2.0f )
337339 connection.sendPacket(CPacketEntityAction (player, CPacketEntityAction .Action .START_FALL_FLYING ))
338340 }
339341
340342 private fun SafeClientEvent.spoofRotation () {
341343 if (player.isSpectator || ! elytraIsEquipped || elytraDurability <= 1 || ! isFlying) return
342344 var rotation = com.lambda.client.util.math.Vec2f (player)
343- if (! isStandingStill) rotation = com.lambda.client.util.math.Vec2f (rotation.x, magicPitch )
345+ if (! isStandingStill) rotation = com.lambda.client.util.math.Vec2f (rotation.x, MAGIC_PITCH )
344346 /* Cancels rotation packets if player is not moving and not clicking */
345- var cancelRotation = isStandingStill
347+ val cancelRotation = isStandingStill
346348 && ((! mc.gameSettings.keyBindUseItem.isKeyDown && ! mc.gameSettings.keyBindAttack.isKeyDown))
347349 sendPlayerPacket {
348350 if (cancelRotation) {
@@ -354,17 +356,18 @@ object ElytraFlight2b2t : Module(
354356 }
355357
356358 private fun SafeClientEvent.pathForward () {
357- beforePathingPlayerPitchYaw = mc. player.pitchYaw
359+ beforePathingPlayerPitchYaw = player.pitchYaw
358360 if (scheduleBaritoneJob?.isActive == true ) return
359361 baritoneStartTime = System .currentTimeMillis()
360362 scheduleBaritoneJob = defaultScope.launch {
361363 delay(baritoneStartDelayMs.toLong())
362- val playerContext = BaritoneUtils .primary?.playerContext!!
363- BaritoneUtils .primary?.customGoalProcess?.setGoalAndPath(GoalXZ .fromDirection(
364- playerContext.playerFeetAsVec(),
365- playerContext.player().rotationYawHead,
366- baritonePathForwardBlocks.toDouble()
367- ))
364+ BaritoneUtils .primary?.playerContext?.let {
365+ BaritoneUtils .primary?.customGoalProcess?.setGoalAndPath(GoalXZ .fromDirection(
366+ it.playerFeetAsVec(),
367+ it.player().rotationYawHead,
368+ baritonePathForwardBlocks.toDouble()
369+ ))
370+ }
368371 }
369372 }
370373
0 commit comments