Skip to content

Commit 1ce0eb9

Browse files
committed
moved request updates in break manager to on tick to remove needless tick delay if rotations are already complete or disabled, and improved general request handling logic
1 parent 7ba7b72 commit 1ce0eb9

File tree

4 files changed

+46
-58
lines changed

4 files changed

+46
-58
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BreakSettings(
4040
override val ignoredBlocks by c.setting("Ignored Blocks", allSigns, "Blocks that wont be broken") { vis() }
4141
override val breakConfirmation by c.setting("Break Confirmation", BreakConfirmationMode.BreakThenAwait, "The style of confirmation used when breaking") { vis() }
4242
override val maxPendingBreaks by c.setting("Max Pending Breaks", 5, 1..30, 1, "The maximum amount of pending breaks") { vis() }
43-
override val breaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() }
43+
override val instantBreaksPerTick by c.setting("Instant Breaks Per Tick", 5, 1..30, 1, "Maximum instant block breaks per tick") { vis() }
4444
override val breakWeakBlocks by c.setting("Break Weak Blocks", false, "Break blocks that dont have structural integrity (e.g: grass)") { vis() }
4545
override val forceSilkTouch by c.setting("Force Silk Touch", false, "Force silk touch when breaking blocks") { vis() }
4646
override val forceFortunePickaxe by c.setting("Force Fortune Pickaxe", false, "Force fortune pickaxe when breaking blocks") { vis() }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ abstract class BreakConfig(
3737
abstract val rotateForBreak: Boolean
3838
abstract val breakConfirmation: BreakConfirmationMode
3939
abstract val maxPendingBreaks: Int
40-
abstract val breaksPerTick: Int
40+
abstract val instantBreaksPerTick: Int
4141
abstract val breakWeakBlocks: Boolean
4242
abstract val forceSilkTouch: Boolean
4343
abstract val forceFortunePickaxe: Boolean

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

Lines changed: 42 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ import com.lambda.interaction.request.breaking.BreakConfig.BreakConfirmationMode
3737
import com.lambda.interaction.request.breaking.BreakConfig.BreakMode
3838
import com.lambda.interaction.request.hotbar.HotbarManager
3939
import com.lambda.interaction.request.hotbar.HotbarRequest
40-
import com.lambda.interaction.request.placing.PlaceManager
41-
import com.lambda.interaction.request.rotation.RotationManager.onRotate
42-
import com.lambda.interaction.request.rotation.RotationManager.onRotatePost
4340
import com.lambda.interaction.request.rotation.RotationRequest
4441
import com.lambda.module.modules.client.TaskFlowModule
4542
import com.lambda.util.BlockUtils.blockState
@@ -87,7 +84,8 @@ object BreakManager : RequestHandler<BreakRequest>(), PositionBlocking {
8784
get() = breakingInfos.mapNotNull { it?.context?.expectedPos } + pendingBreaks.map { it.context.expectedPos }
8885

8986
private var rotation: RotationRequest? = null
90-
private var validRotation = false
87+
private val validRotation
88+
get() = rotation?.done ?: true
9189

9290
private var blockBreakingCooldown = 0
9391

@@ -111,62 +109,43 @@ object BreakManager : RequestHandler<BreakRequest>(), PositionBlocking {
111109

112110
init {
113111
listen<TickEvent.Pre>(priority = Int.MIN_VALUE + 1) {
114-
if (isOnBreakCooldown()) {
115-
blockBreakingCooldown--
116-
return@listen
117-
}
118-
if (PlaceManager.activeThisTick()) return@listen
119-
120-
currentRequest?.let request@ { request ->
121-
if (instantBreaks.isEmpty()) return@request
122-
123-
instantBreaks
124-
.sortedBy { HotbarManager.serverSlot == it.hotbarIndex }
125-
.forEach { ctx ->
126-
val breakInfo = handleRequestContext(ctx, request) ?: return@request
127-
if (!breakInfo.requestHotbarSwap()) return@forEach
128-
updateBlockBreakingProgress(breakInfo)
129-
activeThisTick = true
130-
}
131-
instantBreaks = emptyList()
132-
}
133-
134-
if (!validRotation) return@listen
135-
136-
// Reversed so that the breaking order feels natural to the user as the primary break has to
137-
// be started after the secondary
138-
breakingInfos
139-
.filterNotNull()
140-
.reversed()
141-
.forEach { info ->
142-
if (!info.requestHotbarSwap()) return@forEach
143-
updateBlockBreakingProgress(info)
144-
activeThisTick = true
145-
}
146-
}
147-
148-
onRotate(priority = Int.MIN_VALUE) {
149112
preEvent()
150113

151-
if (!updateRequest()) {
152-
requestRotate()
153-
return@onRotate
154-
}
114+
if (updateRequest()) currentRequest?.let request@ { request ->
115+
if (isOnBreakCooldown()) {
116+
blockBreakingCooldown--
117+
return@request
118+
}
155119

156-
currentRequest?.let request@ { request ->
157120
val breakConfig = request.buildConfig.breakSettings
158-
val takeCount = breakConfig.maxPendingBreaks - (breakingInfos.count { it != null } + pendingBreaks.size)
159-
if (takeCount <= 0) return@request
121+
val maxBreaksThisTick = breakConfig.maxPendingBreaks - (breakingInfos.count { it != null } + pendingBreaks.size)
122+
if (maxBreaksThisTick <= 0) return@request
123+
160124
val validContexts = request.contexts
161125
.filter { ctx -> canAccept(ctx) }
162126
.sortedBy { it.instantBreak }
163-
.take(takeCount)
127+
.take(maxBreaksThisTick)
164128

165129
instantBreaks = validContexts
166-
.take(breakConfig.breaksPerTick)
130+
.take(breakConfig.instantBreaksPerTick)
167131
.filter { it.instantBreak }
132+
.sortedBy { it.hotbarIndex == HotbarManager.serverSlot }
168133

169-
if (instantBreaks.isNotEmpty()) return@request
134+
if (instantBreaks.isNotEmpty()) {
135+
instantBreaks.forEach { ctx ->
136+
if (ctx.hotbarIndex != HotbarManager.serverSlot) {
137+
if (!request.hotbarConfig.request(HotbarRequest(ctx.hotbarIndex)).done) return@request
138+
}
139+
val breakInfo = handleRequestContext(ctx, request) ?: return@request
140+
updateBlockBreakingProgress(breakInfo)
141+
activeThisTick = true
142+
}
143+
if (instantBreaks.size == breakConfig.instantBreaksPerTick) {
144+
instantBreaks = emptyList()
145+
return@request
146+
}
147+
instantBreaks = emptyList()
148+
}
170149

171150
validContexts
172151
.filter { it.instantBreak.not() }
@@ -176,11 +155,19 @@ object BreakManager : RequestHandler<BreakRequest>(), PositionBlocking {
176155
}
177156

178157
requestRotate()
179-
}
158+
if (!validRotation) return@listen
180159

181-
onRotatePost(priority = Int.MIN_VALUE) {
182-
validRotation = rotation?.done ?: true
183-
postEvent()
160+
// ToDo: dynamically update hotbarIndex as contexts are persistent and don't get updated by new requests each tick
161+
// Reversed so that the breaking order feels natural to the user as the primary break has to
162+
// be started after the secondary
163+
breakingInfos
164+
.filterNotNull()
165+
.reversed()
166+
.forEach { info ->
167+
if (!info.requestHotbarSwap()) return@forEach
168+
updateBlockBreakingProgress(info)
169+
activeThisTick = true
170+
}
184171
}
185172

186173
listen<WorldEvent.BlockUpdate.Server> { event ->
@@ -282,7 +269,8 @@ object BreakManager : RequestHandler<BreakRequest>(), PositionBlocking {
282269
primaryBreakingInfo?.let { primaryInfo ->
283270
if (!primaryInfo.breakConfig.doubleBreak
284271
|| primaryInfo.startedWithSecondary
285-
|| secondaryBreakingInfo != null) {
272+
|| secondaryBreakingInfo != null
273+
|| requestCtx.hotbarIndex != primaryInfo.context.hotbarIndex) {
286274
return null
287275
}
288276

common/src/main/kotlin/com/lambda/task/tasks/BuildTask.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ class BuildTask @Ta5kBuilder constructor(
142142
val breakResults = resultsNotBlocked
143143
.filterIsInstance<BreakResult.Break>()
144144

145-
if (build.breakSettings.breaksPerTick > 1) {
145+
if (build.breakSettings.instantBreaksPerTick > 1) {
146146
val takeCount = build.breakSettings
147-
.breaksPerTick
147+
.instantBreaksPerTick
148148
.coerceAtMost(emptyPendingInteractionSlots)
149149
val instantBreakResults = breakResults
150150
.filter { it.context.instantBreak }

0 commit comments

Comments
 (0)