Skip to content

Commit ebd0d3e

Browse files
committed
max dependency depth and reintroduce blocked by player build result
1 parent 6d09f1e commit ebd0d3e

File tree

7 files changed

+37
-15
lines changed

7 files changed

+37
-15
lines changed

src/main/kotlin/com/lambda/context/AutomationConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ object AutomationConfig : Configurable(LambdaConfig), Automated {
6262
val showAllEntries by setting("Show All Entries", false, "Show all entries in the task tree").group(Group.Debug)
6363
val shrinkFactor by setting("Shrink Factor", 0.001, 0.0..1.0, 0.001).group(Group.Debug)
6464
val ignoreItemDropWarnings by setting("Ignore Drop Warnings", false, "Hides the item drop warnings from the break manager").group(Group.Debug)
65+
val maxSimDependencies by setting("Max Sim Dependencies", 10, 0..25, 1, "Maximum dependency build results").group(Group.Debug)
6566

6667
@Volatile
6768
var drawables = listOf<Drawable>()

src/main/kotlin/com/lambda/interaction/construction/result/results/PlaceResult.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import baritone.api.pathing.goals.GoalInverted
2222
import com.lambda.context.Automated
2323
import com.lambda.graphics.renderer.esp.ShapeBuilder
2424
import com.lambda.interaction.construction.context.PlaceContext
25-
import com.lambda.interaction.construction.verify.TargetState
26-
import com.lambda.task.Task
2725
import com.lambda.interaction.construction.result.BuildResult
2826
import com.lambda.interaction.construction.result.ComparableResult
2927
import com.lambda.interaction.construction.result.Contextual
@@ -33,7 +31,6 @@ import com.lambda.interaction.construction.result.Navigable
3331
import com.lambda.interaction.construction.result.Rank
3432
import com.lambda.interaction.construction.result.Resolvable
3533
import com.lambda.task.tasks.BuildTask.Companion.breakBlock
36-
import com.lambda.task.tasks.BuildTask.Companion.build
3734
import net.minecraft.block.BlockState
3835
import net.minecraft.entity.Entity
3936
import net.minecraft.item.ItemPlacementContext
@@ -97,6 +94,23 @@ sealed class PlaceResult : BuildResult() {
9794
}
9895
}
9996

97+
/**
98+
* Represents a scenario where block placement is obstructed by the player itself.
99+
*
100+
* @property pos The position of the block that was attempted to be placed.
101+
*/
102+
data class BlockedBySelf(
103+
override val pos: BlockPos
104+
) : Drawable, Navigable, PlaceResult() {
105+
override val rank = Rank.PlaceBlockedByPlayer
106+
private val color = Color(252, 3, 3, 100)
107+
override val goal = GoalInverted(GoalBlock(pos))
108+
109+
override fun ShapeBuilder.buildRenderer() {
110+
box(pos, color, color)
111+
}
112+
}
113+
100114
/**
101115
* Represents a scenario where block placement is obstructed by an entity.
102116
*

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ interface ISimInfo : Automated {
6161
SimInfo(
6262
pos, state, targetState,
6363
targetState.getProcessingInfo(pos) ?: return,
64-
pov, concurrentResults, this
64+
pov, concurrentResults, Stack(), this
6565
).takeIf { it.checkRequirements() }?.sim(null, simBuilder)
6666
}
6767

@@ -77,7 +77,7 @@ interface ISimInfo : Automated {
7777
SimInfo(
7878
pos, state, targetState,
7979
targetState.getProcessingInfo(pos) ?: return,
80-
pov, concurrentResults, this
80+
pov, concurrentResults, dependencyStack, this
8181
).takeIf { it.checkRequirements() }?.sim(dependable, simBuilder)
8282
}
8383

@@ -97,9 +97,10 @@ data class SimInfo(
9797
override val preProcessing: PreProcessingInfo,
9898
override val pov: Vec3d,
9999
override val concurrentResults: MutableSet<BuildResult>,
100+
override val dependencyStack: Stack<Dependable>,
100101
val automated: Automated
101102
) : ISimInfo, Automated by automated {
102-
override val dependencyStack = Stack<Dependable>()
103+
103104
}
104105

105106
class SimBuilder(simInfo: ISimInfo) : ISimInfo by simInfo

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

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

1818
package com.lambda.interaction.construction.simulation
1919

20+
import com.lambda.context.AutomationConfig.maxSimDependencies
2021
import com.lambda.interaction.construction.processing.PreProcessingInfo
2122
import com.lambda.interaction.construction.result.BuildResult
2223
import com.lambda.interaction.construction.result.Dependable
@@ -43,12 +44,14 @@ annotation class SimCheckerDsl
4344

4445
@SimCheckerDsl
4546
abstract class SimChecker<T : BuildResult> {
46-
protected fun ISimInfo.checkDependent(caller: Dependable?) {
47+
protected fun ISimInfo.checkDependent(caller: Dependable?): Boolean {
4748
if (caller == null) {
4849
dependencyStack.clear()
49-
return
50+
return true
5051
}
52+
if (dependencyStack.size >= maxSimDependencies) return false
5153
dependencyStack.push(caller)
54+
return true
5255
}
5356

5457
fun ISimInfo.result(result: GenericResult) = addResult(result)

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/BreakSim.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class BreakSim private constructor(simInfo: ISimInfo)
7878
context(automatedSafeContext: AutomatedSafeContext, dependable: Dependable?)
7979
suspend fun SimBuilder.simBreak() =
8080
BreakSim(this).run {
81-
checkDependent(dependable)
81+
if (!checkDependent(dependable)) return
8282
automatedSafeContext.checkBreaks()
8383
}
8484
}

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/PlaceSim.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class PlaceSim private constructor(simInfo: ISimInfo)
8181
@SimBuilderDsl
8282
suspend fun SimBuilder.simPlacement() =
8383
PlaceSim(this).run {
84-
checkDependent(dependable)
84+
if (!checkDependent(dependable)) return
8585
automatedSafeContext.checkPlacements()
8686
}
8787
}
@@ -251,14 +251,13 @@ class PlaceSim private constructor(simInfo: ISimInfo)
251251
}
252252

253253
private suspend fun AutomatedSafeContext.handleEntityBlockage(context: ItemPlacementContext): List<Entity> {
254+
val pos = context.blockPos
254255
val theoreticalState = context.stack.blockItem.block.getPlacementState(context)
255256
?: return emptyList()
256257

257258
val collisionShape = theoreticalState.getCollisionShape(
258-
world,
259-
context.blockPos,
260-
ShapeContext.ofPlacement(player)
261-
).offset(context.blockPos)
259+
world, pos, ShapeContext.ofPlacement(player)
260+
).offset(pos)
262261

263262
val collidingEntities = collisionShape.boundingBoxes.flatMap { box ->
264263
world.entities.filter { it.boundingBox.intersects(box) }
@@ -267,6 +266,10 @@ class PlaceSim private constructor(simInfo: ISimInfo)
267266
if (collidingEntities.isNotEmpty()) {
268267
collidingEntities
269268
.mapNotNull { entity ->
269+
if (entity === player) {
270+
result(PlaceResult.BlockedBySelf(pos))
271+
return@mapNotNull null
272+
}
270273
val hitbox = entity.boundingBox
271274
entity.getPositionsWithinHitboxXZ(
272275
(pos.y - (hitbox.maxY - hitbox.minY)).floorToInt(),

src/main/kotlin/com/lambda/interaction/construction/simulation/checks/PostProcessingSim.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class PostProcessingSim private constructor(simInfo: ISimInfo)
5757
@SimBuilderDsl
5858
suspend fun SimBuilder.simPostProcessing() =
5959
PostProcessingSim(this).run {
60-
checkDependent(dependable)
60+
if (!checkDependent(dependable)) return
6161
automatedSafeContext.checkPostProcessing()
6262
}
6363
}

0 commit comments

Comments
 (0)