diff options
author | Lorenz <ESs95s3P5z8Pheb> | 2022-07-14 12:06:07 +0200 |
---|---|---|
committer | Lorenz <ESs95s3P5z8Pheb> | 2022-07-14 12:06:07 +0200 |
commit | a5c540d977a3510812cac7fac340fe17e7d10983 (patch) | |
tree | dbbe5b208e6871378a10868d1206d1d78beeb950 /src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | |
parent | d6c99ed30a2b1cb228b2fdc3d3178cf1f369dc53 (diff) | |
download | skyhanni-a5c540d977a3510812cac7fac340fe17e7d10983.tar.gz skyhanni-a5c540d977a3510812cac7fac340fe17e7d10983.tar.bz2 skyhanni-a5c540d977a3510812cac7fac340fe17e7d10983.zip |
renamed mod to SkyHanni
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt new file mode 100644 index 000000000..b077c4121 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -0,0 +1,72 @@ +package at.hannibal2.skyhanni.utils + +import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex +import at.hannibal2.skyhanni.utils.LorenzUtils.removeColorCodes +import net.minecraft.client.Minecraft +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.item.ItemStack + +object ItemUtils { + + fun ItemStack.cleanName() = this.displayName.removeColorCodes() + + fun getItemsInOpenChest(): List<ItemStack> { + val list = mutableListOf<ItemStack>() + val guiChest = Minecraft.getMinecraft().currentScreen as GuiChest + val inventorySlots = guiChest.inventorySlots.inventorySlots + val skipAt = inventorySlots.size - 9 * 4 + var i = 0 + for (slot in inventorySlots) { + val stack = slot.stack + if (stack != null) { + list.add(stack) + } + i++ + if (i == skipAt) break + } + return list + } + + fun isSack(name: String): Boolean = name.endsWith(" Sack") + + fun ItemStack.getLore() = ItemUtil.getItemLore(this) + + fun isCoOpSoulBound(stack: ItemStack): Boolean = stack.getLore().any { it.contains("Co-op Soulbound") } + + fun isRecombobulated(stack: ItemStack): Boolean = stack.getLore().any { it.contains("§k") } + + fun isPet(name: String): Boolean = name.matchRegex("\\[Lvl (.*)] (.*)") && !listOf( + "Archer", + "Berserk", + "Mage", + "Tank", + "Healer", + "➡", + ).any { name.contains(it) } + + fun maxPetLevel(name: String) = if (name.contains("Golden Dragon")) 200 else 100 + + fun getItemsInInventoryWithSlots(withCursorItem: Boolean = false): Map<ItemStack, Int> { + val map: LinkedHashMap<ItemStack, Int> = LinkedHashMap() + val player = Minecraft.getMinecraft().thePlayer + if (player == null) { + LorenzUtils.warning("getItemsInInventoryWithSlots: player is null!") + return map + } + for (slot in player.openContainer.inventorySlots) { + if (slot.hasStack) { + map[slot.stack] = slot.slotNumber + } + } + + if (withCursorItem) { + if (player.inventory != null) { + if (player.inventory.itemStack != null) { + map[player.inventory.itemStack] = -1 + } + } + } + + return map + } +}
\ No newline at end of file |