Skip to content

Commit dec89a2

Browse files
committed
fix baritone movement again lol and general cleanup
1 parent 9565284 commit dec89a2

File tree

7 files changed

+26
-36
lines changed

7 files changed

+26
-36
lines changed

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/BreakSim.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class BreakSim private constructor(simInfo: ISimInfo)
129129
val validHits = scanShape(pov, shape, pos, Direction.entries.toSet(), preProcessing) ?: return
130130

131131
val bestHit = buildConfig.pointSelection.select(validHits) ?: return
132-
val target = lookAt(bestHit.targetRotation, 0.001)
132+
val target = lookAt(bestHit.targetRotation)
133133
val rotationRequest = RotationRequest(target, this)
134134

135135
val breakContext = BreakContext(

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/PlaceSim.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class PlaceSim private constructor(simInfo: ISimInfo)
180180

181181
val rotationRequest = if (placeConfig.axisRotate && (targetState as? TargetState.State)?.blockState?.contains(Properties.ROTATION) != true)
182182
lookInDirection(PlaceDirection.fromRotation(rotatePlaceTest.rotation))
183-
else lookAt(rotatePlaceTest.rotation, 0.001)
183+
else lookAt(rotatePlaceTest.rotation)
184184

185185
val swapStack = getSwapStack() ?: return
186186
if (!swapStack.item.isEnabled(world.enabledFeatures)) {

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/PostProcessingSim.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class PostProcessingSim private constructor(simInfo: ISimInfo)
151151
) {
152152
buildConfig.pointSelection.select(validHits)?.let { checkedHit ->
153153
val checkedResult = checkedHit.hit.blockResult ?: return
154-
val rotationTarget = lookAt(checkedHit.targetRotation, 0.001)
154+
val rotationTarget = lookAt(checkedHit.targetRotation)
155155
val context = InteractContext(
156156
checkedResult,
157157
RotationRequest(rotationTarget, this),

src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ object RotationManager : RequestHandler<RotationRequest>(
6969
var activeRotation = Rotation.ZERO
7070
var serverRotation = Rotation.ZERO
7171
@JvmStatic var prevServerRotation = Rotation.ZERO
72-
var baritoneRequest: RotationRequest? = null
72+
private var usingBaritoneRotation = false
7373

7474
var activeRequest: RotationRequest? = null
7575
private var changedThisTick = false
@@ -89,6 +89,7 @@ object RotationManager : RequestHandler<RotationRequest>(
8989
}
9090

9191
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
92+
usingBaritoneRotation = false
9293
activeRequest?.let { request ->
9394
request.age++
9495
}
@@ -177,7 +178,8 @@ object RotationManager : RequestHandler<RotationRequest>(
177178
@JvmStatic
178179
fun handleBaritoneRotation(yaw: Float) {
179180
runSafe {
180-
baritoneRequest = lookAt(Rotation(yaw, player.pitch)).requestBy(BaritoneManager)
181+
activeRequest = lookAt(Rotation(yaw, player.pitch)).requestBy(BaritoneManager)
182+
usingBaritoneRotation = true
181183
}
182184
}
183185

@@ -188,7 +190,7 @@ object RotationManager : RequestHandler<RotationRequest>(
188190
*/
189191
@JvmStatic
190192
fun redirectStrafeInputs(input: Input) = runSafe {
191-
if (activeRequest == baritoneRequest) return@runSafe
193+
if (usingBaritoneRotation) return@runSafe
192194

193195
val movementYaw = movementYaw ?: return@runSafe
194196
val playerYaw = player.yaw
@@ -272,7 +274,7 @@ object RotationManager : RequestHandler<RotationRequest>(
272274
prevServerRotation = serverRotation
273275
serverRotation = activeRotation
274276

275-
if (activeRequest?.rotationMode == RotationMode.Lock) {
277+
if (activeRequest?.rotationConfig?.rotationMode == RotationMode.Lock) {
276278
mc.player?.yaw = serverRotation.yawF
277279
mc.player?.pitch = serverRotation.pitchF
278280
}
@@ -285,19 +287,15 @@ object RotationManager : RequestHandler<RotationRequest>(
285287
private fun SafeContext.updateActiveRotation() {
286288
activeRotation = activeRequest?.let { active ->
287289
val rotationTo = if (active.keepTicks >= 0)
288-
active.target.targetRotation.value
289-
?: activeRotation // the same context gets used again && the rotation is null this tick
290+
active.target.targetRotation.value ?: activeRotation // the same context gets used again && the rotation is null this tick
290291
else player.rotation
291292

292-
val speedMultiplier = if (active.keepTicks < 0) 1.0 else active.speedMultiplier
293-
val turnSpeed = active.turnSpeed * speedMultiplier
294-
295293
if (active.keepTicks-- <= 0) {
296294
active.decayTicks--
297295
}
298296

299297
// Important: do NOT wrap the result yaw; keep it continuous to match vanilla packets
300-
serverRotation.slerp(rotationTo, turnSpeed)
298+
serverRotation.slerp(rotationTo, active.rotationConfig.turnSpeed)
301299
} ?: player.rotation
302300

303301
logger.debug("Active rotation set to $activeRotation", activeRequest)
@@ -313,45 +311,43 @@ object RotationManager : RequestHandler<RotationRequest>(
313311

314312
@JvmStatic
315313
val lockRotation
316-
get() = activeRequest?.let {
317-
if (it.rotationMode == RotationMode.Lock && it.keepTicks > 0 && it.decayTicks > 0)
318-
return@let activeRotation
319-
else null
314+
get() = activeRequest?.let { active ->
315+
activeRotation.takeIf { active.rotationConfig.rotationMode == RotationMode.Lock && active.keepTicks > 0 && active.decayTicks > 0 }
320316
}
321317

322318
@JvmStatic
323319
val headYaw
324-
get() = if (activeRequest == null) null else activeRotation.yawF
320+
get() = activeRotation.yawF.takeIf { activeRequest != null }
325321

326322
@JvmStatic
327323
val headPitch
328-
get() = if (activeRequest == null) null else activeRotation.pitchF
324+
get() = activeRotation.pitchF.takeIf { activeRequest != null }
329325

330326
@JvmStatic
331327
val handYaw
332-
get() = if (activeRequest?.rotationMode == RotationMode.Lock) activeRotation.yawF else null
328+
get() = activeRotation.yawF.takeIf { activeRequest?.rotationConfig?.rotationMode == RotationMode.Lock }
333329

334330
@JvmStatic
335331
val handPitch
336-
get() = if (activeRequest?.rotationMode == RotationMode.Lock) activeRotation.pitchF else null
332+
get() = activeRotation.pitchF.takeIf { activeRequest?.rotationConfig?.rotationMode == RotationMode.Lock }
337333

338334
@JvmStatic
339335
val movementYaw: Float?
340336
get() {
341-
if (activeRequest == null || activeRequest?.rotationMode == RotationMode.Silent) return null
342-
return activeRotation.yaw.toFloat()
337+
return if (activeRequest == null || activeRequest?.rotationConfig?.rotationMode == RotationMode.Silent) null
338+
else activeRotation.yaw.toFloat()
343339
}
344340

345341
@JvmStatic
346342
val movementPitch: Float?
347343
get() {
348-
if (activeRequest == null || activeRequest?.rotationMode == RotationMode.Silent) return null
349-
return activeRotation.pitch.toFloat()
344+
return if (activeRequest == null || activeRequest?.rotationConfig?.rotationMode == RotationMode.Silent) null
345+
else activeRotation.pitch.toFloat()
350346
}
351347

352348
@JvmStatic
353349
fun getRotationForVector(deltaTime: Double): Vec2d? {
354-
if (activeRequest == null || activeRequest?.rotationMode == RotationMode.Silent) return null
350+
if (activeRequest == null || activeRequest?.rotationConfig?.rotationMode == RotationMode.Silent) return null
355351

356352
val rot = lerp(deltaTime, serverRotation, activeRotation)
357353
return Vec2d(rot.yaw, rot.pitch)

src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,26 @@ import com.lambda.threading.runSafe
2727
data class RotationRequest(
2828
val target: RotationTarget,
2929
private val automated: Automated,
30-
val rotationMode: RotationMode = automated.rotationConfig.rotationMode,
31-
val turnSpeed: Double = automated.rotationConfig.turnSpeed,
3230
var keepTicks: Int = automated.rotationConfig.keepTicks,
3331
var decayTicks: Int = automated.rotationConfig.decayTicks,
34-
val speedMultiplier: Double = 1.0
3532
) : Request(), LogContext, Automated by automated {
3633
override val requestId = ++requestCount
3734

3835
var age = 0
3936
override val nowOrNothing = false
4037

4138
override val done: Boolean get() =
42-
rotationMode == RotationMode.None || runSafe { target.verify() } == true
39+
rotationConfig.rotationMode == RotationMode.None || runSafe { target.verify() } == true
4340

4441
override fun submit(queueIfClosed: Boolean): RotationRequest =
4542
RotationManager.request(this, queueIfClosed)
4643

4744
override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = {
4845
group("Rotation Request") {
4946
value("Request ID", requestId)
50-
value("Rotation Mode", rotationMode)
51-
value("Turn Speed", turnSpeed)
47+
value("Age", age)
5248
value("Keep Ticks", keepTicks)
5349
value("Decay Ticks", decayTicks)
54-
value("Speed Multiplier", speedMultiplier)
55-
value("Age", age)
5650
}
5751
}
5852

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ annotation class RotationDsl
4646
* @return A [RotationTarget] instance.
4747
*/
4848
@RotationDsl
49-
fun lookAt(angle: Rotation, maxAngleDistance: Double = 10.0) =
49+
fun lookAt(angle: Rotation, maxAngleDistance: Double = 0.001) =
5050
RotationTarget(null, {
5151
RotationManager.activeRotation dist angle < maxAngleDistance
5252
}) { angle }

src/main/kotlin/com/lambda/module/modules/player/RotationLock.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ object RotationLock : Module(
6666
RotationMode.None -> player.pitch.toDouble()
6767
}
6868

69-
RotationRequest(lookAt(Rotation(yaw, pitch), 0.001), this@RotationLock).submit()
69+
RotationRequest(lookAt(Rotation(yaw, pitch)), this@RotationLock).submit()
7070
}
7171
}
7272

0 commit comments

Comments
 (0)