From 73f2443fc869127db948234a5fe8de277faacfba Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Mon, 15 Jul 2024 16:57:35 +0200 Subject: Improvement: own inventory support for estimate chest value (#2218) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../java/at/hannibal2/skyhanni/utils/InventoryUtils.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/utils') diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt index d2c24ceca..76f9fbfcb 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt @@ -6,6 +6,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.client.gui.inventory.GuiContainer +import net.minecraft.client.gui.inventory.GuiInventory import net.minecraft.entity.player.InventoryPlayer import net.minecraft.inventory.ContainerChest import net.minecraft.inventory.Slot @@ -18,12 +19,16 @@ object InventoryUtils { var recentItemsInHand = mutableMapOf() var latestItemInHand: ItemStack? = null - fun getItemsInOpenChest() = buildList { + fun getItemsInOpenChest(): List { val guiChest = Minecraft.getMinecraft().currentScreen as? GuiChest ?: return emptyList() - for (slot in guiChest.inventorySlots.inventorySlots) { - if (slot.inventory is InventoryPlayer) break - if (slot.stack != null) add(slot) - } + return guiChest.inventorySlots.inventorySlots + .filter { it.inventory !is InventoryPlayer && it.stack != null } + } + + fun getSlotsInOwnInventory(): List { + val guiInventory = Minecraft.getMinecraft().currentScreen as? GuiInventory ?: return emptyList() + return guiInventory.inventorySlots.inventorySlots + .filter { it.inventory is InventoryPlayer && it.stack != null } } // TODO add cache that persists until the next gui/window open/close packet is sent/received -- cgit