Skip to content

Commit a7b7d63

Browse files
committed
Fix BuildTask context build timing, block inaccurate pathing positions
1 parent f181bd4 commit a7b7d63

File tree

6 files changed

+30
-44
lines changed

6 files changed

+30
-44
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/context/BuildContext.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,5 @@ interface BuildContext : Comparable<BuildContext>, Drawable {
3939
val rotation: RotationRequest
4040

4141
fun interact(swingHand: Boolean)
42-
43-
override fun compareTo(other: BuildContext) =
44-
compareBy<BuildContext> {
45-
it.distance
46-
}.compare(this, other)
47-
4842
fun shouldRotate(config: BuildConfig): Boolean
4943
}

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildGoal.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ package com.lambda.interaction.construction.simulation
1919

2020
import baritone.api.pathing.goals.Goal
2121
import com.lambda.util.world.fastVectorOf
22+
import com.lambda.util.world.toFastVec
23+
import net.minecraft.util.math.BlockPos
2224

23-
class BuildGoal(private val sim: Simulation) : Goal {
24-
override fun isInGoal(x: Int, y: Int, z: Int) =
25-
sim.simulate(fastVectorOf(x, y, z))
26-
.any { it.rank.ordinal < 4 }
25+
class BuildGoal(
26+
private val sim: Simulation,
27+
blocked: BlockPos
28+
) : Goal {
29+
private val blockedVec = blocked.toFastVec()
30+
31+
override fun isInGoal(x: Int, y: Int, z: Int): Boolean {
32+
val pos = fastVectorOf(x, y, z)
33+
return sim.simulate(pos).any { it.rank.ordinal < 4 } && blockedVec != pos
34+
}
2735

2836
override fun heuristic(x: Int, y: Int, z: Int): Double {
2937
val bestRank = sim.simulate(fastVectorOf(x, y, z))

common/src/main/kotlin/com/lambda/interaction/construction/simulation/BuildSimulator.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,7 @@ object BuildSimulator {
290290
val placeContext = PlaceContext(
291291
eye,
292292
blockHit,
293-
RotationRequest(
294-
lookAtBlock(blockHit.blockPos, setOf(blockHit.side), config = interact), rotation
295-
),
293+
RotationRequest(lookAt(checkedHit.targetRotation, 0.001), rotation),
296294
eye.distanceTo(blockHit.pos),
297295
resultState,
298296
blockHit.blockPos.blockState(world),

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,4 @@ data class RotationRequest(
4343
mode == RotationMode.None || runSafe {
4444
target.verify(target)
4545
} == true
46-
47-
fun megaDone() = target.distance < 0.001
4846
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ data class RotationTarget(
3939
val verify: RotationTarget.() -> Boolean = { hit?.verifyRotation() ?: true },
4040
private val buildRotation: SafeContext.() -> Rotation?,
4141
) {
42-
4342
val targetRotation = resettableLazy {
4443
runSafe { buildRotation() }
4544
}

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

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class BuildTask @Ta5kBuilder constructor(
6767
build.maxPendingInteractions, build.interactionTimeout * 50L
6868
) { info("${it::class.simpleName} at ${it.expectedPos.toShortString()} timed out") }
6969
private var currentInteraction: BuildContext? = null
70+
private val instantBreaks = mutableSetOf<BreakContext>()
7071

7172
private var placements = 0
7273
private var breaks = 0
@@ -79,9 +80,14 @@ class BuildTask @Ta5kBuilder constructor(
7980
init {
8081
listen<TickEvent.Pre> {
8182
currentInteraction?.let { context ->
82-
if (context.shouldRotate(build) && !context.rotation.megaDone()) return@listen
83+
if (context.shouldRotate(build) && !context.rotation.done) return@let
8384
context.interact(interact.swingHand)
8485
}
86+
instantBreaks.forEach { context ->
87+
context.interact(interact.swingHand)
88+
pendingInteractions.add(context)
89+
}
90+
instantBreaks.clear()
8591
}
8692

8793
listen<TickEvent.Post> {
@@ -91,7 +97,9 @@ class BuildTask @Ta5kBuilder constructor(
9197
failure("Structure is empty")
9298
return@listen
9399
}
100+
}
94101

102+
onRotate {
95103
// val sim = blueprint.simulation(interact, rotation, inventory)
96104
// BlockPos.iterateOutwards(player.blockPos, 5, 5, 5).forEach { pos ->
97105
// sim.simulate(pos.toFastVec())
@@ -109,50 +117,33 @@ class BuildTask @Ta5kBuilder constructor(
109117
.sorted()
110118
.take(build.breaksPerTick)
111119

112-
instantResults.forEach {
113-
it.context.interact(interact.swingHand)
114-
pendingInteractions.add(it.context)
115-
}
120+
instantBreaks.addAll(instantResults.map { it.context })
116121

117-
if (instantResults.isNotEmpty()) return@listen
122+
if (instantResults.isNotEmpty()) return@onRotate
118123
}
119124

120125
val resultsWithoutPending = results.filterNot { result ->
121126
result.blockPos in pendingInteractions.map { it.expectedPos }
122127
}
123-
val bestResult = resultsWithoutPending.minOrNull() ?: return@listen
128+
val bestResult = resultsWithoutPending.minOrNull() ?: return@onRotate
124129
when (bestResult) {
125130
is BuildResult.Done,
126131
is BuildResult.Ignored,
127132
is BuildResult.Unbreakable,
128133
is BuildResult.Restricted,
129134
is BuildResult.NoPermission -> {
130-
if (pendingInteractions.isNotEmpty()) return@listen
135+
if (pendingInteractions.isNotEmpty()) return@onRotate
131136
if (blueprint is PropagatingBlueprint) {
132137
blueprint.next()
133-
return@listen
138+
return@onRotate
134139
}
135140
if (finishOnDone) success()
136141
}
137142

138143
is BuildResult.NotVisible,
139144
is PlaceResult.NoIntegrity -> {
140-
if (!build.pathing) return@listen
141-
// ToDo:
142-
// Solve the problem that baritone stops pathing when it thinks it is in a valid goal
143-
// but the player position does not perfectly match the simulated position
144-
// hacky fix for now is to walk "closer" but it wont work in every situation
145-
val interaction = object : InteractionConfig {
146-
override val attackReach = 3.0
147-
override val interactReach = interact.interactReach - 1
148-
override val scanReach = interact.scanReach
149-
override val strictRayCast = interact.strictRayCast
150-
override val checkSideVisibility = interact.checkSideVisibility
151-
override val resolution = interact.resolution
152-
override val pointSelection = interact.pointSelection
153-
override val swingHand = interact.swingHand
154-
}
155-
val goal = BuildGoal(blueprint.simulation(interaction, rotation, inventory, build))
145+
if (!build.pathing) return@onRotate
146+
val goal = BuildGoal(blueprint.simulation(interact, rotation, inventory, build), player.blockPos)
156147
BaritoneUtils.setGoalAndPath(goal)
157148
}
158149

@@ -161,7 +152,7 @@ class BuildTask @Ta5kBuilder constructor(
161152
}
162153

163154
is BuildResult.Contextual -> {
164-
if (pendingInteractions.size >= build.maxPendingInteractions) return@listen
155+
if (pendingInteractions.size >= build.maxPendingInteractions) return@onRotate
165156

166157
currentInteraction = bestResult.context
167158
}
@@ -172,9 +163,7 @@ class BuildTask @Ta5kBuilder constructor(
172163
bestResult.resolve().execute(this@BuildTask)
173164
}
174165
}
175-
}
176166

177-
onRotate {
178167
if (!build.rotateForPlace) return@onRotate
179168
val rotateTo = currentInteraction?.rotation ?: return@onRotate
180169

0 commit comments

Comments
 (0)