@@ -34,7 +34,7 @@ import com.lambda.interaction.request.RequestHandler
3434import com.lambda.interaction.request.breaking.BreakManager
3535import com.lambda.interaction.request.hotbar.HotbarManager
3636import com.lambda.interaction.request.hotbar.HotbarRequest
37- import com.lambda.interaction.request.rotation.RotationManager.onRotate
37+ import com.lambda.interaction.request.rotation.RotationRequest
3838import com.lambda.module.modules.client.TaskFlowModule
3939import com.lambda.util.BlockUtils.blockState
4040import com.lambda.util.BlockUtils.item
@@ -70,7 +70,10 @@ object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
7070 it.pendingInteractionsList.remove(it.context)
7171 }
7272
73- private var placeContexts = emptyList<PlaceContext >()
73+ private var rotation: RotationRequest ? = null
74+ private var validRotation = false
75+
76+ private var shouldCrouch = false
7477
7578 override val blockedPositions
7679 get() = pendingPlacements.map { it.context.expectedPos }
@@ -93,38 +96,16 @@ object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
9396
9497 init {
9598 listen<TickEvent .Pre >(priority = Int .MIN_VALUE ) {
96- currentRequest?.let { request ->
97- placeContexts
98- .forEach { ctx ->
99- val notSneaking = ! player.isSneaking
100- val hotbarRequest = request.hotbarConfig.request(HotbarRequest (ctx.hotbarIndex))
101- if ((ctx.sneak && notSneaking) || ! hotbarRequest.done || ! ctx.rotation.done)
102- return @listen
103-
104- val actionResult = placeBlock(ctx, request, Hand .MAIN_HAND )
105- if (! actionResult.isAccepted) {
106- warn(" Placement interaction failed with $actionResult " )
107- }
108- activeThisTick = true
109- }
110- placeContexts = emptyList()
111- }
112- }
113-
114- onRotate(priority = Int .MIN_VALUE ) {
11599 preEvent()
116100
117101 if (! updateRequest()) {
118102 postEvent()
119- return @onRotate
120- }
121-
122- if (BreakManager .activeThisTick()) {
123- postEvent()
124- return @onRotate
103+ return @listen
125104 }
126105
127106 currentRequest?.let request@ { request ->
107+ if (BreakManager .activeThisTick()) return @request
108+
128109 pendingPlacements.setMaxSize(request.buildConfig.placeSettings.maxPendingPlacements)
129110 pendingPlacements.setDecayTime(request.buildConfig.interactionTimeout * 50L )
130111
@@ -134,25 +115,53 @@ object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
134115 val takeCount = (placeConfig.placementsPerTick.coerceAtMost(maxPlacementsThisTick))
135116 val isSneaking = player.isSneaking
136117 val currentHotbarIndex = HotbarManager .serverSlot
137- placeContexts = request.placeContexts
118+ val placeContexts = request.placeContexts
138119 .filter { canPlace(it) }
139120 .sortedBy { isSneaking == it.sneak && currentHotbarIndex == it.hotbarIndex }
140121 .take(takeCount)
141122
142- request.placeContexts.firstOrNull()?.let { ctx ->
143- if (placeConfig.rotateForPlace || placeConfig.axisRotate)
144- request.rotationConfig.request(ctx.rotation)
123+ rotation = if (placeConfig.rotateForPlace || placeConfig.axisRotate) {
124+ placeContexts.firstOrNull()?.let { ctx ->
125+ if (ctx.rotation.target.angleDistance == 0.0 ) null
126+ else request.rotationConfig.request(ctx.rotation)
127+ }
128+ } else null
129+
130+ placeContexts.forEach { ctx ->
131+ val notSneaking = ! player.isSneaking
132+ val hotbarRequest = request.hotbarConfig.request(HotbarRequest (ctx.hotbarIndex))
133+ if (ctx.sneak && notSneaking) {
134+ shouldCrouch = true
135+ return @listen
136+ }
137+ rotation?.let { rotation ->
138+ if (rotation != = ctx.rotation || ! validRotation) return @listen
139+ }
140+ if (! hotbarRequest.done) return @listen
141+
142+ val actionResult = placeBlock(ctx, request, Hand .MAIN_HAND )
143+ if (! actionResult.isAccepted) {
144+ warn(" Placement interaction failed with $actionResult " )
145+ }
146+ activeThisTick = true
145147 }
146148 }
147149
148150 postEvent()
149151 }
150152
151- listen<MovementEvent .InputUpdate > {
152- if (placeContexts.firstOrNull()?.sneak == true ) it.input.sneaking = true
153+ listen<UpdateManagerEvent .Rotation .Post >(priority = Int .MIN_VALUE ) {
154+ validRotation = rotation?.done ? : true
155+ }
156+
157+ listen<MovementEvent .InputUpdate >(priority = Int .MIN_VALUE ) {
158+ if (shouldCrouch) {
159+ shouldCrouch = false
160+ it.input.sneaking = true
161+ }
153162 }
154163
155- listen<WorldEvent .BlockUpdate .Server > { event ->
164+ listen<WorldEvent .BlockUpdate .Server >(priority = Int . MIN_VALUE ) { event ->
156165 pendingPlacements
157166 .firstOrNull { it.context.expectedPos == event.pos }
158167 ?.let { info ->
0 commit comments