Skip to content

Commit 258ed6c

Browse files
committed
Exhausting interactable block prevention
1 parent f799fc7 commit 258ed6c

File tree

10 files changed

+149
-240
lines changed

10 files changed

+149
-240
lines changed

common/src/main/kotlin/com/lambda/interaction/construction/result/BuildResult.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ abstract class BuildResult : ComparableResult<Rank>, Nameable {
242242
override val pausesParent get() = true
243243

244244
override fun resolve() =
245-
neededStack.select().transfer(MainHandContainer, inventory) ?: MaterialContainer.FailureTask("Couldn't find ${neededStack.item.name.string} anywhere.")
245+
neededStack.select()
246+
.transfer(MainHandContainer, inventory) ?: MaterialContainer.FailureTask("Couldn't find ${neededStack.item.name.string} anywhere.")
246247

247248
override fun SafeContext.buildRenderer() {
248249
if (blockPos.blockState(world).isAir) {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ object BuildSimulator {
279279

280280
val blockHit = checkedResult.blockResult ?: return@forEach
281281
val hitBlock = blockHit.blockPos.blockState(world).block
282-
val shouldSneak = hitBlock in BlockUtils.interactionBlacklist
282+
val shouldSneak = hitBlock::class in BlockUtils.interactionClasses
283283

284284
val primeDirection =
285285
(target as? TargetState.State)?.blockState?.getOrEmpty(Properties.HORIZONTAL_FACING)?.getOrNull()
@@ -440,9 +440,7 @@ object BuildSimulator {
440440
val blockHit = checkedHit.hit.blockResult ?: return@let
441441

442442
val breakContext = BreakContext(
443-
eye, blockHit, RotationRequest(
444-
lookAtBlock(blockHit.blockPos, config = interact), rotation
445-
), state, player.activeHand, instantBreakable(state, pos)
443+
eye, blockHit, RotationRequest(lookAt(checkedHit.targetRotation, 0.001), rotation), state, player.activeHand, instantBreakable(state, pos)
446444
)
447445

448446
/* player has a better tool for the job available */

common/src/main/kotlin/com/lambda/interaction/material/transfer/SlotTransfer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ class SlotTransfer @Ta5kBuilder constructor(
7373

7474
transfer {
7575
// moveSlot(nextFrom.id, nextTo.id)
76-
swap(nextTo.id, 0)
77-
swap(nextFrom.id, 0)
76+
swap(nextTo.id, 1)
77+
swap(nextFrom.id, 1)
7878
}.finally { change ->
7979
changes merge change
8080
}.execute(this@SlotTransfer)

common/src/main/kotlin/com/lambda/interaction/material/transfer/transaction/ClickSlotTransaction.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717

1818
package com.lambda.interaction.material.transfer.transaction
1919

20-
import com.lambda.context.SafeContext
2120
import com.lambda.event.events.TickEvent
2221
import com.lambda.event.listener.SafeListener.Companion.listen
23-
import com.lambda.interaction.material.transfer.InventoryChanges
2422
import com.lambda.interaction.material.transfer.InventoryTransaction
2523
import com.lambda.util.player.SlotUtils.clickSlot
2624
import net.minecraft.screen.slot.SlotActionType
@@ -32,10 +30,10 @@ class ClickSlotTransaction @Ta5kBuilder constructor(
3230
) : InventoryTransaction() {
3331
override val name: String get() = "Click slot #$slotId with action $actionType and button $button"
3432

35-
override fun SafeContext.onStart() {
36-
changes = InventoryChanges(player.currentScreenHandler.slots)
37-
clickSlot(slotId, button, actionType)
38-
changes.detectChanges()
39-
success(changes)
33+
init {
34+
listen<TickEvent.Pre> {
35+
clickSlot(slotId, button, actionType)
36+
finish()
37+
}
4038
}
4139
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.lambda.interaction.construction.verify.ScanMode
2323
import com.lambda.interaction.construction.verify.SurfaceScan
2424
import com.lambda.interaction.request.rotation.*
2525
import com.lambda.interaction.request.rotation.Rotation.Companion.rotationTo
26+
import com.lambda.module.modules.client.TaskFlowModule
2627
import com.lambda.util.extension.component6
2728
import com.lambda.util.math.distSq
2829
import com.lambda.util.world.raycast.InteractionMask
@@ -170,7 +171,7 @@ object VisibilityChecker {
170171
) {
171172
excludedSides.forEach { side ->
172173
if (excludedSides.isNotEmpty() && side !in excludedSides) return@forEach
173-
val (minX, minY, minZ, maxX, maxY, maxZ) = box.contract(1.0E-3).bounds(side)
174+
val (minX, minY, minZ, maxX, maxY, maxZ) = box.contract(TaskFlowModule.shrinkFactor).bounds(side)
174175
val stepX = (maxX - minX) / resolution
175176
val stepY = (maxY - minY) / resolution
176177
val stepZ = (maxZ - minZ) / resolution

common/src/main/kotlin/com/lambda/module/modules/client/TaskFlowModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ object TaskFlowModule : Module(
4141
val inventory = InventorySettings(this) { page == Page.Inventory }
4242

4343
val showAllEntries by setting("Show All Entries", false, "Show all entries in the task tree") { page == Page.Debug }
44+
val shrinkFactor by setting("Shrink Factor", 0.001, 0.0..1.0, 0.001) { page == Page.Debug }
4445

4546
@Volatile
4647
var drawables = listOf<Drawable>()

common/src/main/kotlin/com/lambda/task/Task.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.lambda.threading.runSafe
2828
import com.lambda.util.Communication.logError
2929
import com.lambda.util.Nameable
3030
import com.lambda.util.StringUtils.capitalize
31+
import kotlin.time.Duration.Companion.milliseconds
3132
import kotlin.time.DurationUnit
3233
import kotlin.time.toDuration
3334

@@ -315,7 +316,7 @@ abstract class Task<Result> : Nameable, Muteable {
315316

316317
private fun StringBuilder.appendTaskTree(task: Task<*>, level: Int = 0, maxEntries: Int = 10) {
317318
if (task.state == State.CANCELLED) return
318-
appendLine("${" ".repeat(level * 4)}${task.name}" + if (task !is RootTask) " [${task.state.display}] ${task.duration}" else "")
319+
appendLine("${" ".repeat(level * 4)}${task.name}" + if (task !is RootTask) " [${task.state.display}] ${(task.age * 50).milliseconds}" else "")
319320
val left = task.subTasks.size - maxEntries
320321
if (left > 0) {
321322
appendLine("${" ".repeat((level + 1) * 4)}...and $left more tasks")

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import com.lambda.util.BaritoneUtils
5050
import com.lambda.util.BlockUtils
5151
import com.lambda.util.BlockUtils.blockState
5252
import com.lambda.util.Communication.info
53+
import com.lambda.util.Communication.warn
5354
import com.lambda.util.Formatting.string
5455
import com.lambda.util.collections.LimitedDecayQueue
5556
import com.lambda.util.extension.Structure
@@ -88,8 +89,9 @@ class BuildTask @Ta5kBuilder constructor(
8889
init {
8990
listen<TickEvent.Pre> {
9091
currentInteraction?.let { context ->
91-
// TaskFlowModule.drawables = listOf(context)
92+
TaskFlowModule.drawables = listOf(context)
9293
if (context.shouldRotate(build) && !context.rotation.done) return@let
94+
if (context is PlaceContext && context.sneak && !player.isSneaking) return@let
9395
context.interact(interact.swingHand)
9496
}
9597
instantBreaks.forEach { context ->
@@ -143,8 +145,8 @@ class BuildTask @Ta5kBuilder constructor(
143145
// ToDo: Simulate for each pair player positions that work
144146
val results = blueprint.simulate(player.eyePos, interact, rotation, inventory, build)
145147

146-
TaskFlowModule.drawables = results.filterIsInstance<Drawable>()
147-
.plus(pendingInteractions.toList())
148+
// TaskFlowModule.drawables = results.filterIsInstance<Drawable>()
149+
// .plus(pendingInteractions.toList())
148150
// .plus(sim.goodPositions())
149151

150152
if (build.breaksPerTick > 1) {
@@ -179,7 +181,8 @@ class BuildTask @Ta5kBuilder constructor(
179181
is BuildResult.NotVisible,
180182
is PlaceResult.NoIntegrity -> {
181183
if (!build.pathing) return@onRotate
182-
val goal = BuildGoal(blueprint.simulation(interact, rotation, inventory, build), player.blockPos)
184+
val sim = blueprint.simulation(interact, rotation, inventory, build)
185+
val goal = BuildGoal(sim, player.blockPos)
183186
BaritoneUtils.setGoalAndPath(goal)
184187
}
185188

@@ -209,10 +212,7 @@ class BuildTask @Ta5kBuilder constructor(
209212
listen<MovementEvent.InputUpdate> {
210213
val context = currentInteraction ?: return@listen
211214
if (context !is PlaceContext) return@listen
212-
val hitBlock = context.result.blockPos.blockState(world).block
213-
if (hitBlock in BlockUtils.interactionBlacklist) {
214-
it.input.sneaking = true
215-
}
215+
if (context.sneak) it.input.sneaking = true
216216
}
217217

218218
listen<WorldEvent.BlockUpdate.Client> { event ->
@@ -225,7 +225,10 @@ class BuildTask @Ta5kBuilder constructor(
225225
listen<WorldEvent.BlockUpdate.Server>(alwaysListen = true) { event ->
226226
pendingInteractions.firstOrNull { it.expectedPos == event.pos }?.let { context ->
227227
pendingInteractions.remove(context)
228-
if (!context.targetState.matches(event.newState, event.pos, world)) return@let
228+
if (!context.targetState.matches(event.newState, event.pos, world)) {
229+
this@BuildTask.warn("Update at ${event.pos.toShortString()} was rejected with ${event.newState} instead of ${context.targetState}")
230+
return@let
231+
}
229232
when (context) {
230233
is BreakContext -> breaks++
231234
is PlaceContext -> placements++

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

Lines changed: 0 additions & 181 deletions
This file was deleted.

0 commit comments

Comments
 (0)