Skip to content

Commit ad9b456

Browse files
committed
fix rotations being reset causing incorrect placements
1 parent 2ec256d commit ad9b456

File tree

6 files changed

+18
-27
lines changed

6 files changed

+18
-27
lines changed

common/src/main/kotlin/com/lambda/config/groups/TickStage.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ enum class TickStage {
2121
TickStart,
2222
PostHotbar,
2323
PostInteract,
24-
PostMovement,
24+
PlayerTickPost
2525
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ object PlayerPacketManager {
134134
}
135135
}
136136

137+
// Update the server rotation in RotationManager
138+
with (RotationManager) {
139+
prevServerRotation = serverRotation
140+
serverRotation = new.rotation/*.fixSensitivity(prevServerRotation)*/
141+
activeRequest?.let { request ->
142+
request.matchesServerRot = request.done
143+
}
144+
}
145+
137146
PlayerPacketEvent.Post().post()
138147
}
139148

common/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ data class PlaceContext(
4545
override val targetState: TargetState,
4646
val sneak: Boolean,
4747
val insideBlock: Boolean,
48-
val previousDirWasInvalid: Boolean = false
48+
val currentDirIsInvalid: Boolean = false
4949
) : BuildContext {
5050
private val baseColor = Color(35, 188, 254, 25)
5151
private val sideColor = Color(35, 188, 254, 100)
@@ -79,9 +79,7 @@ data class PlaceContext(
7979
fun requestDependencies(request: PlaceRequest): Boolean {
8080
val hotbarRequest = request.hotbar.request(HotbarRequest(hotbarIndex, request.hotbar))
8181
val validRotation = if (request.build.placing.rotate) {
82-
//ToDo: add a rotation compare to the !previousDirWasInvalid check in case the player
83-
// was able to perform actions after updating the server rotation in the same tick
84-
request.rotation.request(rotation, false).done && !previousDirWasInvalid
82+
request.rotation.request(rotation, false).done && (!currentDirIsInvalid || rotation.matchesServerRot)
8583
} else true
8684
return hotbarRequest.done && validRotation
8785
}

common/src/main/kotlin/com/lambda/interaction/request/RequestHandler.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.lambda.interaction.request
2020
import com.lambda.config.groups.TickStage
2121
import com.lambda.context.SafeContext
2222
import com.lambda.event.Event
23-
import com.lambda.event.events.MovementEvent
2423
import com.lambda.event.events.TickEvent
2524
import com.lambda.event.listener.SafeListener.Companion.listen
2625
import com.lambda.threading.runSafe
@@ -61,7 +60,7 @@ abstract class RequestHandler<R : Request>(
6160
TickStage.TickStart -> openRequestsFor<TickEvent.Pre>(TickStage.TickStart)
6261
TickStage.PostHotbar -> { /*ToDo*/ }
6362
TickStage.PostInteract -> { /*ToDo*/ }
64-
TickStage.PostMovement -> openRequestsFor<MovementEvent.Player.Post>(TickStage.PostMovement)
63+
TickStage.PlayerTickPost -> openRequestsFor<TickEvent.Player.Post>(TickStage.PlayerTickPost)
6564
}
6665
}
6766

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import com.lambda.core.Loadable
2424
import com.lambda.event.Event
2525
import com.lambda.event.EventFlow.post
2626
import com.lambda.event.events.ConnectionEvent
27-
import com.lambda.event.events.PacketEvent
2827
import com.lambda.event.events.RotationEvent
2928
import com.lambda.event.events.TickEvent
3029
import com.lambda.event.events.UpdateManagerEvent
@@ -35,15 +34,13 @@ import com.lambda.interaction.request.RequestHandler
3534
import com.lambda.interaction.request.rotation.Rotation.Companion.slerp
3635
import com.lambda.interaction.request.rotation.visibilty.lookAt
3736
import com.lambda.module.modules.client.Baritone
38-
import com.lambda.threading.runGameScheduled
3937
import com.lambda.threading.runSafe
4038
import com.lambda.util.extension.partialTicks
4139
import com.lambda.util.extension.rotation
4240
import com.lambda.util.math.MathUtils.toRadian
4341
import com.lambda.util.math.Vec2d
4442
import com.lambda.util.math.lerp
4543
import net.minecraft.client.input.Input
46-
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
4744
import kotlin.math.cos
4845
import kotlin.math.round
4946
import kotlin.math.sign
@@ -54,12 +51,12 @@ object RotationManager : RequestHandler<RotationRequest>(
5451
TickStage.PostHotbar,
5552
TickStage.PostInteract,
5653
), Loadable {
57-
var activeRotation = Rotation.ZERO; private set
58-
var serverRotation = Rotation.ZERO; private set
59-
private var prevServerRotation = Rotation.ZERO
54+
var activeRotation = Rotation.ZERO
55+
var serverRotation = Rotation.ZERO
56+
var prevServerRotation = Rotation.ZERO
6057

58+
var activeRequest: RotationRequest? = null
6159
private var changedThisTick = false
62-
private var activeRequest: RotationRequest? = null
6360

6461
override fun load() = "Loaded Rotation Manager"
6562

@@ -79,15 +76,6 @@ object RotationManager : RequestHandler<RotationRequest>(
7976
changedThisTick = false
8077
}
8178

82-
listen<PacketEvent.Receive.Post> { event ->
83-
val packet = event.packet
84-
if (packet !is PlayerPositionLookS2CPacket) return@listen
85-
86-
runGameScheduled {
87-
reset(Rotation(packet.yaw, packet.pitch))
88-
}
89-
}
90-
9179
listenUnsafe<ConnectionEvent.Connect.Pre> {
9280
reset(Rotation.ZERO)
9381
}
@@ -111,10 +99,6 @@ object RotationManager : RequestHandler<RotationRequest>(
11199
updateActiveRotation()
112100
}
113101

114-
// Update the current rotation
115-
prevServerRotation = serverRotation
116-
serverRotation = activeRotation/*.fixSensitivity(prevServerRotation)*/
117-
118102
// Handle LOCK mode
119103
if (activeRequest?.mode == RotationMode.Lock) {
120104
player.yaw = serverRotation.yawF

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ data class RotationRequest(
3333
val speedMultiplier: Double = 1.0
3434
) : Request(prio, rot) {
3535
var age = 0
36+
var matchesServerRot = false
3637

3738
constructor(
3839
target: RotationTarget,

0 commit comments

Comments
 (0)