diff --git a/src/main/kotlin/com/lambda/interaction/material/container/ContainerManager.kt b/src/main/kotlin/com/lambda/interaction/material/container/ContainerManager.kt index d5e60cc91..18656b13b 100644 --- a/src/main/kotlin/com/lambda/interaction/material/container/ContainerManager.kt +++ b/src/main/kotlin/com/lambda/interaction/material/container/ContainerManager.kt @@ -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 @@ -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() + .filterIsInstance() .find { it.blockPos == block.pos - }?.update(stacks) ?: runtimeContainers.add(ChestContainer(stacks, block.pos)) + }?.update(stacks) ?: runtimeContainers.add(LootableContainer(stacks, block.pos)) } } lastInteractedBlockEntity = null diff --git a/src/main/kotlin/com/lambda/interaction/material/container/containers/ChestContainer.kt b/src/main/kotlin/com/lambda/interaction/material/container/containers/LootableContainer.kt similarity index 91% rename from src/main/kotlin/com/lambda/interaction/material/container/containers/ChestContainer.kt rename to src/main/kotlin/com/lambda/interaction/material/container/containers/LootableContainer.kt index 3c6543b71..4c48c9bef 100644 --- a/src/main/kotlin/com/lambda/interaction/material/container/containers/ChestContainer.kt +++ b/src/main/kotlin/com/lambda/interaction/material/container/containers/LootableContainer.kt @@ -29,12 +29,12 @@ 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, val blockPos: BlockPos, val containedInStash: StashContainer? = null @@ -42,13 +42,13 @@ data class ChestContainer( context(safeContext: SafeContext) override val slots get(): List = - 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 ") diff --git a/src/main/kotlin/com/lambda/interaction/material/container/containers/StashContainer.kt b/src/main/kotlin/com/lambda/interaction/material/container/containers/StashContainer.kt index e84b3ce4d..8ca24d9d9 100644 --- a/src/main/kotlin/com/lambda/interaction/material/container/containers/StashContainer.kt +++ b/src/main/kotlin/com/lambda/interaction/material/container/containers/StashContainer.kt @@ -29,14 +29,14 @@ import net.minecraft.screen.slot.Slot import net.minecraft.util.math.Box data class StashContainer( - val chests: Set, + val container: Set, val pos: Box, ) : MaterialContainer(Rank.Stash) { context(_: SafeContext) override val slots: List - get() = chests.flatMap { it.slots } + get() = container.flatMap { it.slots } override var stacks: List - get() = chests.flatMap { it.stacks } + get() = container.flatMap { it.stacks } set(_) {} override val description = buildText { @@ -46,7 +46,7 @@ data class StashContainer( context(_: SafeContext) override fun materialAvailable(selection: StackSelection): Int = - chests.sumOf { + container.sumOf { it.materialAvailable(selection) } }