Skip to content

Commit 62fd5c2

Browse files
committed
Merge remote-tracking branch 'origin/feature/packetmine-rewrite' into feature/packetmine-rewrite
2 parents 9fd7234 + 1012d89 commit 62fd5c2

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import com.lambda.interaction.construction.verify.TargetState
2525
import com.lambda.interaction.request.rotation.RotationRequest
2626
import com.lambda.util.world.raycast.RayCastUtils.distanceTo
2727
import net.minecraft.block.BlockState
28+
import net.minecraft.block.Blocks
29+
import net.minecraft.block.FallingBlock
2830
import net.minecraft.client.network.ClientPlayerInteractionManager
2931
import net.minecraft.client.world.ClientWorld
3032
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
@@ -56,14 +58,16 @@ data class BreakContext(
5658

5759
fun exposedSides(ctx: SafeContext) =
5860
Direction.entries.filter {
59-
ctx.world.isAir(result.blockPos.offset(it))
61+
ctx.world.isAir(expectedPos.offset(it))
6062
}
6163

6264
override val expectedState: BlockState = checkedState.fluidState.blockState
6365

6466
override fun compareTo(other: BuildContext): Int {
6567
return when (other) {
66-
is BreakContext -> compareBy<BreakContext> {
68+
is BreakContext -> compareByDescending<BreakContext> {
69+
if (it.checkedState.block is FallingBlock) it.expectedPos.y else 0
70+
}.thenBy {
6771
it.rotation.target.angleDistance
6872
}.compare(this, other)
6973

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)