1- package com.lambda.manager
1+ package com.lambda.interaction
22
33import com.lambda.Lambda.LOG
44import com.lambda.Lambda.mc
@@ -11,15 +11,14 @@ import com.lambda.event.events.RotationEvent
1111import com.lambda.event.events.TickEvent
1212import com.lambda.event.listener.SafeListener.Companion.listener
1313import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener
14- import com.lambda.interaction.rotation.Rotation
14+ import com.lambda.interaction.rotation.*
1515import com.lambda.interaction.rotation.Rotation.Companion.angleDifference
1616import com.lambda.interaction.rotation.Rotation.Companion.fixSensitivity
1717import com.lambda.interaction.rotation.Rotation.Companion.interpolate
18- import com.lambda.interaction.rotation.RotationContext
19- import com.lambda.interaction.rotation.RotationMode
2018import com.lambda.module.modules.client.Baritone
2119import com.lambda.threading.runOnGameThread
2220import com.lambda.threading.runSafe
21+ import com.lambda.util.Communication.info
2322import com.lambda.util.math.MathUtils.lerp
2423import com.lambda.util.math.MathUtils.toRadian
2524import com.lambda.util.math.Vec2d
@@ -34,7 +33,7 @@ object RotationManager : Loadable {
3433 var currentRotation = Rotation .ZERO
3534 private var prevRotation = Rotation .ZERO
3635
37- var currentContext : RotationContext ? = null
36+ var currentRequest : RotationRequest ? = null
3837
3938 private var keepTicks = 0
4039 private var pauseTicks = 0
@@ -43,11 +42,25 @@ object RotationManager : Loadable {
4342 fun update () =
4443 runSafe {
4544 EventFlow .post(RotationEvent .Pre ()) {
46- rotate()
45+ rotate()?.let {
46+ EventFlow .post(RotationEvent .Post (it))
47+ }
4748 }
48- EventFlow .post(RotationEvent .Post ())
4949 }
5050
51+ @JvmStatic
52+ fun updateInterpolated () = runSafe {
53+ // if (currentRequest == null) return@runSafe
54+ // val interpolation = interpolate(prevRotation, currentRotation, mc.tickDelta.toDouble())
55+ //
56+ // val rot = interpolation.fixSensitivity(prevRotation)
57+ //
58+ // if (currentRequest?.config?.rotationMode == RotationMode.LOCK) {
59+ // player.yaw = rot.yaw.toFloat()
60+ // player.pitch = rot.pitch.toFloat()
61+ // }
62+ }
63+
5164 init {
5265 listener<PacketEvent .Send .Post > { event ->
5366 val packet = event.packet
@@ -69,75 +82,87 @@ object RotationManager : Loadable {
6982 (keepTicks-- ).coerceAtLeast(0 )
7083 (pauseTicks-- ).coerceAtLeast(0 )
7184
72- val resetTicks = currentContext ?.config?.resetTicks ? : 0
85+ val resetTicks = currentRequest ?.config?.resetTicks ? : 0
7386 if (keepTicks + resetTicks < 0 || pauseTicks >= 0 ) {
74- currentContext = null
87+ currentRequest = null
7588 }
7689
77- requests.firstOrNull()?.let {
78- currentContext = RotationContext (it.config, it.rotation)
79- keepTicks = it.config.keepTicks
90+ var chosenRequest: RotationRequest ? = null
91+
92+ requests.firstOrNull()?.let { request ->
93+ chosenRequest = request
94+ currentRequest = request
95+ keepTicks = request.config.keepTicks
8096 }
8197
8298 currentRotation = Rotation (player.yaw, player.pitch)
8399
84- val context = currentContext ? : return @runSafe
100+ val context = currentRequest ? : return @runSafe chosenRequest
85101 val rotationTo = if (keepTicks >= 0 ) context.rotation else currentRotation
86102
87103 var speedMultiplier = (context.config as ? RotationSettings )?.speedMultiplier ? : 1.0
88104 if (keepTicks < 0 ) speedMultiplier = 1.0
89105
90106 val turnSpeed = context.config.turnSpeed * speedMultiplier
91107
92- currentRotation = interpolate(prevRotation, rotationTo, turnSpeed)
93- .fixSensitivity(prevRotation)
108+ val interpolation = interpolate(prevRotation, rotationTo, turnSpeed)
109+
110+ currentRotation = interpolation.fixSensitivity(prevRotation)
94111
95112 if (context.config.rotationMode == RotationMode .LOCK ) {
96113 player.yaw = currentRotation.yaw.toFloat()
97114 player.pitch = currentRotation.pitch.toFloat()
98115 }
116+
117+ chosenRequest?.let { request ->
118+ if (request.rotation.fixSensitivity(prevRotation) == currentRotation) {
119+ request.isPending = false
120+ }
121+ }
122+
123+ return @runSafe chosenRequest
99124 }
100125
101126 private fun reset (rotation : Rotation ) {
102127 prevRotation = rotation
103128 currentRotation = rotation
104129
105- currentContext = null
130+ currentRequest = null
106131 pauseTicks = 3
107132 }
108133
109134 private val smoothRotation get() =
110135 lerp(prevRotation, currentRotation, mc.partialTicks)
111136
112137 @JvmStatic val lockRotation get() =
113- if (currentContext ?.config?.rotationMode == RotationMode .LOCK ) smoothRotation else null
138+ if (currentRequest ?.config?.rotationMode == RotationMode .LOCK ) smoothRotation else null
114139
115140 @JvmStatic val renderYaw get() =
116- if (currentContext ?.config == null ) null else smoothRotation.yaw.toFloat()
141+ if (currentRequest ?.config == null ) null else smoothRotation.yaw.toFloat()
117142
118143 @JvmStatic val renderPitch get() =
119- if (currentContext ?.config == null ) null else smoothRotation.pitch.toFloat()
144+ if (currentRequest ?.config == null ) null else smoothRotation.pitch.toFloat()
120145
121146 @JvmStatic val handYaw get() =
122- if (currentContext ?.config?.rotationMode == RotationMode .LOCK ) currentRotation.yaw.toFloat() else null
147+ if (currentRequest ?.config?.rotationMode == RotationMode .LOCK ) currentRotation.yaw.toFloat() else null
123148
124149 @JvmStatic val handPitch get() =
125- if (currentContext ?.config?.rotationMode == RotationMode .LOCK ) currentRotation.pitch.toFloat() else null
150+ if (currentRequest ?.config?.rotationMode == RotationMode .LOCK ) currentRotation.pitch.toFloat() else null
126151
127152 @JvmStatic val movementYaw: Float? get() {
128- val config = currentContext ?.config ? : return null
153+ val config = currentRequest ?.config ? : return null
129154 if (config.rotationMode == RotationMode .SILENT ) return null
130155 return currentRotation.yaw.toFloat()
131156 }
132157
133158 @JvmStatic val movementPitch: Float? get() {
134- val config = currentContext ?.config ? : return null
159+ val config = currentRequest ?.config ? : return null
135160 if (config.rotationMode == RotationMode .SILENT ) return null
136161 return currentRotation.pitch.toFloat()
137162 }
138163
139164 @JvmStatic fun getRotationForVector (deltaTime : Double ): Vec2d ? {
140- val config = currentContext ?.config ? : return null
165+ val config = currentRequest ?.config ? : return null
141166 if (config.rotationMode == RotationMode .SILENT ) return null
142167
143168 val rot = lerp(prevRotation, currentRotation, deltaTime)
@@ -167,7 +192,7 @@ object RotationManager : Loadable {
167192
168193 @JvmStatic
169194 fun processPlayerMovement () = runSafe {
170- val config = currentContext ?.config ? : return @runSafe
195+ val config = currentRequest ?.config ? : return @runSafe
171196
172197 val input = player.input
173198 val handledByBaritone = input !is KeyboardInput
0 commit comments