Skip to content

Commit 1012d89

Browse files
committed
Smarter intermediate pathing
1 parent b3e21a4 commit 1012d89

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ data class Simulation(
6666
blueprint.simulate(view, interact, rotation, inventory, build)
6767
}
6868

69-
fun goodPositions() = cache.filter { it.value.any { it.rank.ordinal < 4 } }.map { PossiblePos(it.key.toBlockPos()) }
69+
fun goodPositions() = cache
70+
.filter { entry -> entry.value.any { it.rank.ordinal < 4 } }
71+
.map { PossiblePos(it.key.toBlockPos(), it.value.count { it.rank.ordinal < 4 }) }
7072

71-
class PossiblePos(val pos: BlockPos): Drawable {
73+
class PossiblePos(val pos: BlockPos, val interactions: Int): Drawable {
7274
override fun SafeContext.buildRenderer() {
7375
withBox(Vec3d.ofBottomCenter(pos).playerBox(), Color(0, 255, 0, 50))
7476
}

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.task.tasks
1919

2020
import baritone.api.pathing.goals.GoalBlock
21+
import baritone.api.pathing.goals.GoalNear
2122
import com.lambda.Lambda.LOG
2223
import com.lambda.config.groups.BuildConfig
2324
import com.lambda.config.groups.InteractionConfig
@@ -55,6 +56,7 @@ import com.lambda.util.extension.Structure
5556
import com.lambda.util.extension.inventorySlots
5657
import com.lambda.util.item.ItemUtils.block
5758
import com.lambda.util.player.SlotUtils.hotbarAndStorage
59+
import com.lambda.util.world.toFastVec
5860
import net.minecraft.entity.ItemEntity
5961
import net.minecraft.util.math.BlockPos
6062
import java.util.concurrent.ConcurrentLinkedQueue
@@ -95,13 +97,26 @@ class BuildTask @Ta5kBuilder constructor(
9597
listen<TickEvent.Pre> {
9698
if (collectDrops()) return@listen
9799

98-
// ToDo: Simulate for each pair player positions that work
99100
val results = blueprint.simulate(player.eyePos, interact, rotation, inventory, build)
101+
val resultPostions = results.map { it.blockPos }
100102

101-
TaskFlowModule.drawables = results
103+
val sim = blueprint.simulation(interact, rotation, inventory, build)
104+
BlockPos.iterateOutwards(player.blockPos, 2, 2, 2).forEach {
105+
sim.simulate(it.toFastVec())
106+
}
107+
val bestPos = sim.goodPositions()
108+
.filter { it.pos !in resultPostions }
109+
.maxByOrNull { it.interactions }
110+
111+
val drawables = results
102112
.filterIsInstance<Drawable>()
103113
.plus(pendingInteractions.toList())
104-
// .plus(sim.goodPositions())
114+
.toMutableList()
115+
116+
if (bestPos != null) {
117+
drawables.add(bestPos)
118+
}
119+
TaskFlowModule.drawables = drawables
105120

106121
val resultsNotBlocked = results
107122
.filter { result -> pendingInteractions.none { it.expectedPos == result.blockPos } }
@@ -127,7 +142,6 @@ class BuildTask @Ta5kBuilder constructor(
127142
is BuildResult.NotVisible,
128143
is PlaceResult.NoIntegrity -> {
129144
if (!build.pathing) return@listen
130-
val sim = blueprint.simulation(interact, rotation, inventory, build)
131145
val goal = BuildGoal(sim, player.blockPos)
132146
BaritoneUtils.setGoalAndPath(goal)
133147
}
@@ -137,6 +151,10 @@ class BuildTask @Ta5kBuilder constructor(
137151
}
138152

139153
is BuildResult.Contextual -> {
154+
bestPos?.let {
155+
BaritoneUtils.setGoalAndPath(GoalNear(it.pos, 1))
156+
}
157+
140158
if (atMaxPendingInteractions) return@listen
141159
when (bestResult) {
142160
is BreakResult.Break -> {

0 commit comments

Comments
 (0)