diff options
| author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-07-15 16:57:35 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-15 16:57:35 +0200 |
| commit | 73f2443fc869127db948234a5fe8de277faacfba (patch) | |
| tree | 20644bf9d1d90177cff878eed66a1e24aa0f0ed4 /src/main/java/at/hannibal2/skyhanni/utils | |
| parent | 82f2a2c6ea8c4b552cc5e65e27c397308fcb8989 (diff) | |
| download | skyhanni-73f2443fc869127db948234a5fe8de277faacfba.tar.gz skyhanni-73f2443fc869127db948234a5fe8de277faacfba.tar.bz2 skyhanni-73f2443fc869127db948234a5fe8de277faacfba.zip | |
Improvement: own inventory support for estimate chest value (#2218)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt | 15 |
1 files changed, 10 insertions, 5 deletions
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<Long, NEUInternalName>() var latestItemInHand: ItemStack? = null - fun getItemsInOpenChest() = buildList<Slot> { + fun getItemsInOpenChest(): List<Slot> { val guiChest = Minecraft.getMinecraft().currentScreen as? GuiChest ?: return emptyList<Slot>() - 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<Slot> { + val guiInventory = Minecraft.getMinecraft().currentScreen as? GuiInventory ?: return emptyList<Slot>() + 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 |
