Skip to content

Commit e214bae

Browse files
committed
split back to update on rotate and perform on tick
1 parent bea07d3 commit e214bae

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

common/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package com.lambda.interaction.request.breaking
2020
import com.lambda.config.groups.BuildConfig
2121
import com.lambda.context.SafeContext
2222
import com.lambda.event.EventFlow.post
23+
import com.lambda.event.events.TickEvent
2324
import com.lambda.event.events.UpdateManagerEvent
2425
import com.lambda.event.events.WorldEvent
2526
import com.lambda.event.listener.SafeListener.Companion.listen
@@ -75,8 +76,21 @@ object BreakManager : RequestHandler<BreakRequest>() {
7576
private var blockBreakingCooldown = 0
7677

7778
private var rotation: RotationRequest? = null
79+
private var validRotation = false
7880

7981
init {
82+
listen<TickEvent.Pre> {
83+
if (!validRotation) return@listen
84+
85+
breakingInfos
86+
.filterNotNull()
87+
.reversed()
88+
.forEach { info ->
89+
if (info.hotbarConfig.request(HotbarRequest(info.context.hotbarIndex)).done.not()) return@forEach
90+
updateBlockBreakingProgress(info, player.mainHandStack)
91+
}
92+
}
93+
8094
onRotate(priority = Int.MIN_VALUE) {
8195
preEvent()
8296

@@ -134,22 +148,11 @@ object BreakManager : RequestHandler<BreakRequest>() {
134148
}
135149

136150
onRotatePost {
137-
val notNullInfos = breakingInfos.filterNotNull()
138-
139-
notNullInfos
151+
breakingInfos
152+
.filterNotNull()
140153
.firstOrNull()?.let { info ->
141154
activeThisTick = true
142-
if (info.breakConfig.rotateForBreak && rotation?.done != true) {
143-
postEvent()
144-
return@onRotatePost
145-
}
146-
}
147-
148-
notNullInfos
149-
.reversed()
150-
.forEach { info ->
151-
if (info.hotbarConfig.request(HotbarRequest(info.context.hotbarIndex)).done.not()) return@forEach
152-
updateBlockBreakingProgress(info, player.mainHandStack)
155+
validRotation = info.breakConfig.rotateForBreak && rotation?.done == true
153156
}
154157

155158
postEvent()

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

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.lambda.config.groups.BuildConfig
2121
import com.lambda.context.SafeContext
2222
import com.lambda.event.EventFlow.post
2323
import com.lambda.event.events.MovementEvent
24+
import com.lambda.event.events.TickEvent
2425
import com.lambda.event.events.UpdateManagerEvent
2526
import com.lambda.event.events.WorldEvent
2627
import com.lambda.event.listener.SafeListener.Companion.listen
@@ -59,11 +60,24 @@ object PlaceManager : RequestHandler<PlaceRequest>() {
5960
) { info("${it::class.simpleName} at ${it.context.expectedPos.toShortString()} timed out") }
6061

6162
private var rotation: RotationRequest? = null
63+
private var validRotation = false
6264

6365
val blockedPositions
6466
get() = pendingInteractions.map { it.context.expectedPos }
6567

6668
init {
69+
listen<TickEvent.Pre> {
70+
currentRequest?.let { request ->
71+
val notSneaking = !player.isSneaking
72+
val hotbarRequest = request.hotbarConfig.request(HotbarRequest(request.placeContext.hotbarIndex))
73+
val invalidRotation = request.buildConfig.placeSettings.rotateForPlace && !validRotation
74+
if ((request.placeContext.sneak && notSneaking) || !hotbarRequest.done || invalidRotation)
75+
return@listen
76+
77+
placeBlock(request, Hand.MAIN_HAND)
78+
}
79+
}
80+
6781
onRotate(priority = Int.MIN_VALUE) {
6882
preEvent()
6983

@@ -95,18 +109,8 @@ object PlaceManager : RequestHandler<PlaceRequest>() {
95109
}
96110

97111
onRotatePost {
98-
currentRequest?.let { request ->
99-
val notSneaking = !player.isSneaking
100-
val hotbarRequest = request.hotbarConfig.request(HotbarRequest(request.placeContext.hotbarIndex))
101-
val invalidRotation = request.buildConfig.placeSettings.rotateForPlace && rotation?.done != true
102-
if ((request.placeContext.sneak && notSneaking) || !hotbarRequest.done || invalidRotation) {
103-
postEvent()
104-
return@onRotatePost
105-
}
106-
107-
placeBlock(request, Hand.MAIN_HAND)
108-
postEvent()
109-
}
112+
validRotation = rotation?.done == true
113+
postEvent()
110114
}
111115

112116
listen<MovementEvent.InputUpdate> {

0 commit comments

Comments
 (0)