Skip to content

Commit bf39de5

Browse files
committed
activity checks
1 parent 216b031 commit bf39de5

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package com.lambda.interaction.request
1919

2020
import com.lambda.event.Event
21+
import com.lambda.event.events.TickEvent
22+
import com.lambda.event.listener.SafeListener.Companion.listen
2123
import java.util.concurrent.ConcurrentHashMap
2224

2325
/**
@@ -29,11 +31,24 @@ abstract class RequestHandler<R : Request> {
2931

3032
private val requestMap = ConcurrentHashMap<RequestConfig<R>, R>()
3133

34+
/**
35+
* Represents if the handler performed any external actions within this tick
36+
*/
37+
protected var activeThisTick = false
38+
3239
/**
3340
* The currently active request.
3441
*/
3542
var currentRequest: R? = null; protected set
3643

44+
init {
45+
listen<TickEvent.Post>(Int.MIN_VALUE) {
46+
activeThisTick = false
47+
}
48+
}
49+
50+
fun activeThisTick() = activeThisTick
51+
3752
/**
3853
* Registers a new request with the given configuration.
3954
*

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.lambda.interaction.request.breaking.BreakConfig.BreakConfirmationMode
3131
import com.lambda.interaction.request.breaking.BreakConfig.BreakMode
3232
import com.lambda.interaction.request.hotbar.HotbarConfig
3333
import com.lambda.interaction.request.hotbar.HotbarRequest
34+
import com.lambda.interaction.request.placing.PlaceManager
3435
import com.lambda.interaction.request.rotation.RotationConfig
3536
import com.lambda.interaction.request.rotation.RotationManager.onRotate
3637
import com.lambda.module.modules.client.TaskFlowModule
@@ -80,6 +81,12 @@ object BreakManager : RequestHandler<BreakRequest>() {
8081
return@listen
8182
}
8283

84+
if (PlaceManager.activeThisTick()) {
85+
updateRequest(true) { true }
86+
postEvent()
87+
return@listen
88+
}
89+
8390
var swapped = false
8491

8592
//ToDo: improve instamine / non instamine integration
@@ -106,25 +113,33 @@ object BreakManager : RequestHandler<BreakRequest>() {
106113
request.hotbarConfig.request(HotbarRequest(info.context.hotbarIndex))
107114
swapped = true
108115
}
109-
updateBlockBreakingProgress(info, player.mainHandStack)
110-
instaBreaks++
116+
if (updateBlockBreakingProgress(info, player.mainHandStack)) {
117+
instaBreaks++
118+
activeThisTick = true
119+
}
111120
}
112121
}
113122
}
114123
}
115124
}
116125

117-
breakingInfos.firstOrNull()?.let { info ->
118-
if ((!swapped && !info.hotbarConfig.request(HotbarRequest(info.context.hotbarIndex)).done)
119-
|| (info.breakConfig.rotateForBreak && !info.context.rotation.done)) {
120-
postEvent()
121-
return@listen
126+
breakingInfos
127+
.filterNotNull()
128+
.firstOrNull()?.let { info ->
129+
activeThisTick = true
130+
if ((!swapped && !info.hotbarConfig.request(HotbarRequest(info.context.hotbarIndex)).done)
131+
|| (info.breakConfig.rotateForBreak && !info.context.rotation.done)) {
132+
postEvent()
133+
return@listen
134+
}
122135
}
123-
}
124136

125-
breakingInfos.reversed().filterNotNull().forEach { info ->
126-
updateBlockBreakingProgress(info, player.mainHandStack)
127-
}
137+
breakingInfos
138+
.filterNotNull()
139+
.reversed()
140+
.forEach { info ->
141+
updateBlockBreakingProgress(info, player.mainHandStack)
142+
}
128143

129144
postEvent()
130145
}

common/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ object HotbarManager : RequestHandler<HotbarRequest>(), Loadable {
4848

4949
listen<TickEvent.Pre> {
5050
preEvent()
51-
updateRequest()
52-
interaction.syncSelectedSlot()
51+
if (updateRequest()) interaction.syncSelectedSlot()
52+
if (currentRequest != null) activeThisTick = true
5353
postEvent()
5454
}
5555

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.lambda.event.listener.SafeListener.Companion.listen
2828
import com.lambda.interaction.construction.context.PlaceContext
2929
import com.lambda.interaction.construction.verify.TargetState
3030
import com.lambda.interaction.request.RequestHandler
31+
import com.lambda.interaction.request.breaking.BreakManager
3132
import com.lambda.interaction.request.hotbar.HotbarRequest
3233
import com.lambda.interaction.request.rotation.RotationManager.onRotate
3334
import com.lambda.module.modules.client.TaskFlowModule
@@ -65,10 +66,17 @@ object PlaceManager : RequestHandler<PlaceRequest>() {
6566
return@listen
6667
}
6768

69+
if (BreakManager.activeThisTick()) {
70+
postEvent()
71+
return@listen
72+
}
73+
6874
currentRequest?.let request@ { request ->
6975
if (pendingInteractions.size >= request.buildConfig.placeSettings.maxPendingPlacements)
7076
return@request
7177

78+
activeThisTick = true
79+
7280
if (request.placeContext.sneak && !player.isSneaking
7381
|| (request.buildConfig.placeSettings.rotateForPlace && !request.placeContext.rotation.done)
7482
|| (!request.hotbarConfig.request(HotbarRequest(request.placeContext.hotbarIndex)).done)
@@ -79,7 +87,7 @@ object PlaceManager : RequestHandler<PlaceRequest>() {
7987
pendingInteractions.setMaxSize(request.buildConfig.maxPendingInteractions)
8088
pendingInteractions.setDecayTime(request.buildConfig.interactionTimeout * 50L)
8189
placeBlock(request, Hand.MAIN_HAND)
82-
}
90+
}
8391

8492
postEvent()
8593
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ object RotationManager : RequestHandler<RotationRequest>(), Loadable {
7777
entry.value.target.targetRotation.value != null
7878
}
7979

80+
if (currentRequest != null) activeThisTick = true
81+
8082
if (!changed) { // rebuild the rotation if the same context gets used again
8183
currentRequest?.target?.targetRotation?.update()
8284
}

0 commit comments

Comments
 (0)