From c0683e2ee9ff1b599b8afe94c385d47e7c552d7d Mon Sep 17 00:00:00 2001 From: Ic3Tank <61137113+IceTank@users.noreply.github.com> Date: Thu, 2 Apr 2026 21:28:58 +0200 Subject: [PATCH] Fix issue with ChestContainer breaking when the opened gui is not a generic chest block --- .../container/containers/ChestContainer.kt | 59 ++++++++++--------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/material/container/containers/ChestContainer.kt b/src/main/kotlin/com/lambda/interaction/material/container/containers/ChestContainer.kt index 3c6543b71..b56a0aee4 100644 --- a/src/main/kotlin/com/lambda/interaction/material/container/containers/ChestContainer.kt +++ b/src/main/kotlin/com/lambda/interaction/material/container/containers/ChestContainer.kt @@ -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, - val blockPos: BlockPos, - val containedInStash: StashContainer? = null + override var stacks: List, + val blockPos: BlockPos, + val containedInStash: StashContainer? = null ) : MaterialContainer(Rank.Chest), ExternalContainer { - context(safeContext: SafeContext) - override val slots - get(): List = - if (ContainerManager.lastInteractedBlockEntity is ChestBlockEntity) - safeContext.player.currentScreenHandler.containerSlots - else emptyList() + context(safeContext: SafeContext) + override val slots + get(): List = + 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): 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): Task<*> = + OpenContainerTask(blockPos, automatedSafeContext).then { + taskGenerator.invoke(automatedSafeContext, Unit).finally { + if (exitAfter) automatedSafeContext.player.closeScreen() + } + } + + companion object { + fun isContainerLike(blockEntity: BlockEntity?) = blockEntity is LockableContainerBlockEntity + } }