@@ -29,39 +29,44 @@ import com.lambda.util.extension.containerSlots
2929import com.lambda.util.text.buildText
3030import com.lambda.util.text.highlighted
3131import com.lambda.util.text.literal
32- import net.minecraft.block.entity.ChestBlockEntity
32+ import net.minecraft.block.entity.BlockEntity
33+ import net.minecraft.block.entity.LockableContainerBlockEntity
3334import net.minecraft.item.ItemStack
3435import net.minecraft.screen.slot.Slot
3536import net.minecraft.util.math.BlockPos
3637
3738data class ChestContainer (
38- override var stacks : List <ItemStack >,
39- val blockPos : BlockPos ,
40- val containedInStash : StashContainer ? = null
39+ override var stacks : List <ItemStack >,
40+ val blockPos : BlockPos ,
41+ val containedInStash : StashContainer ? = null
4142) : MaterialContainer(Rank .Chest ), ExternalContainer {
42- context(safeContext: SafeContext )
43- override val slots
44- get(): List <Slot > =
45- if (ContainerManager .lastInteractedBlockEntity is ChestBlockEntity )
46- safeContext.player.currentScreenHandler.containerSlots
47- else emptyList()
43+ context(safeContext: SafeContext )
44+ override val slots
45+ get(): List <Slot > =
46+ if (isContainerLike( ContainerManager .lastInteractedBlockEntity) )
47+ safeContext.player.currentScreenHandler.containerSlots
48+ else emptyList()
4849
49- override val description =
50- buildText {
51- literal(" Chest at " )
52- highlighted(blockPos.toShortString())
53- containedInStash?.let { stash ->
54- literal(" (contained in " )
55- highlighted(stash.name)
56- literal(" )" )
57- }
58- }
50+ override val description =
51+ buildText {
52+ literal(" Chest at " )
53+ highlighted(blockPos.toShortString())
54+ containedInStash?.let { stash ->
55+ literal(" (contained in " )
56+ highlighted(stash.name)
57+ literal(" )" )
58+ }
59+ }
5960
60- context(automatedSafeContext: AutomatedSafeContext )
61- override fun accessThen (exitAfter : Boolean , taskGenerator : TaskGenerator <Unit >): Task <* > =
62- OpenContainerTask (blockPos, automatedSafeContext).then {
63- taskGenerator.invoke(automatedSafeContext, Unit ).finally {
64- if (exitAfter) automatedSafeContext.player.closeScreen()
65- }
66- }
61+ context(automatedSafeContext: AutomatedSafeContext )
62+ override fun accessThen (exitAfter : Boolean , taskGenerator : TaskGenerator <Unit >): Task <* > =
63+ OpenContainerTask (blockPos, automatedSafeContext).then {
64+ taskGenerator.invoke(automatedSafeContext, Unit ).finally {
65+ if (exitAfter) automatedSafeContext.player.closeScreen()
66+ }
67+ }
68+
69+ companion object {
70+ fun isContainerLike (blockEntity : BlockEntity ? ) = blockEntity is LockableContainerBlockEntity
71+ }
6772}
0 commit comments