@@ -5,15 +5,20 @@ import com.lambda.client.event.events.OnUpdateWalkingPlayerEvent
55import com.lambda.client.event.events.PacketEvent
66import com.lambda.client.event.events.PlayerTravelEvent
77import com.lambda.client.event.listener.listener
8+ import com.lambda.client.manager.managers.PacketManager
89import com.lambda.client.manager.managers.PlayerPacketManager.sendPlayerPacket
10+ import com.lambda.client.mixin.extension.playerPosLookPitch
11+ import com.lambda.client.mixin.extension.playerPosLookYaw
912import com.lambda.client.module.Category
1013import com.lambda.client.module.Module
1114import com.lambda.client.util.MovementUtils
1215import com.lambda.client.util.MovementUtils.calcMoveYaw
1316import com.lambda.client.util.threads.runSafe
1417import com.lambda.client.util.threads.safeListener
18+ import net.minecraft.network.play.client.CPacketConfirmTeleport
1519import net.minecraft.network.play.client.CPacketPlayer
1620import net.minecraft.network.play.server.SPacketCloseWindow
21+ import net.minecraft.network.play.server.SPacketPlayerPosLook
1722import kotlin.math.cos
1823import kotlin.math.sin
1924
@@ -23,12 +28,23 @@ object Flight : Module(
2328 category = Category .MOVEMENT ,
2429 modulePriority = 500
2530) {
26- private val mode by setting(" Mode" , FlightMode .VANILLA )
31+ private val mode by setting(" Mode" , FlightMode .PACKET )
2732 private val speed by setting(" Speed" , 1.0f , 0.0f .. 10.0f , 0.1f )
2833 private val glideSpeed by setting(" Glide Speed" , 0.05 , 0.0 .. 0.3 , 0.001 )
34+ private val packetMode by setting(" Packet Mode" , PacketMode .NEGATIVE , { mode == FlightMode .PACKET })
35+ private val upSpeed by setting(" Up Speed" , 0.0622 , 0.0 .. 0.3 , 0.001 , { mode == FlightMode .PACKET })
36+ private val antiKick by setting(" Anti Kick" , true , { mode == FlightMode .PACKET })
37+ private val antiKickSpeed by setting(" Anti Kick Speed" , 0.0622 , 0.0 .. 0.3 , 0.001 , { mode == FlightMode .PACKET && antiKick })
38+ private val antiKickDelay by setting(" Anti Kick Delay" , 14 , 0 .. 100 , 1 , { mode == FlightMode .PACKET && antiKick})
39+ private val hShrinkAmount by setting(" Horizontal Shrink Amount" , 4.0 , 1.0 .. 10.0 , 0.1 , { mode == FlightMode .PACKET })
40+ private val vShrinkAmount by setting(" Vertical Shrink Amount" , 2.70 , 1.0 .. 10.0 , 0.1 , { mode == FlightMode .PACKET })
2941
3042 private enum class FlightMode {
31- VANILLA , STATIC , PACKET
43+ PACKET , VANILLA , STATIC
44+ }
45+
46+ private enum class PacketMode {
47+ POSITIVE , NEGATIVE
3248 }
3349
3450 init {
@@ -43,6 +59,41 @@ object Flight : Module(
4359
4460 safeListener<PlayerTravelEvent > {
4561 when (mode) {
62+ FlightMode .PACKET -> {
63+ it.cancel()
64+
65+ player.motionY = if (mc.gameSettings.keyBindJump.isKeyDown xor mc.gameSettings.keyBindSneak.isKeyDown) {
66+ if (mc.gameSettings.keyBindJump.isKeyDown) {
67+ if (player.ticksExisted % antiKickDelay == 0 && antiKick) {
68+ - antiKickSpeed / vShrinkAmount
69+ } else {
70+ upSpeed / vShrinkAmount
71+ }
72+ } else (- upSpeed / vShrinkAmount)
73+ } else {
74+ if (MovementUtils .isInputting) {
75+ val yaw = calcMoveYaw()
76+ player.motionX = (- sin(yaw) * 0.2f * speed) / hShrinkAmount
77+ player.motionZ = (cos(yaw) * 0.2f * speed) / hShrinkAmount
78+ }
79+ - glideSpeed / vShrinkAmount
80+ }
81+
82+ val posX = player.posX + (player.motionX * hShrinkAmount)
83+ val posY = player.posY + (player.motionY * vShrinkAmount)
84+ val posZ = player.posZ + (player.motionZ * hShrinkAmount)
85+
86+ val invalidPacketOffset = when (packetMode) {
87+ PacketMode .POSITIVE -> 1000
88+ PacketMode .NEGATIVE -> - 1000
89+ }
90+
91+ connection.sendPacket(CPacketPlayer .Position (posX, posY, posZ, false ))
92+ connection.sendPacket(CPacketPlayer .Position (posX, player.posY + invalidPacketOffset, posZ, false ))
93+ if (PacketManager .lastTeleportId != - 1 ) {
94+ connection.sendPacket(CPacketConfirmTeleport (PacketManager .lastTeleportId++ ))
95+ }
96+ }
4697 FlightMode .STATIC -> {
4798 player.capabilities.isFlying = true
4899 player.capabilities.flySpeed = speed
@@ -62,40 +113,27 @@ object Flight : Module(
62113 && ! mc.gameSettings.keyBindJump.isKeyDown
63114 && ! mc.gameSettings.keyBindSneak.isKeyDown) player.motionY = - glideSpeed
64115 }
65- FlightMode .PACKET -> {
66- it.cancel()
67-
68- player.motionY = if (mc.gameSettings.keyBindJump.isKeyDown xor mc.gameSettings.keyBindSneak.isKeyDown) {
69- if (mc.gameSettings.keyBindJump.isKeyDown) 0.0622
70- else - 0.0622
71- } else {
72- if (MovementUtils .isInputting) {
73- val yaw = calcMoveYaw()
74- player.motionX = - sin(yaw) * 0.2f
75- player.motionZ = cos(yaw) * 0.2f
76- }
77- - glideSpeed
78- }
79-
80- val posX = player.posX + player.motionX
81- val posY = player.posY + player.motionY
82- val posZ = player.posZ + player.motionZ
83-
84- connection.sendPacket(CPacketPlayer .PositionRotation (posX, posY, posZ, player.rotationYaw, player.rotationPitch, false ))
85- connection.sendPacket(CPacketPlayer .Position (posX, player.posY - 42069 , posZ, true ))
86- }
87116 }
88117 }
89118
90119 listener<OnUpdateWalkingPlayerEvent > {
91- if (mode != FlightMode . PACKET || it.phase != Phase . PRE ) return @listener
120+ if (it.phase != Phase . PRE || mode != FlightMode . PACKET ) return @listener
92121 sendPlayerPacket {
93122 cancelAll()
94123 }
95124 }
96125
97- listener<PacketEvent .Receive > {
98- if (mode == FlightMode .PACKET && it.packet is SPacketCloseWindow ) it.cancel()
126+ safeListener<PacketEvent .Receive > {
127+ if (mode != FlightMode .PACKET ) return @safeListener
128+ when (it.packet) {
129+ is SPacketPlayerPosLook -> {
130+ it.packet.playerPosLookYaw = player.rotationYaw
131+ it.packet.playerPosLookPitch = player.rotationPitch
132+ }
133+ is SPacketCloseWindow -> {
134+ it.cancel()
135+ }
136+ }
99137 }
100138 }
101139}
0 commit comments