Skip to content

Commit 91afb8a

Browse files
committed
Fix rotations
1 parent c6dfd9d commit 91afb8a

1 file changed

Lines changed: 10 additions & 15 deletions

File tree

src/client/kotlin/com/github/fdh911/modules/macro/controls/CursorManager.kt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.fdh911.modules.macro.controls
22

33
import com.github.fdh911.utils.RandomizedArc
4+
import com.github.fdh911.utils.mc
45
import com.github.fdh911.utils.plus
56
import com.github.fdh911.utils.times
67
import kotlinx.coroutines.CompletableDeferred
@@ -10,6 +11,7 @@ import org.joml.Vector2f
1011
import org.lwjgl.glfw.GLFW.*
1112
import kotlin.math.PI
1213
import kotlin.math.cos
14+
import kotlin.math.floor
1315
import kotlin.math.min
1416
import kotlin.random.Random
1517

@@ -18,12 +20,11 @@ object CursorManager
1820
var isMouseLocked = false
1921

2022
suspend fun moveMouseCursor(xPos: Int, yPos: Int) {
21-
val client = MinecraftClient.getInstance()
22-
val windowPtr = client.window.handle
23+
val hwnd = mc.window.handle
2324

2425
val xPtr = doubleArrayOf(0.0)
2526
val yPtr = doubleArrayOf(0.0)
26-
glfwGetCursorPos(windowPtr, xPtr, yPtr)
27+
glfwGetCursorPos(hwnd, xPtr, yPtr)
2728

2829
val start = Vector2f(xPtr[0].toFloat(), yPtr[0].toFloat())
2930
val end = Vector2f(xPos.toFloat(), yPos.toFloat())
@@ -34,7 +35,7 @@ object CursorManager
3435
precision = 1.0f,
3536
maxError = 50.0f,
3637
) {
37-
point: Vector2f -> glfwSetCursorPos(windowPtr, point.x.toDouble(), point.y.toDouble())
38+
point -> glfwSetCursorPos(hwnd, point.x.toDouble(), point.y.toDouble())
3839
}
3940
}
4041

@@ -44,23 +45,17 @@ object CursorManager
4445
}
4546

4647
suspend fun rotateHeadAbsolute(yaw: Float, pitch: Float) {
47-
val player = MinecraftClient.getInstance().player!!
48+
val player = mc.player!!
4849

49-
val yawOffset = player.yaw.let {
50-
var yaw = it
51-
var offset = 0.0f
52-
while(yaw < 180.0f) { yaw += 360.0f; offset += 360.0f }
53-
while(yaw >= 180.0f) { yaw -= 360.0f; offset -= 360.0f }
54-
offset
55-
}
50+
val offset = floor((player.yaw + 180.0f) / 360.0f) * 360.0f
5651

5752
generate(
58-
start = Vector2f(player.yaw + yawOffset, player.pitch),
59-
end = Vector2f(yaw, pitch),
53+
start = Vector2f(player.yaw, player.pitch),
54+
end = Vector2f(yaw + offset, pitch),
6055
precision = 1.0f,
6156
maxError = 30.0f
6257
) {
63-
point: Vector2f -> player.rotate(point.x, point.y)
58+
point -> player.rotate(point.x, point.y)
6459
}
6560
}
6661

0 commit comments

Comments
 (0)