From b808a6aea1ba28ffd10712e7586b6f0d6cc1804a Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal002@users.noreply.github.com> Date: Tue, 12 Mar 2024 18:04:56 +0100 Subject: Internal Change: Code cleanup ContainerChest getAllItems (#1047) Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../at/hannibal2/skyhanni/utils/InventoryUtils.kt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (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 c0b5e04df..3566761b2 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt @@ -80,4 +80,26 @@ object InventoryUtils { countItemsInLowerInventory { it.getInternalNameOrNull() == name } fun isItemInInventory(name: NEUInternalName) = getAmountOfItemInInventory(name) > 0 + + fun ContainerChest.getUpperItems(): Map = buildMap { + for ((slot, stack) in getAllItems()) { + if (slot.slotNumber != slot.slotIndex) continue + this[slot] = stack + } + } + + fun ContainerChest.getLowerItems(): Map = buildMap { + for ((slot, stack) in getAllItems()) { + if (slot.slotNumber == slot.slotIndex) continue + this[slot] = stack + } + } + + fun ContainerChest.getAllItems(): Map = buildMap { + for (slot in inventorySlots) { + if (slot == null) continue + val stack = slot.stack ?: continue + this[slot] = stack + } + } } -- cgit