Skip to content

Commit 8c846ec

Browse files
committed
manager utils, abstracted blockedPositions, and build task now checks blocked positions before calling success
1 parent 6edb0a6 commit 8c846ec

File tree

5 files changed

+74
-10
lines changed

5 files changed

+74
-10
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.request
19+
20+
import com.lambda.interaction.request.breaking.BreakManager
21+
import com.lambda.interaction.request.hotbar.HotbarManager
22+
import com.lambda.interaction.request.placing.PlaceManager
23+
import com.lambda.interaction.request.rotation.RotationManager
24+
25+
object ManagerUtils {
26+
val managers = listOf(
27+
RotationManager,
28+
HotbarManager,
29+
BreakManager,
30+
PlaceManager
31+
)
32+
33+
val positionBlockingManagers = managers
34+
.filterIsInstance<PositionBlocking>()
35+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.interaction.request
19+
20+
import net.minecraft.util.math.BlockPos
21+
22+
interface PositionBlocking {
23+
val blockedPositions: List<BlockPos>
24+
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.lambda.event.events.WorldEvent
2626
import com.lambda.event.listener.SafeListener.Companion.listen
2727
import com.lambda.interaction.construction.context.BreakContext
2828
import com.lambda.interaction.construction.verify.TargetState
29+
import com.lambda.interaction.request.PositionBlocking
2930
import com.lambda.interaction.request.RequestHandler
3031
import com.lambda.interaction.request.breaking.BreakConfig.BreakConfirmationMode
3132
import com.lambda.interaction.request.breaking.BreakConfig.BreakMode
@@ -57,7 +58,7 @@ import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
5758
import net.minecraft.sound.SoundCategory
5859
import net.minecraft.util.math.BlockPos
5960

60-
object BreakManager : RequestHandler<BreakRequest>() {
61+
object BreakManager : RequestHandler<BreakRequest>(), PositionBlocking {
6162
private var primaryBreakingInfo: BreakInfo?
6263
get() = breakingInfos[0]
6364
set(value) { breakingInfos[0] = value }
@@ -70,16 +71,16 @@ object BreakManager : RequestHandler<BreakRequest>() {
7071
TaskFlowModule.build.maxPendingInteractions, TaskFlowModule.build.interactionTimeout * 50L
7172
) { info("${it::class.simpleName} at ${it.context.expectedPos.toShortString()} timed out") }
7273

73-
val blockedPositions
74+
override val blockedPositions
7475
get() = breakingInfos.mapNotNull { it?.context?.expectedPos } + pendingInteractions.map { it.context.expectedPos }
7576

77+
private var rotation: RotationRequest? = null
78+
private var validRotation = false
79+
7680
private var blockBreakingCooldown = 0
7781

7882
private var instantBreaks = listOf<BreakContext>()
7983

80-
private var rotation: RotationRequest? = null
81-
private var validRotation = false
82-
8384
fun Any.onBreak(
8485
alwaysListen: Boolean = false,
8586
block: SafeContext.() -> Unit

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.lambda.event.events.WorldEvent
2727
import com.lambda.event.listener.SafeListener.Companion.listen
2828
import com.lambda.interaction.construction.context.PlaceContext
2929
import com.lambda.interaction.construction.verify.TargetState
30+
import com.lambda.interaction.request.PositionBlocking
3031
import com.lambda.interaction.request.RequestHandler
3132
import com.lambda.interaction.request.breaking.BreakManager
3233
import com.lambda.interaction.request.hotbar.HotbarRequest
@@ -56,17 +57,17 @@ import net.minecraft.util.math.BlockPos
5657
import net.minecraft.world.GameMode
5758
import org.apache.commons.lang3.mutable.MutableObject
5859

59-
object PlaceManager : RequestHandler<PlaceRequest>() {
60+
object PlaceManager : RequestHandler<PlaceRequest>(), PositionBlocking {
6061
private val pendingInteractions = LimitedDecayQueue<PlaceInfo>(
6162
TaskFlowModule.build.maxPendingInteractions, TaskFlowModule.build.interactionTimeout * 50L
6263
) { info("${it::class.simpleName} at ${it.context.expectedPos.toShortString()} timed out") }
6364

65+
override val blockedPositions
66+
get() = pendingInteractions.map { it.context.expectedPos }
67+
6468
private var rotation: RotationRequest? = null
6569
private var validRotation = false
6670

67-
val blockedPositions
68-
get() = pendingInteractions.map { it.context.expectedPos }
69-
7071
init {
7172
listen<TickEvent.Pre>(priority = Int.MIN_VALUE) {
7273
currentRequest?.let { request ->

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
3939
import com.lambda.interaction.construction.simulation.Simulation.Companion.simulation
4040
import com.lambda.interaction.construction.verify.TargetState
4141
import com.lambda.interaction.material.transfer.TransactionExecutor.Companion.transfer
42+
import com.lambda.interaction.request.ManagerUtils.positionBlockingManagers
4243
import com.lambda.interaction.request.breaking.BreakManager
4344
import com.lambda.interaction.request.breaking.BreakRequest
4445
import com.lambda.interaction.request.hotbar.HotbarConfig
@@ -140,7 +141,9 @@ class BuildTask @Ta5kBuilder constructor(
140141
blueprint.next()
141142
return@onRotate
142143
}
143-
if (finishOnDone) success()
144+
145+
val managersStillRunning = positionBlockingManagers.any { it.blockedPositions.isNotEmpty() }
146+
if (finishOnDone && !managersStillRunning) success()
144147
}
145148

146149
is BuildResult.NotVisible,

0 commit comments

Comments
 (0)