Skip to content

Commit 1983957

Browse files
committed
Reworked container placement code
1 parent ea817fc commit 1983957

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

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

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,32 @@ class PlaceContainer @Ta5kBuilder constructor(
6464
.simulate(player.eyePos)
6565
}
6666

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
67+
val options = results.filterIsInstance<PlaceResult.Place>().filter {
68+
canBeOpened(startStack, it.blockPos, it.context.result.side)
69+
} + results.filterIsInstance<BuildResult.WrongItemSelection>().filter {
70+
canBeOpened(startStack, it.blockPos, it.context.result.side)
7071
}
71-
val wrongStacks = results.filterIsInstance<BuildResult.WrongItemSelection>().filter {
72-
canBeOpened(startStack, it.blockPos, it.context.result.side) && it.blockPos.y == player.blockPos.y
72+
val containerPosition = options.filter {
73+
// ToDo: Check based on if we can move the player close enough rather than y level once the custom pathfinder is merged
74+
it.blockPos.y == player.blockPos.y
75+
}.minOrNull()?.blockPos ?: run {
76+
failure("Couldn't find a valid container placement position for ${startStack.name.string}")
77+
return@onStart
7378
}
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
80-
}
8179

82-
structure.build(
83-
finishOnDone = true,
84-
collectDrops = false,
85-
build = build,
86-
rotation = rotation,
87-
interact = interact,
88-
inventory = inventory
89-
).finally {
90-
success(containerPosition)
91-
}.execute(this@PlaceContainer)
80+
containerPosition
81+
.toStructure(TargetState.Stack(startStack))
82+
.toBlueprint()
83+
.build(
84+
finishOnDone = true,
85+
collectDrops = false,
86+
build = build,
87+
rotation = rotation,
88+
interact = interact,
89+
inventory = inventory
90+
).finally {
91+
success(containerPosition)
92+
}.execute(this@PlaceContainer)
9293
}
9394

9495
private fun SafeContext.canBeOpened(
@@ -99,7 +100,6 @@ class PlaceContainer @Ta5kBuilder constructor(
99100
Items.ENDER_CHEST -> {
100101
!ChestBlock.isChestBlocked(world, blockPos)
101102
}
102-
103103
in shulkerBoxes -> {
104104
val box = ShulkerEntity
105105
.calculateBoundingBox(0.5f, direction, 0.0f, blockPos.toBottomCenterPos())
@@ -108,7 +108,6 @@ class PlaceContainer @Ta5kBuilder constructor(
108108

109109
world.isSpaceEmpty(box)
110110
}
111-
112111
else -> false
113112
}
114113
}

0 commit comments

Comments
 (0)