diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-22 20:55:33 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-22 20:55:33 +0200 |
commit | 45c2a9a29f7171a5392ddf03bf9053aaefcfd8d4 (patch) | |
tree | 11c373fd4c4798dfe36bf4b21a2b62dde4d80e48 /src/main/java/at/hannibal2 | |
parent | 1017af091e5e00fecb315cb5c71ae04dd98c35d3 (diff) | |
download | skyhanni-45c2a9a29f7171a5392ddf03bf9053aaefcfd8d4.tar.gz skyhanni-45c2a9a29f7171a5392ddf03bf9053aaefcfd8d4.tar.bz2 skyhanni-45c2a9a29f7171a5392ddf03bf9053aaefcfd8d4.zip |
code cleanup
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt | 50 |
1 files changed, 13 insertions, 37 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt index 4e49f4be2..9edd186d2 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/InventoryUtils.kt @@ -3,23 +3,11 @@ package at.hannibal2.skyhanni.utils import net.minecraft.client.Minecraft import net.minecraft.client.gui.inventory.GuiChest import net.minecraft.inventory.ContainerChest -import net.minecraft.inventory.Slot import net.minecraft.item.ItemStack object InventoryUtils { - //TODO use this method more widely - fun currentlyOpenInventory(): String { - val screen = Minecraft.getMinecraft().currentScreen - if (screen !is GuiChest) return "" - val inventorySlots = screen.inventorySlots - val chest = inventorySlots as ContainerChest - - return chest.getInventoryName() - } - - fun getItemsInOpenChest(): List<Slot> { - val list = mutableListOf<Slot>() + fun getItemsInOpenChest() = buildList { val guiChest = Minecraft.getMinecraft().currentScreen as GuiChest val inventorySlots = guiChest.inventorySlots.inventorySlots val skipAt = inventorySlots.size - 9 * 4 @@ -27,43 +15,31 @@ object InventoryUtils { for (slot in inventorySlots) { val stack = slot.stack if (stack != null) { - list.add(slot) + add(slot) } i++ if (i == skipAt) break } - return list } - fun openInventoryName(): String { - val guiChest = Minecraft.getMinecraft().currentScreen - val chestName = if (guiChest is GuiChest) { - val chest = guiChest.inventorySlots as ContainerChest - chest.getInventoryName() - } else "" - return chestName - } - - fun ContainerChest.getInventoryName() = this.lowerChestInventory.displayName.unformattedText.trim() + fun openInventoryName() = Minecraft.getMinecraft().currentScreen.let { + if (it is GuiChest) { + val chest = it.inventorySlots as ContainerChest + chest.getInventoryName() + } else "" + } - fun getItemsInOwnInventory(): MutableList<ItemStack> { - val list = mutableListOf<ItemStack>() - for (itemStack in Minecraft.getMinecraft().thePlayer.inventory.mainInventory) { - itemStack?.let { - list.add(it) - } - } + fun ContainerChest.getInventoryName() = this.lowerChestInventory.displayName.unformattedText.trim() - return list - } + fun getItemsInOwnInventory() = Minecraft.getMinecraft().thePlayer.inventory.mainInventory.filterNotNull() fun countItemsInLowerInventory(predicate: (ItemStack) -> Boolean) = getItemsInOwnInventory().filter { predicate(it) }.sumOf { it.stackSize } - fun getArmor(): Array<ItemStack?> = - Minecraft.getMinecraft().thePlayer.inventory.armorInventory + fun getArmor(): Array<ItemStack?> = Minecraft.getMinecraft().thePlayer.inventory.armorInventory - fun inStorage() = openInventoryName().let { it.contains("Storage") || it.contains("Ender Chest") || it.contains("Backpack") } + fun inStorage() = + openInventoryName().let { it.contains("Storage") || it.contains("Ender Chest") || it.contains("Backpack") } fun getItemInHand(): ItemStack? = Minecraft.getMinecraft().thePlayer.heldItem }
\ No newline at end of file |