Skip to content

Commit ea817fc

Browse files
committed
Fix shulker container placement
1 parent 016b1d7 commit ea817fc

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ object ManagerUtils {
3535
fun Event.toLogContext() = this::class.qualifiedName?.substringAfter("com.lambda.event.events.")
3636

3737
fun isPosBlocked(pos: BlockPos) =
38-
positionBlockingManagers.any { manager -> manager.blockedPositions.any { blocked -> blocked == pos } }
38+
positionBlockingManagers.any { pos in it.blockedPositions }
3939
}

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

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import com.lambda.interaction.request.rotating.RotationConfig
3333
import com.lambda.module.modules.client.TaskFlowModule
3434
import com.lambda.task.Task
3535
import com.lambda.task.tasks.BuildTask.Companion.build
36+
import com.lambda.util.BlockUtils.blockPos
3637
import com.lambda.util.BlockUtils.blockState
3738
import com.lambda.util.item.ItemUtils.shulkerBoxes
3839
import 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

Comments
 (0)