Skip to content

Commit d4a40de

Browse files
committed
Rename ChestContainer to LootableContainer and accept all types of containers
# Conflicts: # src/main/kotlin/com/lambda/interaction/material/container/containers/LootableContainer.kt
1 parent ffafb42 commit d4a40de

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

src/main/kotlin/com/lambda/interaction/material/container/ContainerManager.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ import com.lambda.event.listener.SafeListener.Companion.listen
2626
import com.lambda.interaction.material.ContainerSelection
2727
import com.lambda.interaction.material.StackSelection
2828
import com.lambda.interaction.material.StackSelection.Companion.select
29-
import com.lambda.interaction.material.container.containers.ChestContainer
29+
import com.lambda.interaction.material.container.containers.LootableContainer
3030
import com.lambda.interaction.material.container.containers.EnderChestContainer
3131
import com.lambda.util.BlockUtils.blockEntity
3232
import com.lambda.util.extension.containerStacks
3333
import com.lambda.util.reflections.getInstances
3434
import net.minecraft.block.entity.BlockEntity
35-
import net.minecraft.block.entity.ChestBlockEntity
3635
import net.minecraft.block.entity.EnderChestBlockEntity
36+
import net.minecraft.block.entity.LootableContainerBlockEntity
3737
import net.minecraft.screen.GenericContainerScreenHandler
3838
import net.minecraft.screen.ScreenHandlerType
3939
import net.minecraft.screen.slot.Slot
@@ -67,16 +67,14 @@ object ContainerManager : Loadable {
6767
EnderChestContainer.update(handler.containerStacks)
6868
}
6969

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

7573
containers
76-
.filterIsInstance<ChestContainer>()
74+
.filterIsInstance<LootableContainer>()
7775
.find {
7876
it.blockPos == block.pos
79-
}?.update(stacks) ?: runtimeContainers.add(ChestContainer(stacks, block.pos))
77+
}?.update(stacks) ?: runtimeContainers.add(LootableContainer(stacks, block.pos))
8078
}
8179
}
8280
lastInteractedBlockEntity = null

src/main/kotlin/com/lambda/interaction/material/container/containers/ChestContainer.kt renamed to src/main/kotlin/com/lambda/interaction/material/container/containers/LootableContainer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@ import com.lambda.util.extension.containerSlots
2929
import com.lambda.util.text.buildText
3030
import com.lambda.util.text.highlighted
3131
import com.lambda.util.text.literal
32-
import net.minecraft.block.entity.ChestBlockEntity
32+
import net.minecraft.block.entity.LootableContainerBlockEntity
3333
import net.minecraft.item.ItemStack
3434
import net.minecraft.screen.slot.Slot
3535
import net.minecraft.util.math.BlockPos
3636

37-
data class ChestContainer(
37+
data class LootableContainer(
3838
override var stacks: List<ItemStack>,
3939
val blockPos: BlockPos,
4040
val containedInStash: StashContainer? = null
4141
) : MaterialContainer(Rank.Chest), ExternalContainer {
4242
context(safeContext: SafeContext)
4343
override val slots
4444
get(): List<Slot> =
45-
if (ContainerManager.lastInteractedBlockEntity is ChestBlockEntity)
45+
if (ContainerManager.lastInteractedBlockEntity is LootableContainerBlockEntity)
4646
safeContext.player.currentScreenHandler.containerSlots
4747
else emptyList()
4848

4949
override val description =
5050
buildText {
51-
literal("Chest at ")
51+
literal("Container at ")
5252
highlighted(blockPos.toShortString())
5353
containedInStash?.let { stash ->
5454
literal(" (contained in ")

src/main/kotlin/com/lambda/interaction/material/container/containers/StashContainer.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ import net.minecraft.screen.slot.Slot
2929
import net.minecraft.util.math.Box
3030

3131
data class StashContainer(
32-
val chests: Set<ChestContainer>,
32+
val container: Set<LootableContainer>,
3333
val pos: Box,
3434
) : MaterialContainer(Rank.Stash) {
3535
context(_: SafeContext)
3636
override val slots: List<Slot>
37-
get() = chests.flatMap { it.slots }
37+
get() = container.flatMap { it.slots }
3838
override var stacks: List<ItemStack>
39-
get() = chests.flatMap { it.stacks }
39+
get() = container.flatMap { it.stacks }
4040
set(_) {}
4141

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

4747
context(_: SafeContext)
4848
override fun materialAvailable(selection: StackSelection): Int =
49-
chests.sumOf {
49+
container.sumOf {
5050
it.materialAvailable(selection)
5151
}
5252
}

0 commit comments

Comments
 (0)