Skip to content

Commit b3221c2

Browse files
committed
correct packetmine sorting, remove separating instant breaks from regular in break manager as build result sorting should do that already, and add rebreak renders
1 parent dec89a2 commit b3221c2

File tree

7 files changed

+40
-50
lines changed

7 files changed

+40
-50
lines changed

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

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

2020
import com.lambda.context.AutomatedSafeContext
21-
import com.lambda.interaction.construction.blueprint.Blueprint
2221
import com.lambda.interaction.construction.result.BuildResult
2322
import com.lambda.interaction.construction.result.results.PostSimResult
2423
import com.lambda.interaction.construction.simulation.ISimInfo.Companion.sim
@@ -27,6 +26,7 @@ import com.lambda.interaction.construction.simulation.checks.PlaceSim.Companion.
2726
import com.lambda.interaction.construction.simulation.checks.PostProcessingSim.Companion.simPostProcessing
2827
import com.lambda.interaction.construction.verify.TargetState
2928
import com.lambda.util.BlockUtils.blockState
29+
import com.lambda.util.extension.Structure
3030
import io.ktor.util.collections.*
3131
import kotlinx.coroutines.Dispatchers
3232
import kotlinx.coroutines.launch
@@ -46,14 +46,14 @@ object BuildSimulator : Sim<PostSimResult>() {
4646
* @see simBreak
4747
*/
4848
context(automatedSafeContext: AutomatedSafeContext)
49-
fun Blueprint.simulate(
49+
fun Structure.simulate(
5050
pov: Vec3d = automatedSafeContext.player.eyePos
51-
): Set<BuildResult> = runBlocking(Dispatchers.Default) {
51+
) : Set<BuildResult> = runBlocking(Dispatchers.Default) {
5252
supervisorScope {
5353
val concurrentSet = ConcurrentSet<BuildResult>()
5454

5555
with(automatedSafeContext) {
56-
structure.forEach { (pos, targetState) ->
56+
forEach { (pos, targetState) ->
5757
launch {
5858
sim(pos, blockState(pos), targetState, pov, concurrentSet) {
5959
if (targetState is TargetState.State && matchesTarget(complete = false)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ data class Simulation(
5454
val isWalkable = blockState(blockPos.down()).isSideSolidFullSquare(world, blockPos, Direction.UP)
5555
if (!isWalkable) return@getOrPut emptySet()
5656
if (!playerFitsIn(blockPos)) return@getOrPut emptySet()
57-
blueprint.simulate(pov)
57+
blueprint.structure.simulate(pov)
5858
} ?: emptySet()
5959
}
6060

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import com.lambda.event.listener.SafeListener.Companion.listen
3131
import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe
3232
import com.lambda.graphics.renderer.esp.DynamicAABB
3333
import com.lambda.interaction.construction.blueprint.Blueprint.Companion.toStructure
34-
import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
3534
import com.lambda.interaction.construction.context.BreakContext
3635
import com.lambda.interaction.construction.result.results.BreakResult
3736
import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
@@ -418,7 +417,6 @@ object BreakManager : RequestHandler<BreakRequest>(
418417
}
419418

420419
breaks = newBreaks
421-
.sortedByDescending { it.instantBreak }
422420
.take(
423421
min(
424422
breakConfig.maxPendingBreaks - pendingBreakCount,
@@ -563,7 +561,6 @@ object BreakManager : RequestHandler<BreakRequest>(
563561
abandonedInfo.request.runSafeAutomated {
564562
abandonedInfo.context.blockPos
565563
.toStructure(TargetState.Empty)
566-
.toBlueprint()
567564
.simulate()
568565
.filterIsInstance<BreakResult.Break>()
569566
.filter { canAccept(it.context) }

src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,18 @@
1818
package com.lambda.module.modules.player
1919

2020
import com.lambda.config.AutomationConfig.Companion.automationConfig
21-
import com.lambda.config.groups.BuildConfig
2221
import com.lambda.context.SafeContext
2322
import com.lambda.event.events.PlayerEvent
2423
import com.lambda.event.events.TickEvent
2524
import com.lambda.event.events.onStaticRender
2625
import com.lambda.event.listener.SafeListener.Companion.listen
27-
import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
2826
import com.lambda.interaction.construction.context.BreakContext
2927
import com.lambda.interaction.construction.context.BuildContext
3028
import com.lambda.interaction.construction.result.results.BreakResult
3129
import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
3230
import com.lambda.interaction.construction.verify.TargetState
3331
import com.lambda.interaction.request.breaking.BreakConfig
3432
import com.lambda.interaction.request.breaking.BreakRequest.Companion.breakRequest
35-
import com.lambda.interaction.request.inventory.InventoryConfig
3633
import com.lambda.module.Module
3734
import com.lambda.module.tag.ModuleTag
3835
import com.lambda.threading.runSafeAutomated
@@ -64,13 +61,15 @@ object PacketMine : Module(
6461
.onValueChange { _, to -> if (!to) queuePositions.clear() }
6562
private val queueOrder by setting("Queue Order", QueueOrder.Standard, "Which end of the queue to break blocks from") { queue }.group(Group.General)
6663

67-
private val renderQueue by setting("Render Queue", true, "Adds renders to signify what block positions are queued").disabled { !breakConfig.renders }.group(Group.Renders)
68-
private val renderSize by setting("Render Size", 0.3f, 0.01f..1f, 0.01f, "The scale of the queue renders") { renderQueue }.disabled { !breakConfig.renders }.group(Group.Renders)
69-
private val renderMode by setting("Render Mode", RenderMode.State, "The style of the queue renders") { renderQueue }.disabled { !breakConfig.renders }.group(Group.Renders)
70-
private val dynamicColor by setting("Dynamic Color", true, "Interpolates the color between start and end") { renderQueue }.disabled { !breakConfig.renders }.group(Group.Renders)
71-
private val staticColor by setting("Color", Color(255, 0, 0, 60).brighter()) { renderQueue && !dynamicColor }.disabled { !breakConfig.renders }.group(Group.Renders)
72-
private val startColor by setting("Start Color", Color(255, 255, 0, 60).brighter(), "The color of the start (closest to breaking) of the queue") { renderQueue && dynamicColor }.disabled { !breakConfig.renders }.group(Group.Renders)
73-
private val endColor by setting("End Color", Color(255, 0, 0, 60).brighter(), "The color of the end (farthest from breaking) of the queue") { renderQueue && dynamicColor }.disabled { !breakConfig.renders }.group(Group.Renders)
64+
private val renderRebreak by setting("Render Rebreak", true, "Displays what block is being checked for rebreak").group(Group.Renders)
65+
private val rebreakColor by setting("Rebreak Color", Color.RED) { renderRebreak }.group(Group.Renders)
66+
private val renderQueue by setting("Render Queue", true, "Adds renders to signify what block positions are queued").group(Group.Renders)
67+
private val renderSize by setting("Render Size", 0.3f, 0.01f..1f, 0.01f, "The scale of the queue renders") { renderQueue }.group(Group.Renders)
68+
private val renderMode by setting("Render Mode", RenderMode.State, "The style of the queue renders") { renderQueue }.group(Group.Renders)
69+
private val dynamicColor by setting("Dynamic Color", true, "Interpolates the color between start and end") { renderQueue }.group(Group.Renders)
70+
private val staticColor by setting("Color", Color(255, 0, 0, 60)) { renderQueue && !dynamicColor }.group(Group.Renders)
71+
private val startColor by setting("Start Color", Color(255, 255, 0, 60), "The color of the start (closest to breaking) of the queue") { renderQueue && dynamicColor }.group(Group.Renders)
72+
private val endColor by setting("End Color", Color(255, 0, 0, 60), "The color of the end (farthest from breaking) of the queue") { renderQueue && dynamicColor }.group(Group.Renders)
7473

7574
private val pendingInteractions = ConcurrentLinkedQueue<BuildContext>()
7675

@@ -81,7 +80,8 @@ object PacketMine : Module(
8180
private val queuePositions = ArrayList<MutableCollection<BlockPos>>()
8281
private val SafeContext.queueSorted
8382
get() = when (queueOrder) {
84-
QueueOrder.Standard -> queuePositions
83+
QueueOrder.Standard,
84+
QueueOrder.Efficient -> queuePositions
8585
QueueOrder.Reversed -> queuePositions.asReversed()
8686
QueueOrder.Closest -> queuePositions.sortedBy {
8787
it.firstOrNull()
@@ -92,21 +92,9 @@ object PacketMine : Module(
9292
}
9393
}
9494

95-
private var reBreakPos: BlockPos? = null
95+
private var rebreakPos: BlockPos? = null
9696
private var attackedThisTick = false
9797

98-
override val buildConfig = object : BuildConfig by super.buildConfig {
99-
override val pathing = false
100-
override val stayInRange = false
101-
override val collectDrops = false
102-
}
103-
override val inventoryConfig = object : InventoryConfig by super.inventoryConfig {
104-
override val accessShulkerBoxes = false
105-
override val accessEnderChest = false
106-
override val accessChests = false
107-
override val accessStashes = false
108-
}
109-
11098
init {
11199
defaultAutomationConfig = automationConfig {
112100
breakConfig.apply {
@@ -169,12 +157,15 @@ object PacketMine : Module(
169157
if (!attackedThisTick) {
170158
requestBreakManager((breakPositions + queueSorted.flatten()).toList())
171159
if (!breakConfig.rebreak || (rebreakMode != RebreakMode.Auto && rebreakMode != RebreakMode.AutoConstant)) return@listen
172-
val reBreak = reBreakPos ?: return@listen
160+
val reBreak = rebreakPos ?: return@listen
173161
requestBreakManager(listOf(reBreak), true)
174162
}
175163
}
176164

177-
onStaticRender {
165+
onStaticRender { event ->
166+
if (renderRebreak) {
167+
rebreakPos?.let { event.outline(it, rebreakColor) }
168+
}
178169
if (!renderQueue) return@onStaticRender
179170
queueSorted.forEachIndexed { index, positions ->
180171
positions.forEach { pos ->
@@ -186,7 +177,7 @@ object PacketMine : Module(
186177
}.map { lerp(renderSize.toDouble(), Box(it.center, it.center), it).offset(pos) }
187178

188179
boxes.forEach { box ->
189-
it.box(box, color, color.setAlpha(1.0))
180+
event.box(box, color, color.setAlpha(1.0))
190181
}
191182
}
192183
}
@@ -196,7 +187,7 @@ object PacketMine : Module(
196187
breakPositions[0] = null
197188
breakPositions[1] = null
198189
queuePositions.clear()
199-
reBreakPos = null
190+
rebreakPos = null
200191
attackedThisTick = false
201192
}
202193
}
@@ -212,8 +203,8 @@ object PacketMine : Module(
212203
onUpdate { onProgress(it) }
213204
onStop { removeBreak(it); breaks++ }
214205
onCancel { removeBreak(it, true) }
215-
onReBreakStart { reBreakPos = it }
216-
onReBreak { removeBreak(it); reBreakPos = it }
206+
onReBreakStart { rebreakPos = it }
207+
onReBreak { removeBreak(it); rebreakPos = it }
217208
}.submit()
218209
}
219210

@@ -228,20 +219,23 @@ object PacketMine : Module(
228219
runSafeAutomated {
229220
positions
230221
.filterNotNull()
231-
.associateWith { TargetState.State(blockState(it).fluidState.blockState) }
232-
.toBlueprint()
222+
.associateWith { TargetState.Empty }
233223
.simulate()
234224
.filterIsInstance<BreakResult.Break>()
225+
.let {
226+
if (queueOrder == QueueOrder.Efficient) it.sorted()
227+
else it.sortedBy { ctx -> positions.indexOf(ctx.pos) }
228+
}
235229
.map { it.context }
236-
.toCollection(mutableListOf())
230+
237231
}
238232

239233
private fun addBreak(pos: BlockPos) {
240234
if (breakConfig.doubleBreak && breakPositions[0] != null) {
241235
breakPositions[1] = breakPositions[0]
242236
}
243237
breakPositions[0] = pos
244-
reBreakPos = null
238+
rebreakPos = null
245239
}
246240

247241
private fun removeBreak(pos: BlockPos, includeReBreak: Boolean = false) {
@@ -250,8 +244,8 @@ object PacketMine : Module(
250244
breakPositions[index] = null
251245
}
252246
}
253-
if (includeReBreak && pos == reBreakPos) {
254-
reBreakPos = null
247+
if (includeReBreak && pos == rebreakPos) {
248+
rebreakPos = null
255249
}
256250
}
257251

@@ -288,6 +282,7 @@ object PacketMine : Module(
288282
) : NamedEnum, Describable {
289283
Manual("Manual", "Re-break only when you trigger it explicitly."),
290284
Auto("Auto", "Automatically re-break when it’s beneficial or required."),
285+
//ToDo: Implement auto constant rebreak
291286
AutoConstant("Auto (Constant)", "Continuously re-break as soon as conditions allow; most aggressive.")
292287
}
293288

@@ -297,7 +292,8 @@ object PacketMine : Module(
297292
) : NamedEnum, Describable {
298293
Standard("Standard", "Process in planned order (first in, first out)."),
299294
Reversed("Reversed", "Process in reverse planned order (last in, first out)."),
300-
Closest("Closest", "Process the closest targets first.")
295+
Closest("Closest", "Process the closest targets first."),
296+
Efficient("Efficient", "Process the most efficient targets first.")
301297
}
302298

303299
private enum class RenderMode(

src/main/kotlin/com/lambda/module/modules/player/Scaffold.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import com.lambda.context.SafeContext
2424
import com.lambda.event.events.MovementEvent
2525
import com.lambda.event.events.TickEvent
2626
import com.lambda.event.listener.SafeListener.Companion.listen
27-
import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
2827
import com.lambda.interaction.construction.context.BuildContext
2928
import com.lambda.interaction.construction.result.results.PlaceResult
3029
import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
@@ -93,7 +92,6 @@ object Scaffold : Module(
9392
runSafeAutomated {
9493
scaffoldPositions(beneath)
9594
.associateWith { TargetState.Solid(emptySet()) }
96-
.toBlueprint()
9795
.simulate()
9896
.filterIsInstance<PlaceResult.Place>()
9997
.minByOrNull { it.pos distSq beneath }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ package com.lambda.task.tasks
1919

2020
import baritone.api.pathing.goals.GoalBlock
2121
import com.lambda.Lambda.LOG
22+
import com.lambda.config.AutomationConfig.Companion.DEFAULT
2223
import com.lambda.config.groups.EatConfig.Companion.reasonEating
2324
import com.lambda.context.Automated
24-
import com.lambda.config.AutomationConfig.Companion.DEFAULT
2525
import com.lambda.context.SafeContext
2626
import com.lambda.event.events.TickEvent
2727
import com.lambda.event.listener.SafeListener.Companion.listen
@@ -121,7 +121,7 @@ class BuildTask private constructor(
121121
}
122122

123123
private fun SafeContext.simulateAndProcess() {
124-
val results = runSafeAutomated { blueprint.simulate() }
124+
val results = runSafeAutomated { blueprint.structure.simulate() }
125125

126126
DEFAULT.drawables = results
127127
.filterIsInstance<Drawable>()

src/main/kotlin/com/lambda/task/tasks/PlaceContainer.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class PlaceContainer @Ta5kBuilder constructor(
5454
.filter { !ManagerUtils.isPosBlocked(it) }
5555
.flatMap {
5656
it.toStructure(TargetState.Stack(startStack))
57-
.toBlueprint()
5857
.simulate()
5958
}
6059
}

0 commit comments

Comments
 (0)