@@ -7,8 +7,8 @@ import com.lambda.client.event.events.PacketEvent
7
7
import com.lambda.client.event.events.PlayerMoveEvent
8
8
import com.lambda.client.event.events.PlayerTravelEvent
9
9
import 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
12
12
import com.lambda.client.module.Category
13
13
import com.lambda.client.module.Module
14
14
import com.lambda.client.module.modules.player.ViewLock
@@ -41,29 +41,29 @@ object ElytraFlight2b2t : Module(
41
41
category = Category .MOVEMENT ,
42
42
modulePriority = 1000
43
43
) {
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 ,
45
45
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 " )
47
47
private val baritoneBlockagePathing by setting(" Baritone Blockage Pathing" , true ,
48
48
description = " Use baritone to path around blockages on the highway." )
49
49
private val baritonePathForwardBlocks by setting(" Baritone Path Distance" , 20 , 1 .. 50 , 1 ,
50
50
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 " )
55
55
private val midairFallFly by setting(" Mid-flight Packet Deploy" , true ,
56
56
description = " Uses packets to redeploy when mid-flight." )
57
57
private val autoFlyForward by setting(" Auto Fly Forward" , true ,
58
58
description = " Automatically move forward when flying." )
59
59
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 ,
62
62
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 " ,
65
65
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 ,
67
67
visibility = { enableBoost },
68
68
description = " Boost speed increase per tick (blocks per second / 2)" )
69
69
private val initialFlightSpeed by setting(" Initial Flight Speed" , 39.5 , 35.0 .. 80.0 , 0.01 ,
@@ -77,62 +77,63 @@ object ElytraFlight2b2t : Module(
77
77
private val autoViewLockManage by setting(" Auto ViewLock Manage" , true ,
78
78
description = " Automatically configures and toggles viewlock for straight flight on highways." )
79
79
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
+
82
84
private var currentState = State .PAUSED
85
+ private var isFlying = false
86
+ private var isBaritoning = false
87
+
83
88
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
86
95
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
90
97
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
96
103
private var flyTickCount = 0
97
- private var flyPlayerLastPos: Vec3d = Vec3d .ZERO
98
104
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
+
103
111
private var scheduleBaritoneJob: Job ? = null
104
- private var motionPrev: Vec2f = Vec2f (0.0f , 0.0f )
105
- private const val jumpDelay: Int = 10
106
112
107
113
enum class State {
108
114
FLYING , TAKEOFF , PAUSED , WALKING
109
115
}
110
116
111
- override fun getHudInfo (): String {
112
- return currentState.name
113
- }
117
+ override fun getHudInfo () = currentState.name
114
118
115
119
init {
116
-
117
120
onEnable {
118
121
currentState = State .PAUSED
119
122
timer.reset()
120
123
shouldStartBoosting = false
121
124
lastRubberband = Long .MIN_VALUE
122
- if (autoViewLockManage)
123
- configureViewLock()
125
+ if (autoViewLockManage) configureViewLock()
124
126
}
125
127
126
128
onDisable {
127
129
currentState = State .PAUSED
128
130
resetFlightSpeed()
129
131
BaritoneUtils .cancelEverything()
130
132
shouldStartBoosting = false
131
- mc.timer.tickLength = 50.0f
133
+ resetTimer()
132
134
wasInLiquid = false
133
135
isFlying = false
134
- if (autoViewLockManage)
135
- ViewLock .disable()
136
+ if (autoViewLockManage) ViewLock .disable()
136
137
}
137
138
138
139
safeListener<ConnectionEvent .Disconnect > {
@@ -167,8 +168,8 @@ object ElytraFlight2b2t : Module(
167
168
// delay takeoff if we were pathing
168
169
if (isBaritoning) {
169
170
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
172
173
isBaritoning = false
173
174
return @safeListener
174
175
}
@@ -177,24 +178,24 @@ object ElytraFlight2b2t : Module(
177
178
}
178
179
State .TAKEOFF -> {
179
180
if (autoViewLockManage && ViewLock .isDisabled) ViewLock .enable()
180
- mc.timer.tickLength = 50.0f
181
+ resetTimer()
181
182
shouldStartBoosting = false
182
183
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) {
185
186
timer.reset()
186
187
currentState = State .FLYING
187
- } else if (midairFallFly && mc. player.isElytraFlying) {
188
+ } else if (midairFallFly && player.isElytraFlying) {
188
189
connection.sendPacket(CPacketPlayer (true ))
189
190
}
190
191
}
191
192
State .FLYING -> {
192
193
if (autoViewLockManage && ViewLock .isDisabled) ViewLock .enable()
193
- if (! mc. player.isElytraFlying && flyTickCount++ > 30 ) {
194
+ if (! player.isElytraFlying && flyTickCount++ > 30 ) {
194
195
pathForward()
195
196
currentState = State .WALKING
196
197
} else flyTickCount = 0
197
- val playerCurrentPos = mc. player.positionVector
198
+ val playerCurrentPos = player.positionVector
198
199
if (! avoidUnloaded || (avoidUnloaded && nextBlockMoveLoaded)) {
199
200
if (playerCurrentPos.distanceTo(flyPlayerLastPos) < 2.0 ) {
200
201
if (flyBlockedTickCount++ > 20 ) {
@@ -207,7 +208,9 @@ object ElytraFlight2b2t : Module(
207
208
if (! enableBoost) return @safeListener
208
209
if (shouldStartBoosting) {
209
210
if (avoidUnloaded) {
210
- if (nextBlockMoveLoaded && isFlying) setFlightSpeed(currentFlightSpeed + boostSpeedIncrease)
211
+ if (nextBlockMoveLoaded && isFlying) {
212
+ setFlightSpeed(currentFlightSpeed + boostSpeedIncrease)
213
+ }
211
214
} else setFlightSpeed(currentFlightSpeed + boostSpeedIncrease)
212
215
} else if (timer.tick(boostDelayTicks, true )) shouldStartBoosting = true
213
216
}
@@ -220,7 +223,7 @@ object ElytraFlight2b2t : Module(
220
223
if (System .currentTimeMillis() - lastSPacketPlayerPosLook < rubberBandDetectionTime.toLong()) {
221
224
resetFlightSpeed()
222
225
shouldStartBoosting = false
223
- mc.timer.tickLength = 50.0f
226
+ resetTimer()
224
227
wasInLiquid = false
225
228
isFlying = false
226
229
currentState = if (baritoneBlockagePathing) {
@@ -233,16 +236,15 @@ object ElytraFlight2b2t : Module(
233
236
}
234
237
235
238
safeListener<PacketEvent .Send > {
236
- if (avoidUnloaded && ! nextBlockMoveLoaded && it.packet is CPacketPlayer )
237
- it.cancel()
239
+ if (avoidUnloaded && ! nextBlockMoveLoaded && it.packet is CPacketPlayer ) it.cancel()
238
240
}
239
241
240
242
safeListener<PlayerTravelEvent > {
241
243
stateUpdate()
242
244
if (currentState == State .FLYING && elytraIsEquipped && elytraDurability > 1 ) {
243
245
if (stoppedFlying) setFlightSpeed(currentFlightSpeed / redeploySpeedDecreaseFactor)
244
246
if (isFlying) {
245
- mc.timer.tickLength = 50.0f
247
+ resetTimer()
246
248
player.isSprinting = false
247
249
} else takeoff(it)
248
250
}
@@ -253,14 +255,14 @@ object ElytraFlight2b2t : Module(
253
255
safeListener<PlayerMoveEvent > {
254
256
if (currentState == State .FLYING ) {
255
257
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 )) {
257
259
nextBlockMoveLoaded = false
258
260
motionPrev = Vec2f (it.x.toFloat(), it.z.toFloat())
259
261
setSpeed(0.0 )
260
262
player.motionY = 0.0
261
263
return @safeListener
262
264
} 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 )) {
264
266
setSpeed(0.0 )
265
267
player.motionY = 0.0
266
268
return @safeListener
@@ -274,19 +276,17 @@ object ElytraFlight2b2t : Module(
274
276
}
275
277
276
278
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) {
278
280
it.movementInput.moveStrafe = 0.0f
279
281
it.movementInput.moveForward = 1.0f
280
282
}
281
283
}
282
284
}
283
285
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
287
287
288
288
private fun resetFlightSpeed () {
289
- setFlightSpeed(this . initialFlightSpeed)
289
+ setFlightSpeed(initialFlightSpeed)
290
290
}
291
291
292
292
private fun setFlightSpeed (speed : Double ) {
@@ -299,9 +299,9 @@ object ElytraFlight2b2t : Module(
299
299
elytraIsEquipped = armorSlot.item == Items .ELYTRA
300
300
301
301
/* 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
305
305
306
306
/* wasInLiquid check */
307
307
if (player.isInWater || player.isInLava) {
@@ -324,25 +324,27 @@ object ElytraFlight2b2t : Module(
324
324
val timerSpeed = takeoffTimerSpeed
325
325
val height = 0.1
326
326
val closeToGround = player.posY <= world.getGroundPos(player).y + height && ! wasInLiquid && ! mc.isSingleplayer
327
+
327
328
if (player.motionY >= - 0.02 ) return
328
329
if (closeToGround) {
329
- mc.timer.tickLength = 50.0f
330
+ resetTimer()
330
331
return
331
332
}
332
333
if (! wasInLiquid && ! mc.isSingleplayer) {
333
334
event.cancel()
334
335
player.setVelocity(0.0 , - 0.02 , 0.0 )
335
336
}
336
- if (! mc.isSingleplayer) mc.timer.tickLength = timerSpeed * 2.0f
337
+
338
+ if (! mc.isSingleplayer) modifyTimer(timerSpeed * 2.0f )
337
339
connection.sendPacket(CPacketEntityAction (player, CPacketEntityAction .Action .START_FALL_FLYING ))
338
340
}
339
341
340
342
private fun SafeClientEvent.spoofRotation () {
341
343
if (player.isSpectator || ! elytraIsEquipped || elytraDurability <= 1 || ! isFlying) return
342
344
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 )
344
346
/* Cancels rotation packets if player is not moving and not clicking */
345
- var cancelRotation = isStandingStill
347
+ val cancelRotation = isStandingStill
346
348
&& ((! mc.gameSettings.keyBindUseItem.isKeyDown && ! mc.gameSettings.keyBindAttack.isKeyDown))
347
349
sendPlayerPacket {
348
350
if (cancelRotation) {
@@ -354,17 +356,18 @@ object ElytraFlight2b2t : Module(
354
356
}
355
357
356
358
private fun SafeClientEvent.pathForward () {
357
- beforePathingPlayerPitchYaw = mc. player.pitchYaw
359
+ beforePathingPlayerPitchYaw = player.pitchYaw
358
360
if (scheduleBaritoneJob?.isActive == true ) return
359
361
baritoneStartTime = System .currentTimeMillis()
360
362
scheduleBaritoneJob = defaultScope.launch {
361
363
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
+ }
368
371
}
369
372
}
370
373
0 commit comments