Skip to content
Open
Show file tree
Hide file tree
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 @@ -26,14 +26,14 @@ import com.lambda.event.listener.SafeListener.Companion.listen
import com.lambda.interaction.material.ContainerSelection
import com.lambda.interaction.material.StackSelection
import com.lambda.interaction.material.StackSelection.Companion.select
import com.lambda.interaction.material.container.containers.ChestContainer
import com.lambda.interaction.material.container.containers.LootableContainer
import com.lambda.interaction.material.container.containers.EnderChestContainer
import com.lambda.util.BlockUtils.blockEntity
import com.lambda.util.extension.containerStacks
import com.lambda.util.reflections.getInstances
import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.ChestBlockEntity
import net.minecraft.block.entity.EnderChestBlockEntity
import net.minecraft.block.entity.LootableContainerBlockEntity
import net.minecraft.screen.GenericContainerScreenHandler
import net.minecraft.screen.ScreenHandlerType
import net.minecraft.screen.slot.Slot
Expand Down Expand Up @@ -67,16 +67,14 @@ object ContainerManager : Loadable {
EnderChestContainer.update(handler.containerStacks)
}

is ChestBlockEntity -> {
// ToDo: Handle double chests and single chests
if (handler.type != ScreenHandlerType.GENERIC_9X6) return@listen
is LootableContainerBlockEntity -> {
val stacks = handler.containerStacks

containers
.filterIsInstance<ChestContainer>()
.filterIsInstance<LootableContainer>()
.find {
it.blockPos == block.pos
}?.update(stacks) ?: runtimeContainers.add(ChestContainer(stacks, block.pos))
}?.update(stacks) ?: runtimeContainers.add(LootableContainer(stacks, block.pos))
}
}
lastInteractedBlockEntity = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ 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.LootableContainerBlockEntity
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot
import net.minecraft.util.math.BlockPos

data class ChestContainer(
data class LootableContainer(
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)
if (ContainerManager.lastInteractedBlockEntity is LootableContainerBlockEntity)
safeContext.player.currentScreenHandler.containerSlots
else emptyList()

override val description =
buildText {
literal("Chest at ")
literal("Container at ")
highlighted(blockPos.toShortString())
containedInStash?.let { stash ->
literal(" (contained in ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import net.minecraft.screen.slot.Slot
import net.minecraft.util.math.Box

data class StashContainer(
val chests: Set<ChestContainer>,
val container: Set<LootableContainer>,
val pos: Box,
) : MaterialContainer(Rank.Stash) {
context(_: SafeContext)
override val slots: List<Slot>
get() = chests.flatMap { it.slots }
get() = container.flatMap { it.slots }
override var stacks: List<ItemStack>
get() = chests.flatMap { it.stacks }
get() = container.flatMap { it.stacks }
set(_) {}

override val description = buildText {
Expand All @@ -46,7 +46,7 @@ data class StashContainer(

context(_: SafeContext)
override fun materialAvailable(selection: StackSelection): Int =
chests.sumOf {
container.sumOf {
it.materialAvailable(selection)
}
}