Skip to content

Commit fe55de4

Browse files
committed
hotbar swapping delegated to the break manager
1 parent f8c40e0 commit fe55de4

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.lambda.interaction.construction.verify.TargetState
2727
import com.lambda.interaction.request.RequestHandler
2828
import com.lambda.interaction.request.breaking.BreakConfig.BreakConfirmationMode
2929
import com.lambda.interaction.request.breaking.BreakConfig.BreakMode
30+
import com.lambda.interaction.request.hotbar.HotbarRequest
3031
import com.lambda.interaction.request.rotation.RotationConfig
3132
import com.lambda.interaction.request.rotation.RotationManager.onRotate
3233
import com.lambda.module.modules.client.TaskFlowModule
@@ -69,24 +70,23 @@ object BreakManager : RequestHandler<BreakRequest>() {
6970
return@listen
7071
}
7172

72-
if (updateRequest(false) { true }) {
73+
var swapped = false
74+
75+
if (updateRequest(true) { true }) {
7376
currentRequest?.let request@ { request ->
7477
var instaBreaks = 0
7578
request.contexts
7679
.sortedBy { it.instantBreak }
7780
.forEach { requestCtx ->
78-
if (!canAccept(requestCtx)) {
79-
return@forEach
80-
}
81-
val breakType = handleRequestContext(
82-
requestCtx,
83-
request.onBreak,
84-
request.buildConfig,
85-
request.rotationConfig
86-
)
81+
if (!canAccept(requestCtx)) return@forEach
82+
val breakType = handleRequestContext(requestCtx, request.onBreak, request.buildConfig, request.rotationConfig)
8783
if (breakType == BreakType.Null) return@request
8884
if (requestCtx.instantBreak && instaBreaks < request.buildConfig.breakSettings.breaksPerTick) {
8985
breakingInfos.getOrNull(breakType.index)?.let { info ->
86+
if (!swapped) {
87+
request.hotbarConfig.request(HotbarRequest(info.context.hotbarIndex))
88+
swapped = true
89+
}
9090
updateBlockBreakingProgress(info, player.mainHandStack)
9191
instaBreaks++
9292
}
@@ -95,6 +95,13 @@ object BreakManager : RequestHandler<BreakRequest>() {
9595
}
9696
}
9797

98+
currentRequest?.let { request ->
99+
breakingInfos.firstOrNull()?.let { info ->
100+
if (!swapped && !request.hotbarConfig.request(HotbarRequest(info.context.hotbarIndex)).done)
101+
return@listen
102+
}
103+
}
104+
98105
breakingInfos.reversed().filterNotNull().forEach { info ->
99106
if (info.breakConfig.rotateForBreak && !info.context.rotation.done) return@listen
100107
updateBlockBreakingProgress(info, player.mainHandStack)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ import com.lambda.config.groups.BuildConfig
2121
import com.lambda.interaction.construction.context.BreakContext
2222
import com.lambda.interaction.request.Priority
2323
import com.lambda.interaction.request.Request
24+
import com.lambda.interaction.request.hotbar.HotbarConfig
2425
import com.lambda.interaction.request.rotation.RotationConfig
2526

2627
data class BreakRequest(
2728
val contexts: List<BreakContext>,
2829
val buildConfig: BuildConfig,
2930
val rotationConfig: RotationConfig,
31+
val hotbarConfig: HotbarConfig,
3032
val prio: Priority = 0,
3133
val onBreak: () -> Unit
3234
) : Request(prio) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ class BuildTask @Ta5kBuilder constructor(
166166
.sorted()
167167
.take(build.breakSettings.breaksPerTick)
168168

169-
instantResults.firstOrNull()?.let { firstInstant ->
170-
if (!hotbar.request(HotbarRequest(firstInstant.context.hotbarIndex)).done) return@onRotate
171-
build.breakSettings.request(BreakRequest(instantResults.map { it.context }, build, rotation) { breaks++ })
169+
instantResults.firstOrNull()?.let {
170+
build.breakSettings.request(BreakRequest(instantResults.map { it.context }, build, rotation, hotbar) { breaks++ })
172171
return@onRotate
173172
}
174173
}
@@ -210,7 +209,7 @@ class BuildTask @Ta5kBuilder constructor(
210209
if (bestResult !is BreakResult.Break) return@onRotate
211210

212211
val contexts = resultsNotBlocked.filterIsInstance<BreakResult.Break>().take(2).map { it.context }
213-
val request = BreakRequest(contexts, build, rotation) { breaks++ }
212+
val request = BreakRequest(contexts, build, rotation, hotbar) { breaks++ }
214213
build.breakSettings.request(request)
215214
}
216215

0 commit comments

Comments
 (0)