Skip to content

Commit b267a79

Browse files
committed
rotations fix!!!
1 parent c59b824 commit b267a79

File tree

13 files changed

+71
-63
lines changed

13 files changed

+71
-63
lines changed

common/src/main/java/com/lambda/mixin/baritone/MixinBaritonePlayerContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void syncRotationWithBaritone(CallbackInfoReturnable<Rotation> cir) {
4242

4343
RotationManager rm = RotationManager.INSTANCE;
4444
cir.setReturnValue(new Rotation(
45-
(float) rm.getCurrentRotation().getYaw(), (float) rm.getCurrentRotation().getPitch())
45+
(float) rm.getActiveRotation().getYaw(), (float) rm.getActiveRotation().getPitch())
4646
);
4747
}
4848
}

common/src/main/kotlin/com/lambda/interaction/PlayerPacketManager.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ import com.lambda.util.math.component3
3232
import com.lambda.util.player.MovementUtils.motionX
3333
import com.lambda.util.player.MovementUtils.motionZ
3434
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
35-
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.*
35+
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.Full
36+
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.LookAndOnGround
37+
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.OnGroundOnly
38+
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.PositionAndOnGround
3639
import net.minecraft.util.math.Vec3d
3740

3841
object PlayerPacketManager {
@@ -51,7 +54,7 @@ object PlayerPacketManager {
5154
runSafe {
5255
PlayerPacketEvent.Pre(
5356
player.pos,
54-
RotationManager.currentRotation,
57+
RotationManager.activeRotation,
5558
player.isOnGround,
5659
player.isSprinting,
5760
player.isSneaking

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ object BuildSimulator {
434434
return acc
435435
}
436436

437-
val currentRotation = RotationManager.currentRotation
437+
val currentRotation = RotationManager.activeRotation
438438
val currentCast = currentRotation.rayCast(interact.interactReach, eye)
439439

440440
val voxelShape = state.getOutlineShape(world, pos)

common/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,7 @@ object PlaceManager : RequestHandler<PlaceRequest>(
141141
placementsThisTick++
142142
iterator.remove()
143143
}
144-
if (potentialPlacements.isEmpty()) {
145-
activeRequest = null
146-
return
147-
}
148-
if (!request.rotation.rotate) return
149-
150-
// In case you cant rotate and place within the same tick
151-
potentialPlacements.getOrNull(maxPlacementsThisTick - 1)?.let { nextPredictedPlacement ->
152-
request.rotation.request(nextPredictedPlacement.rotation)
153-
}
144+
if (potentialPlacements.isEmpty()) activeRequest = null
154145
}
155146

156147
/**

common/src/main/kotlin/com/lambda/interaction/request/rotation/RotationManager.kt

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ import kotlin.math.sin
5252
object RotationManager : RequestHandler<RotationRequest>(
5353
TickStage.TickStart
5454
), Loadable {
55-
var currentRotation = Rotation.ZERO
56-
private var prevRotation = Rotation.ZERO
55+
var activeRotation = Rotation.ZERO; private set
56+
var serverRotation = Rotation.ZERO; private set
57+
private var prevServerRotation = Rotation.ZERO
5758

5859
private var changedThisTick = false
5960
private var activeRequest: RotationRequest? = null
@@ -94,6 +95,7 @@ object RotationManager : RequestHandler<RotationRequest>(
9495
activeRequest?.let { if (it.age <= 0) return }
9596
if (request.target.targetRotation.value != null) {
9697
activeRequest = request
98+
updateActiveRotation()
9799
changedThisTick = true
98100
}
99101
}
@@ -104,29 +106,17 @@ object RotationManager : RequestHandler<RotationRequest>(
104106

105107
if (!changedThisTick) { // rebuild the rotation if the same context gets used again
106108
activeRequest?.target?.targetRotation?.update()
109+
updateActiveRotation()
107110
}
108111

109-
// Calculate the target rotation
110-
val targetRotation = activeRequest?.let { request ->
111-
val rotationTo = if (request.keepTicks >= 0)
112-
request.target.targetRotation.value
113-
?: currentRotation // same context gets used again && the rotation is null this tick
114-
else player.rotation
115-
116-
val speedMultiplier = if (request.keepTicks < 0) 1.0 else request.speedMultiplier
117-
val turnSpeed = request.turnSpeed() * speedMultiplier
118-
119-
currentRotation.slerp(rotationTo, turnSpeed)
120-
} ?: player.rotation
121-
122112
// Update the current rotation
123-
prevRotation = currentRotation
124-
currentRotation = targetRotation/*.fixSensitivity(prevRotation)*/
113+
prevServerRotation = serverRotation
114+
serverRotation = activeRotation/*.fixSensitivity(prevServerRotation)*/
125115

126116
// Handle LOCK mode
127117
if (activeRequest?.mode == RotationMode.Lock) {
128-
player.yaw = currentRotation.yawF
129-
player.pitch = currentRotation.pitchF
118+
player.yaw = serverRotation.yawF
119+
player.pitch = serverRotation.pitchF
130120
}
131121

132122
// Tick and reset the context
@@ -137,15 +127,30 @@ object RotationManager : RequestHandler<RotationRequest>(
137127
}
138128
}
139129

130+
private fun SafeContext.updateActiveRotation() {
131+
activeRotation = activeRequest?.let { request ->
132+
val rotationTo = if (request.keepTicks >= 0)
133+
request.target.targetRotation.value
134+
?: activeRotation // same context gets used again && the rotation is null this tick
135+
else player.rotation
136+
137+
val speedMultiplier = if (request.keepTicks < 0) 1.0 else request.speedMultiplier
138+
val turnSpeed = request.turnSpeed() * speedMultiplier
139+
140+
serverRotation.slerp(rotationTo, turnSpeed)
141+
} ?: player.rotation
142+
}
143+
140144
private fun reset(rotation: Rotation) {
141-
prevRotation = rotation
142-
currentRotation = rotation
145+
prevServerRotation = rotation
146+
serverRotation = rotation
147+
activeRotation = rotation
143148
activeRequest = null
144149
}
145150

146151
private val smoothRotation
147152
get() =
148-
lerp(Lambda.mc.partialTicks, prevRotation, currentRotation)
153+
lerp(Lambda.mc.partialTicks, prevServerRotation, serverRotation)
149154

150155
@JvmStatic
151156
val lockRotation
@@ -165,32 +170,32 @@ object RotationManager : RequestHandler<RotationRequest>(
165170
@JvmStatic
166171
val handYaw
167172
get() =
168-
if (activeRequest?.mode == RotationMode.Lock) currentRotation.yaw.toFloat() else null
173+
if (activeRequest?.mode == RotationMode.Lock) serverRotation.yaw.toFloat() else null
169174

170175
@JvmStatic
171176
val handPitch
172177
get() =
173-
if (activeRequest?.mode == RotationMode.Lock) currentRotation.pitch.toFloat() else null
178+
if (activeRequest?.mode == RotationMode.Lock) serverRotation.pitch.toFloat() else null
174179

175180
@JvmStatic
176181
val movementYaw: Float?
177182
get() {
178183
if (activeRequest?.mode == RotationMode.Silent) return null
179-
return currentRotation.yaw.toFloat()
184+
return serverRotation.yaw.toFloat()
180185
}
181186

182187
@JvmStatic
183188
val movementPitch: Float?
184189
get() {
185190
if (activeRequest?.mode == RotationMode.Silent) return null
186-
return currentRotation.pitch.toFloat()
191+
return serverRotation.pitch.toFloat()
187192
}
188193

189194
@JvmStatic
190195
fun getRotationForVector(deltaTime: Double): Vec2d? {
191196
if (activeRequest?.mode == RotationMode.Silent) return null
192197

193-
val rot = lerp(deltaTime, prevRotation, currentRotation)
198+
val rot = lerp(deltaTime, prevServerRotation, serverRotation)
194199
return Vec2d(rot.yaw, rot.pitch)
195200
}
196201

@@ -234,7 +239,7 @@ object RotationManager : RequestHandler<RotationRequest>(
234239
if (signForward == 0f && signStrafe == 0f) return@runSafe
235240

236241
// Actual yaw used by the physics engine
237-
var actualYaw = currentRotation.yaw
242+
var actualYaw = serverRotation.yaw
238243

239244
if (activeRequest?.mode == RotationMode.Silent) {
240245
actualYaw = player.yaw.toDouble()
@@ -262,7 +267,7 @@ object RotationManager : RequestHandler<RotationRequest>(
262267
// Makes baritone movement safe
263268
// when yaw difference is too big to compensate it by modifying keyboard input
264269
val minYawDist = movementYawList
265-
.map { currentRotation.yaw + it } // all possible movement directions (including diagonals)
270+
.map { serverRotation.yaw + it } // all possible movement directions (including diagonals)
266271
.minOf { Rotation.angleDifference(it, baritoneYaw) }
267272

268273
if (minYawDist > 5.0) {

common/src/main/kotlin/com/lambda/interaction/request/rotation/visibilty/PointSelection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import com.lambda.util.math.distSq
2424
enum class PointSelection(val select: (MutableList<VisibilityChecker.CheckedHit>) -> VisibilityChecker.CheckedHit?) {
2525
ByRotation({ hits ->
2626
hits.minByOrNull {
27-
RotationManager.currentRotation dist it.targetRotation
27+
RotationManager.activeRotation dist it.targetRotation
2828
}
2929
}),
3030
Optimum( optimum@ { hits ->

common/src/main/kotlin/com/lambda/interaction/request/rotation/visibilty/RequestedHit.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ abstract class RequestedHit {
6060
*
6161
* @return True if the hit is valid, false otherwise.
6262
*/
63-
fun verifyRotation(rotation: Rotation = RotationManager.currentRotation) =
63+
fun verifyRotation(rotation: Rotation = RotationManager.activeRotation) =
6464
rotation.rayCast(reach)?.let { verifyHit(it) } ?: false
6565

6666
/**
@@ -69,7 +69,7 @@ abstract class RequestedHit {
6969
* @return [HitResult] if passed, null otherwise.
7070
*/
7171
fun hitIfValid() =
72-
RotationManager.currentRotation.rayCast(reach)?.let {
72+
RotationManager.activeRotation.rayCast(reach)?.let {
7373
if (!verifyHit(it)) null else it
7474
}
7575

common/src/main/kotlin/com/lambda/interaction/request/rotation/visibilty/RotationTarget.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ data class RotationTarget(
4343
}
4444

4545
val angleDistance get() = runSafe {
46-
targetRotation.value?.dist(RotationManager.currentRotation)
46+
targetRotation.value?.dist(RotationManager.activeRotation)
4747
} ?: 1000.0
4848

4949
/**

common/src/main/kotlin/com/lambda/interaction/request/rotation/visibilty/RotationTargets.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ annotation class RotationDsl
4747
@RotationDsl
4848
fun lookAt(angle: Rotation, maxAngleDistance: Double = 10.0) =
4949
RotationTarget(null, {
50-
RotationManager.currentRotation dist angle < maxAngleDistance
50+
RotationManager.activeRotation dist angle < maxAngleDistance
5151
}) { angle }
5252

5353
/**

common/src/main/kotlin/com/lambda/interaction/request/rotation/visibilty/VisibilityChecker.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import com.lambda.config.groups.InteractionConfig
2121
import com.lambda.context.SafeContext
2222
import com.lambda.interaction.construction.verify.ScanMode
2323
import com.lambda.interaction.construction.verify.SurfaceScan
24-
import com.lambda.interaction.request.rotation.*
24+
import com.lambda.interaction.request.rotation.Rotation
2525
import com.lambda.interaction.request.rotation.Rotation.Companion.rotationTo
26+
import com.lambda.interaction.request.rotation.RotationManager
2627
import com.lambda.module.modules.client.TaskFlowModule
2728
import com.lambda.util.extension.component6
2829
import com.lambda.util.math.distSq
@@ -63,7 +64,7 @@ object VisibilityChecker {
6364
interaction: InteractionConfig,
6465
verify: CheckedHit.() -> Boolean
6566
): CheckedHit? {
66-
val currentRotation = RotationManager.currentRotation
67+
val currentRotation = RotationManager.activeRotation
6768

6869
if (boxes.any { it.contains(eye) }) {
6970
currentRotation.rayCast(reach, eye)?.let { hit ->

0 commit comments

Comments
 (0)