@@ -22,6 +22,7 @@ import com.lambda.config.groups.InteractionConfig
2222import com.lambda.context.SafeContext
2323import com.lambda.interaction.construction.blueprint.Blueprint.Companion.toStructure
2424import com.lambda.interaction.construction.blueprint.StaticBlueprint.Companion.toBlueprint
25+ import com.lambda.interaction.construction.blueprint.TickingBlueprint.Companion.tickingBlueprint
2526import com.lambda.interaction.construction.result.BuildResult
2627import com.lambda.interaction.construction.result.PlaceResult
2728import com.lambda.interaction.construction.simulation.BuildSimulator.simulate
@@ -32,6 +33,7 @@ import com.lambda.module.modules.client.TaskFlowModule
3233import com.lambda.task.Task
3334import com.lambda.task.tasks.BuildTask.Companion.build
3435import com.lambda.util.BlockUtils.blockPos
36+ import com.lambda.util.BlockUtils.blockState
3537import com.lambda.util.item.ItemUtils.shulkerBoxes
3638import net.minecraft.block.ChestBlock
3739import net.minecraft.entity.mob.ShulkerEntity
@@ -51,39 +53,46 @@ class PlaceContainer @Ta5kBuilder constructor(
5153 override val name: String get() = " Placing container ${startStack.name.string} "
5254
5355 override fun SafeContext.onStart () {
54- val results = BlockPos .iterateOutwards(player.blockPos, 4 , 3 , 4 )
55- .map { it.blockPos }
56- .flatMap {
57- it.blockPos
58- .toStructure(TargetState .Stack (startStack))
59- .toBlueprint()
60- .simulate(player.eyePos)
56+ tickingBlueprint { current ->
57+ if (current.isNotEmpty() &&
58+ current.all { it.value.matches(blockState(it.key), it.key, world) })
59+ {
60+ return @tickingBlueprint current
6161 }
6262
63- // ToDo: Check based on if we can move the player close enough rather than y level once the custom pathfinder is merged
64- val succeeds = results.filterIsInstance<PlaceResult .Place >().filter {
65- canBeOpened(startStack, it.blockPos, it.context.result.side) && it.blockPos.y == player.blockPos.y
66- }
67- val wrongStacks = results.filterIsInstance<BuildResult .WrongItemSelection >().filter {
68- canBeOpened(startStack, it.blockPos, it.context.result.side) && it.blockPos.y == player.blockPos.y
69- }
70- (succeeds + wrongStacks).minOrNull()?.let { result ->
71- build(
72- build = build,
73- rotation = rotation,
74- interact = interact,
75- inventory = inventory,
76- ) {
77- result.blockPos
78- .toStructure(TargetState .Stack (startStack))
79- .toBlueprint()
80- }.finally {
81- success(result.blockPos)
82- }.execute(this @PlaceContainer)
83- return
84- }
63+ val results = BlockPos .iterateOutwards(player.blockPos, 4 , 3 , 4 )
64+ .map { it.blockPos }
65+ .flatMap {
66+ it.blockPos
67+ .toStructure(TargetState .Stack (startStack))
68+ .toBlueprint()
69+ .simulate(player.eyePos)
70+ }
8571
86- failure(" No valid placement found" )
72+ // ToDo: Check based on if we can move the player close enough rather than y level once the custom pathfinder is merged
73+ val succeeds = results.filterIsInstance<PlaceResult .Place >().filter {
74+ canBeOpened(startStack, it.blockPos, it.context.result.side) && it.blockPos.y == player.blockPos.y
75+ }
76+ val wrongStacks = results.filterIsInstance<BuildResult .WrongItemSelection >().filter {
77+ canBeOpened(startStack, it.blockPos, it.context.result.side) && it.blockPos.y == player.blockPos.y
78+ }
79+ (succeeds + wrongStacks).minOrNull()
80+ ?.blockPos
81+ ?.toStructure(TargetState .Stack (startStack))
82+ }.build(
83+ true ,
84+ false ,
85+ build = build,
86+ rotation = rotation,
87+ interact = interact,
88+ inventory = inventory
89+ ).finally {
90+ val pos = it.keys.firstOrNull() ? : run {
91+ failure(" The returned structure was empty" )
92+ return @finally
93+ }
94+ success(pos)
95+ }.execute(this @PlaceContainer)
8796 }
8897
8998 private fun SafeContext.canBeOpened (
0 commit comments