Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,44 @@ import com.lambda.util.extension.containerSlots
import com.lambda.util.text.buildText
import com.lambda.util.text.highlighted
import com.lambda.util.text.literal
import net.minecraft.block.entity.ChestBlockEntity
import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.LockableContainerBlockEntity
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot
import net.minecraft.util.math.BlockPos

data class ChestContainer(
override var stacks: List<ItemStack>,
val blockPos: BlockPos,
val containedInStash: StashContainer? = null
override var stacks: List<ItemStack>,
val blockPos: BlockPos,
val containedInStash: StashContainer? = null
) : MaterialContainer(Rank.Chest), ExternalContainer {
context(safeContext: SafeContext)
override val slots
get(): List<Slot> =
if (ContainerManager.lastInteractedBlockEntity is ChestBlockEntity)
safeContext.player.currentScreenHandler.containerSlots
else emptyList()
context(safeContext: SafeContext)
override val slots
get(): List<Slot> =
if (isContainerLike(ContainerManager.lastInteractedBlockEntity))
safeContext.player.currentScreenHandler.containerSlots
else emptyList()

override val description =
buildText {
literal("Chest at ")
highlighted(blockPos.toShortString())
containedInStash?.let { stash ->
literal(" (contained in ")
highlighted(stash.name)
literal(")")
}
}
override val description =
buildText {
literal("Chest at ")
highlighted(blockPos.toShortString())
containedInStash?.let { stash ->
literal(" (contained in ")
highlighted(stash.name)
literal(")")
}
}

context(automatedSafeContext: AutomatedSafeContext)
override fun accessThen(exitAfter: Boolean, taskGenerator: TaskGenerator<Unit>): Task<*> =
OpenContainerTask(blockPos, automatedSafeContext).then {
taskGenerator.invoke(automatedSafeContext, Unit).finally {
if (exitAfter) automatedSafeContext.player.closeScreen()
}
}
context(automatedSafeContext: AutomatedSafeContext)
override fun accessThen(exitAfter: Boolean, taskGenerator: TaskGenerator<Unit>): Task<*> =
OpenContainerTask(blockPos, automatedSafeContext).then {
taskGenerator.invoke(automatedSafeContext, Unit).finally {
if (exitAfter) automatedSafeContext.player.closeScreen()
}
}

companion object {
fun isContainerLike(blockEntity: BlockEntity?) = blockEntity is LockableContainerBlockEntity
}
}