Skip to content

Commit fca9ae2

Browse files
committed
Decision making on tick post
1 parent e60615f commit fca9ae2

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ object RotationManager : RequestHandler<RotationRequest>(), Loadable {
5353
override fun load() = "Loaded Rotation Manager"
5454

5555
/**
56-
* Registers a listener called right before [RotationManager] updates the context and the rotation
56+
* Registers a listener called immediately before [RotationManager] handles its context and applies rotation updates.
5757
*
58-
* Use this if you need to match specific state of the client
59-
* (when the player and its input are already updated this tick and similar) /
60-
* when you don't know when to rotate / you simply want to request before rotation update
58+
* This is useful if you need to synchronize with the latest player state (including inputs and movement),
59+
* or if you must place your rotation requests as the tick is completed and just before the new rotation is processed.
60+
*
61+
* @param alwaysListen Whether to keep this listener active at all times. Defaults to false.
62+
* @param block A callback providing a [SafeContext] where you can place rotation-related operations or other logic.
6163
*/
6264
fun Any.onRotate(
6365
alwaysListen: Boolean = false,

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package com.lambda.task.tasks
2020
import com.lambda.Lambda.LOG
2121
import com.lambda.config.groups.BuildConfig
2222
import com.lambda.config.groups.InteractionConfig
23-
import com.lambda.config.groups.InteractionSettings
2423
import com.lambda.config.groups.InventoryConfig
2524
import com.lambda.interaction.request.rotation.RotationConfig
2625
import com.lambda.context.SafeContext
@@ -40,7 +39,6 @@ import com.lambda.interaction.construction.simulation.BuildGoal
4039
import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
4140
import com.lambda.interaction.construction.simulation.Simulation.Companion.simulation
4241
import com.lambda.interaction.construction.verify.TargetState
43-
import com.lambda.interaction.request.rotation.visibilty.PointSelection
4442
import com.lambda.module.modules.client.TaskFlowModule
4543
import com.lambda.task.Task
4644
import com.lambda.util.BaritoneUtils
@@ -86,12 +84,13 @@ class BuildTask @Ta5kBuilder constructor(
8684
}
8785

8886
currentPlacement?.let { context ->
89-
currentPlacement = null
9087
if (build.rotateForPlace && !context.rotation.done) return@listen
9188
context.place(interact.swingHand)
9289
pendingPlacements.add(context)
9390
}
91+
}
9492

93+
listen<TickEvent.Post> {
9594
(blueprint as? DynamicBlueprint)?.update()
9695

9796
if (finishOnDone && blueprint.structure.isEmpty()) {
@@ -100,7 +99,7 @@ class BuildTask @Ta5kBuilder constructor(
10099
}
101100

102101
// ToDo: Simulate for each pair player positions that work
103-
val results = blueprint.simulate(player.getCameraPosVec(mc.tickDelta), interact, rotation, inventory)
102+
val results = blueprint.simulate(player.eyePos, interact, rotation, inventory)
104103
TaskFlowModule.drawables = results.filterIsInstance<Drawable>().plus(pendingPlacements.toList())
105104

106105
val instantResults = results.filterIsInstance<BreakResult.Break>()
@@ -115,12 +114,12 @@ class BuildTask @Ta5kBuilder constructor(
115114
return@listen
116115
}
117116

118-
val resultsWithoutPending = results.filterNot { res ->
117+
val resultsWithoutPending = results.filterNot { result ->
119118
val blockedPositions = pendingPlacements.map { it.expectedPos }
120-
res is PlaceResult.Place && res.context.expectedPos in blockedPositions
119+
result is PlaceResult.Place && result.context.expectedPos in blockedPositions
121120
}
122-
val result = resultsWithoutPending.minOrNull() ?: return@listen
123-
when (result) {
121+
val bestResult = resultsWithoutPending.minOrNull() ?: return@listen
122+
when (bestResult) {
124123
is BuildResult.Done,
125124
is BuildResult.Ignored,
126125
is BuildResult.Unbreakable,
@@ -151,23 +150,23 @@ class BuildTask @Ta5kBuilder constructor(
151150
}
152151

153152
is Navigable -> {
154-
if (build.pathing) BaritoneUtils.setGoalAndPath(result.goal)
153+
if (build.pathing) BaritoneUtils.setGoalAndPath(bestResult.goal)
155154
}
156155

157156
is PlaceResult.Place -> {
158157
if (pendingPlacements.size >= build.maxPendingPlacements) return@listen
159158

160-
currentPlacement = result.context
159+
currentPlacement = bestResult.context
161160
}
162161

163162
is Resolvable -> {
164-
LOG.info("Resolving: ${result.name}")
163+
LOG.info("Resolving: ${bestResult.name}")
165164

166-
if (result is BreakResult.Break) {
167-
result.collectDrop = collectDrops
165+
if (bestResult is BreakResult.Break) {
166+
bestResult.collectDrop = collectDrops
168167
}
169168

170-
result.resolve().execute(this@BuildTask, pauseParent = result.pausesParent)
169+
bestResult.resolve().execute(this@BuildTask, pauseParent = bestResult.pausesParent)
171170
}
172171
}
173172
}

0 commit comments

Comments
 (0)