@@ -33,6 +33,7 @@ import com.lambda.interaction.request.rotating.RotationConfig
3333import com.lambda.module.modules.client.TaskFlowModule
3434import com.lambda.task.Task
3535import com.lambda.task.tasks.BuildTask.Companion.build
36+ import com.lambda.util.BlockUtils.blockPos
3637import com.lambda.util.BlockUtils.blockState
3738import com.lambda.util.item.ItemUtils.shulkerBoxes
3839import net.minecraft.block.ChestBlock
@@ -53,44 +54,40 @@ class PlaceContainer @Ta5kBuilder constructor(
5354 override val name: String get() = " Placing container ${startStack.name.string} "
5455
5556 override fun SafeContext.onStart () {
56- tickingBlueprint { current ->
57- if (current.isNotEmpty() &&
58- (current.all { it.value.matches(blockState(it.key), it.key, world) } ||
59- ManagerUtils .positionBlockingManagers.any { it.blockedPositions.isNotEmpty() }))
60- {
61- return @tickingBlueprint current
57+ val results = BlockPos .iterateOutwards(player.blockPos, 4 , 3 , 4 )
58+ .map { it.blockPos }
59+ .asSequence()
60+ .filter { ! ManagerUtils .isPosBlocked(it) }
61+ .flatMap {
62+ it.toStructure(TargetState .Stack (startStack))
63+ .toBlueprint()
64+ .simulate(player.eyePos)
6265 }
6366
64- val results = BlockPos .iterateOutwards( player.blockPos, 4 , 3 , 4 )
65- .flatMap {
66- it.toStructure( TargetState . Stack (startStack))
67- .toBlueprint()
68- .simulate(player.eyePos)
69- }
70-
71- // ToDo: Check based on if we can move the player close enough rather than y level once the custom pathfinder is merged
72- val succeeds = results.filterIsInstance< PlaceResult . Place >().filter {
73- canBeOpened(startStack, it.blockPos, it.context.result.side) && it.blockPos.y == player.blockPos.y
74- }
75- val wrongStacks = results.filterIsInstance< BuildResult . WrongItemSelection >().filter {
76- canBeOpened(startStack, it.blockPos, it.context.result.side) && it.blockPos.y == player.blockPos.y
67+ // ToDo: Check based on if we can move the player close enough rather than y level once the custom pathfinder is merged
68+ val succeeds = results.filterIsInstance< PlaceResult . Place >().filter {
69+ canBeOpened(startStack, it.blockPos, it.context.result.side) && it.blockPos.y == player.blockPos.y
70+ }
71+ val wrongStacks = results.filterIsInstance< BuildResult . WrongItemSelection >().filter {
72+ canBeOpened(startStack, it.blockPos, it.context.result.side) && it.blockPos.y == player.blockPos.y
73+ }
74+ val containerPosition = (succeeds + wrongStacks).minOrNull()?.blockPos
75+ val structure = containerPosition
76+ ?.toStructure( TargetState . Stack (startStack))
77+ ?.toBlueprint() ? : run {
78+ failure( " Couldn't find a valid container position " )
79+ return @onStart
7780 }
78- (succeeds + wrongStacks).minOrNull()
79- ?.blockPos
80- ?.toStructure(TargetState .Stack (startStack))
81- }.build(
81+
82+ structure.build(
8283 finishOnDone = true ,
8384 collectDrops = false ,
8485 build = build,
8586 rotation = rotation,
8687 interact = interact,
8788 inventory = inventory
8889 ).finally {
89- val pos = it.keys.firstOrNull() ? : run {
90- failure(" The returned structure was empty" )
91- return @finally
92- }
93- success(pos)
90+ success(containerPosition)
9491 }.execute(this @PlaceContainer)
9592 }
9693
0 commit comments