@@ -10,17 +10,18 @@ import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener
1010import com.lambda.interaction.rotation.Rotation
1111import com.lambda.interaction.rotation.Rotation.Companion.angleDifference
1212import com.lambda.interaction.rotation.Rotation.Companion.fixSensitivity
13- import com.lambda.interaction.rotation.Rotation.Companion.interpolate
13+ import com.lambda.interaction.rotation.Rotation.Companion.slerp
14+ import com.lambda.interaction.rotation.Rotation.Companion.lerp
1415import com.lambda.interaction.rotation.RotationContext
1516import com.lambda.interaction.rotation.RotationMode
16- import com.lambda.interaction.rotation.RotationRequest
1717import com.lambda.module.modules.client.Baritone
1818import com.lambda.threading.runOnGameThread
1919import com.lambda.threading.runSafe
2020import com.lambda.util.math.MathUtils.lerp
2121import com.lambda.util.math.MathUtils.toRadian
2222import com.lambda.util.math.Vec2d
2323import com.lambda.util.primitives.extension.partialTicks
24+ import com.lambda.util.primitives.extension.rotation
2425import net.minecraft.client.input.KeyboardInput
2526import net.minecraft.enchantment.EnchantmentHelper
2627import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
@@ -30,9 +31,9 @@ import kotlin.math.sign
3031
3132object RotationManager : Loadable {
3233 var currentRotation = Rotation .ZERO
33- private var prevRotation = Rotation .ZERO
34+ var prevRotation = Rotation .ZERO
3435
35- var currentRequest : RotationRequest ? = null
36+ var currentContext : RotationContext ? = null
3637
3738 private var keepTicks = 0
3839 private var pauseTicks = 0
@@ -41,9 +42,8 @@ object RotationManager : Loadable {
4142 fun update () =
4243 runSafe {
4344 RotationEvent .Pre ().post {
44- rotate()?.let {
45- RotationEvent .Post (it).post()
46- }
45+ rotate(context)
46+ currentContext?.let { RotationEvent .Post (it).post() }
4747 }
4848 }
4949
@@ -58,108 +58,97 @@ object RotationManager : Loadable {
5858 }
5959
6060 listener<RenderEvent .UpdateTarget > {
61- if (currentRequest == null ) return @listener
62- if (currentRequest? .config? .rotationMode != RotationMode .LOCK ) return @listener
63- val interpolation = prevRotation.interpolate (currentRotation, mc.tickDelta.toDouble())
61+ val context = currentContext ? : return @listener
62+ if (context .config.rotationMode != RotationMode .LOCK ) return @listener
63+ val interpolation = prevRotation.lerp (currentRotation, mc.tickDelta.toDouble())
6464
65- // val rot = interpolation.fixSensitivity(prevRotation)
66-
67- player.yaw = interpolation.yaw.toFloat()
68- player.pitch = interpolation.pitch.toFloat()
65+ player.yaw = interpolation.yawF
66+ player.pitch = interpolation.pitchF
6967 }
7068
7169 unsafeListener<ConnectionEvent .Disconnect > {
7270 reset(Rotation .ZERO )
7371 }
7472 }
7573
76- private fun RotationEvent.Pre. rotate () = runSafe {
74+ private fun rotate (newContext : RotationContext ? ) = runSafe {
7775 prevRotation = currentRotation
7876
7977 (keepTicks-- ).coerceAtLeast(0 )
8078 (pauseTicks-- ).coerceAtLeast(0 )
8179
82- val resetTicks = currentRequest?.config?.resetTicks ? : 0
83- if (keepTicks + resetTicks < 0 || pauseTicks >= 0 ) {
84- currentRequest = null
80+ currentContext?.let { current ->
81+ if (keepTicks + current.config.resetTicks < 0 || pauseTicks >= 0 ) {
82+ currentContext = null
83+ }
8584 }
8685
87- var chosenRequest: RotationRequest ? = null
88-
89- requests.firstOrNull()?.let { request ->
90- chosenRequest = request
91- currentRequest = request
86+ newContext?.let { request ->
87+ currentContext = request
9288 keepTicks = request.config.keepTicks
9389 }
9490
95- currentRotation = Rotation (player.yaw, player.pitch)
96-
97- val context = currentRequest ? : return @runSafe chosenRequest
98- val rotationTo = if (keepTicks >= 0 ) context.rotation else currentRotation
91+ currentContext?.let { current ->
92+ val rotationTo = if (keepTicks >= 0 ) current.rotation else currentRotation
9993
100- var speedMultiplier = (context .config as ? RotationSettings )?.speedMultiplier ? : 1.0
101- if (keepTicks < 0 ) speedMultiplier = 1.0
94+ var speedMultiplier = (current .config as ? RotationSettings )?.speedMultiplier ? : 1.0
95+ if (keepTicks < 0 ) speedMultiplier = 1.0
10296
103- val turnSpeed = context .config.turnSpeed * speedMultiplier
97+ val turnSpeed = current .config.turnSpeed * speedMultiplier
10498
105- val interpolation = prevRotation.interpolate (rotationTo, turnSpeed)
99+ val interpolation = prevRotation.slerp (rotationTo, turnSpeed)
106100
107- currentRotation = interpolation.fixSensitivity(prevRotation)
101+ currentRotation = interpolation.fixSensitivity(prevRotation)
108102
109- if (context.config.rotationMode == RotationMode .LOCK ) {
110- player.yaw = currentRotation.yaw.toFloat()
111- player.pitch = currentRotation.pitch.toFloat()
112- }
113-
114- chosenRequest?.let { request ->
115- if (request.rotation.fixSensitivity(prevRotation) == currentRotation) {
116- request.isPending = false
103+ if (current.config.rotationMode == RotationMode .LOCK ) {
104+ player.yaw = currentRotation.yaw.toFloat()
105+ player.pitch = currentRotation.pitch.toFloat()
117106 }
107+ } ? : run {
108+ currentRotation = player.rotation
118109 }
119-
120- return @runSafe chosenRequest
121110 }
122111
123112 private fun reset (rotation : Rotation ) {
124113 prevRotation = rotation
125114 currentRotation = rotation
126115
127- currentRequest = null
116+ currentContext = null
128117 pauseTicks = 3
129118 }
130119
131120 private val smoothRotation get() =
132121 lerp(prevRotation, currentRotation, mc.partialTicks)
133122
134123 @JvmStatic val lockRotation get() =
135- if (currentRequest ?.config?.rotationMode == RotationMode .LOCK ) smoothRotation else null
124+ if (currentContext ?.config?.rotationMode == RotationMode .LOCK ) smoothRotation else null
136125
137126 @JvmStatic val renderYaw get() =
138- if (currentRequest ?.config == null ) null else smoothRotation.yaw.toFloat()
127+ if (currentContext ?.config == null ) null else smoothRotation.yaw.toFloat()
139128
140129 @JvmStatic val renderPitch get() =
141- if (currentRequest ?.config == null ) null else smoothRotation.pitch.toFloat()
130+ if (currentContext ?.config == null ) null else smoothRotation.pitch.toFloat()
142131
143132 @JvmStatic val handYaw get() =
144- if (currentRequest ?.config?.rotationMode == RotationMode .LOCK ) currentRotation.yaw.toFloat() else null
133+ if (currentContext ?.config?.rotationMode == RotationMode .LOCK ) currentRotation.yaw.toFloat() else null
145134
146135 @JvmStatic val handPitch get() =
147- if (currentRequest ?.config?.rotationMode == RotationMode .LOCK ) currentRotation.pitch.toFloat() else null
136+ if (currentContext ?.config?.rotationMode == RotationMode .LOCK ) currentRotation.pitch.toFloat() else null
148137
149138 @JvmStatic val movementYaw: Float? get() {
150- val config = currentRequest ?.config ? : return null
139+ val config = currentContext ?.config ? : return null
151140 if (config.rotationMode == RotationMode .SILENT ) return null
152141 return currentRotation.yaw.toFloat()
153142 }
154143
155144 @JvmStatic val movementPitch: Float? get() {
156- val config = currentRequest ?.config ? : return null
145+ val config = currentContext ?.config ? : return null
157146 if (config.rotationMode == RotationMode .SILENT ) return null
158147 return currentRotation.pitch.toFloat()
159148 }
160149
161150 @JvmStatic fun getRotationForVector (deltaTime : Double ): Vec2d ? {
162- val config = currentRequest ?.config ? : return null
151+ val config = currentContext ?.config ? : return null
163152 if (config.rotationMode == RotationMode .SILENT ) return null
164153
165154 val rot = lerp(prevRotation, currentRotation, deltaTime)
@@ -188,12 +177,12 @@ object RotationManager : Loadable {
188177
189178 @JvmStatic
190179 fun handleBaritoneRotation (yaw : Float , pitch : Float ) = runSafe {
191- baritoneContext = RotationContext (Baritone .rotation, Rotation (yaw, pitch))
180+ baritoneContext = RotationContext (Rotation (yaw, pitch), Baritone .rotation )
192181 }
193182
194183 @JvmStatic
195184 fun processPlayerMovement () = runSafe {
196- val config = currentRequest ?.config ? : return @runSafe
185+ val config = currentContext ?.config ? : return @runSafe
197186
198187 val input = player.input
199188 val handledByBaritone = input !is KeyboardInput
0 commit comments