diff options
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
3 files changed, 135 insertions, 288 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt index 4368ac0f9..7a60f7120 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt @@ -30,12 +30,12 @@ class ToolTooltipTweaks { val dedicationFortune = FarmingFortuneDisplay.getDedicationFortune(event.itemStack, crop) val reforgeName = event.itemStack.getReforgeName()?.firstLetterUppercase() - val enchantments = event.itemStack.getEnchantments() + val enchantments = event.itemStack.getEnchantments() ?: emptyMap() val sunderFortune = (enchantments["sunder"] ?: 0) * 12.5 val harvestingFortune = (enchantments["harvesting"] ?: 0) * 12.5 val cultivatingFortune = (enchantments["cultivating"] ?: 0).toDouble() - val ffdFortune = event.itemStack.getFarmingForDummiesCount().toDouble() + val ffdFortune = event.itemStack.getFarmingForDummiesCount()?.toDouble() ?: 0.0 val cropFortune = (toolFortune + counterFortune + collectionFortune + turboCropFortune + dedicationFortune) val iterator = event.toolTip.listIterator() diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/EstimatedItemValue.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/EstimatedItemValue.kt index f52a778d7..285b985a8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/EstimatedItemValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/EstimatedItemValue.kt @@ -173,88 +173,73 @@ class EstimatedItemValue { } private fun addRecomb(stack: ItemStack, list: MutableList<String>): Double { - if (stack.isRecombobulated()) { - val wtfHardcodedRecomb = "RECOMBOBULATOR_3000" - val price = NEUItems.getPrice(wtfHardcodedRecomb) - list.add("§7Recombobulated: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") - return price - } + if (!stack.isRecombobulated()) return 0.0 - return 0.0 + val wtfHardcodedRecomb = "RECOMBOBULATOR_3000" + val price = NEUItems.getPrice(wtfHardcodedRecomb) + list.add("§7Recombobulated: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") + return price } private fun addJalapenoBook(stack: ItemStack, list: MutableList<String>): Double { - if (stack.hasJalapenoBook()) { - val wtfHardcodedJalapeno = "JALAPENO_BOOK" + if (!stack.hasJalapenoBook()) return 0.0 - val price = NEUItems.getPrice(wtfHardcodedJalapeno) - list.add("§7Jalapeno Book: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") - return price - } + val wtfHardcodedJalapeno = "JALAPENO_BOOK" - return 0.0 + val price = NEUItems.getPrice(wtfHardcodedJalapeno) + list.add("§7Jalapeno Book: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") + return price } private fun addEtherwarp(stack: ItemStack, list: MutableList<String>): Double { - if (stack.hasEtherwarp()) { - val wtfHardcodedConduit = "ETHERWARP_CONDUIT" - val wtfHardcodedMerger = "ETHERWARP_MERGER" - val price = NEUItems.getPrice(wtfHardcodedConduit) + NEUItems.getPrice(wtfHardcodedMerger) - list.add("§7Etherwarp: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") - return price - } + if (!stack.hasEtherwarp()) return 0.0 - return 0.0 + val wtfHardcodedConduit = "ETHERWARP_CONDUIT" + val wtfHardcodedMerger = "ETHERWARP_MERGER" + val price = NEUItems.getPrice(wtfHardcodedConduit) + NEUItems.getPrice(wtfHardcodedMerger) + list.add("§7Etherwarp: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") + return price } private fun addWoodSingularity(stack: ItemStack, list: MutableList<String>): Double { - if (stack.hasWoodSingularity()) { - val wtfHardcodedSingularity = "WOOD_SINGULARITY" - val price = NEUItems.getPrice(wtfHardcodedSingularity) - list.add("§7Wood Singularity: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") - return price - } + if (!stack.hasWoodSingularity()) return 0.0 - return 0.0 + val wtfHardcodedSingularity = "WOOD_SINGULARITY" + val price = NEUItems.getPrice(wtfHardcodedSingularity) + list.add("§7Wood Singularity: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") + return price } private fun addArtOfWar(stack: ItemStack, list: MutableList<String>): Double { - if (stack.hasArtOfWar()) { - val ripTechno = "THE_ART_OF_WAR" - val price = NEUItems.getPrice(ripTechno) - list.add("§7The Art of War: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") - return price - } + if (!stack.hasArtOfWar()) return 0.0 - return 0.0 + val ripTechno = "THE_ART_OF_WAR" + val price = NEUItems.getPrice(ripTechno) + list.add("§7The Art of War: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") + return price } private fun addStatsBook(stack: ItemStack, list: MutableList<String>): Double { - if (stack.hasBookOfStats()) { - val ripTechno = "BOOK_OF_STATS" - val price = NEUItems.getPrice(ripTechno) - list.add("§7Book of Stats: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") - return price - } + if (!stack.hasBookOfStats()) return 0.0 - return 0.0 + val ripTechno = "BOOK_OF_STATS" + val price = NEUItems.getPrice(ripTechno) + list.add("§7Book of Stats: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") + return price } // TODO untested private fun addArtOfPiece(stack: ItemStack, list: MutableList<String>): Double { - if (stack.hasArtOfPiece()) { - val ripTechno = "THE_ART_OF_PEACE" - val price = NEUItems.getPrice(ripTechno) - list.add("§7The Art Of Piece: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") - return price - } + if (!stack.hasArtOfPiece()) return 0.0 - return 0.0 + val ripTechno = "THE_ART_OF_PEACE" + val price = NEUItems.getPrice(ripTechno) + list.add("§7The Art Of Piece: §a§l✔ §7(§6" + NumberUtil.format(price) + "§7)") + return price } private fun addHotPotatoBooks(stack: ItemStack, list: MutableList<String>): Double { - val count = stack.getHotPotatoCount() - if (count == 0) return 0.0 + val count = stack.getHotPotatoCount() ?: return 0.0 val hpb: Int val fuming: Int @@ -284,8 +269,7 @@ class EstimatedItemValue { } private fun addFarmingForDummies(stack: ItemStack, list: MutableList<String>): Double { - val count = stack.getFarmingForDummiesCount() - if (count == 0) return 0.0 + val count = stack.getFarmingForDummiesCount() ?: return 0.0 val wtfHardcodedDumbFarmers = "FARMING_FOR_DUMMIES" val price = NEUItems.getPrice(wtfHardcodedDumbFarmers) * count @@ -294,8 +278,7 @@ class EstimatedItemValue { } private fun addSilex(stack: ItemStack, list: MutableList<String>): Double { - val tier = stack.getSilexCount() - if (tier == 0) return 0.0 + val tier = stack.getSilexCount() ?: return 0.0 val internalName = stack.getInternalName() val maxTier = if (internalName == "STONK_PICKAXE") 4 else 5 @@ -307,8 +290,7 @@ class EstimatedItemValue { } private fun addTransmissionTuners(stack: ItemStack, list: MutableList<String>): Double { - val count = stack.getTransmissionTunerCount() - if (count == 0) return 0.0 + val count = stack.getTransmissionTunerCount() ?: return 0.0 val wtfHardcodedTuner = "TRANSMISSION_TUNER" val price = NEUItems.getPrice(wtfHardcodedTuner) * count @@ -317,8 +299,7 @@ class EstimatedItemValue { } private fun addManaDisintegrators(stack: ItemStack, list: MutableList<String>): Double { - val count = stack.getManaDisintegrators() - if (count == 0) return 0.0 + val count = stack.getManaDisintegrators() ?: return 0.0 val wtfHardcodedTuner = "MANA_DISINTEGRATOR" val price = NEUItems.getPrice(wtfHardcodedTuner) * count @@ -352,9 +333,11 @@ class EstimatedItemValue { } private fun addDrillUpgrades(stack: ItemStack, list: MutableList<String>): Double { + val drillUpgrades = stack.getDrillUpgrades() ?: return 0.0 + var totalPrice = 0.0 val map = mutableMapOf<String, Double>() - for (internalName in stack.getDrillUpgrades()) { + for (internalName in drillUpgrades) { val name = NEUItems.getItemStackOrNull(internalName)!!.name val price = NEUItems.getPriceOrNull(internalName) ?: continue @@ -397,9 +380,11 @@ class EstimatedItemValue { } private fun addAbilityScrolls(stack: ItemStack, list: MutableList<String>): Double { + val abilityScrolls = stack.getAbilityScrolls() ?: return 0.0 + var totalPrice = 0.0 val map = mutableMapOf<String, Double>() - for (internalName in stack.getAbilityScrolls()) { + for (internalName in abilityScrolls) { val name = NEUItems.getItemStackOrNull(internalName)!!.name val price = NEUItems.getPriceOrNull(internalName) ?: continue @@ -432,6 +417,8 @@ class EstimatedItemValue { } private fun addEnchantments(stack: ItemStack, list: MutableList<String>): Double { + val enchantments = stack.getEnchantments() ?: return 0.0 + var totalPrice = 0.0 val map = mutableMapOf<String, Double>() @@ -447,7 +434,7 @@ class EstimatedItemValue { ) val internalName = stack.getInternalName() - for ((rawName, rawLevel) in stack.getEnchantments()) { + for ((rawName, rawLevel) in enchantments) { // efficiency 1-5 is cheap, 6-10 is handled by silex if (rawName == "efficiency") continue @@ -508,8 +495,7 @@ class EstimatedItemValue { } private fun addGemstones(stack: ItemStack, list: MutableList<String>): Double { - val gemstones = stack.getGemstones() - if (gemstones.isEmpty()) return 0.0 + val gemstones = stack.getGemstones() ?: return 0.0 var totalPrice = 0.0 val counterMap = mutableMapOf<String, Int>() diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt index a7e97bb0e..3ff2e54e6 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt @@ -7,57 +7,18 @@ import net.minecraft.item.ItemStack object SkyBlockItemModifierUtils { private val drillPartTypes = listOf("drill_part_upgrade_module", "drill_part_engine", "drill_part_fuel_tank") - fun ItemStack.getHotPotatoCount(): Int { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes != "hot_potato_count") continue - return extraAttributes.getInteger(attributes) - } - } - return 0 - } + fun ItemStack.getHotPotatoCount() = getAttributeInt("hot_potato_count") - fun ItemStack.getFarmingForDummiesCount(): Int { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes != "farming_for_dummies_count") continue - return extraAttributes.getInteger(attributes) - } - } - return 0 - } + fun ItemStack.getFarmingForDummiesCount() = getAttributeInt("farming_for_dummies_count") - fun ItemStack.getCultivatingCount(): Int? { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes != "farmed_cultivating") continue - return extraAttributes.getInteger(attributes) - } - } - return null - } + fun ItemStack.getCultivatingCount() = getAttributeInt("farmed_cultivating") - fun ItemStack.getCounter(): Int? { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes != "mined_crops") continue - return extraAttributes.getInteger(attributes) - } - } - return null - } + fun ItemStack.getCounter() = getAttributeInt("mined_crops") - fun ItemStack.getSilexCount(): Int { + fun ItemStack.getSilexCount(): Int? { + val enchantments = getEnchantments() ?: return null var silexTier = 0 - for ((name, amount) in getEnchantments()) { + for ((name, amount) in enchantments) { if (name == "efficiency") { if (amount > 5) { silexTier = amount - 5 @@ -72,29 +33,9 @@ object SkyBlockItemModifierUtils { return silexTier } - fun ItemStack.getTransmissionTunerCount(): Int { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes != "tuned_transmission") continue - return extraAttributes.getInteger(attributes) - } - } - return 0 - } + fun ItemStack.getTransmissionTunerCount() = getAttributeInt("tuned_transmission") - fun ItemStack.getManaDisintegrators(): Int { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes != "mana_disintegrator_count") continue - return extraAttributes.getInteger(attributes) - } - } - return 0 - } + fun ItemStack.getManaDisintegrators() = getAttributeInt("mana_disintegrator_count") fun ItemStack.getMasterStars(): Int { val stars = mapOf( @@ -114,195 +55,115 @@ object SkyBlockItemModifierUtils { return 0 } - fun ItemStack.getDrillUpgrades(): List<String> { + fun ItemStack.getDrillUpgrades() = getExtraAttributes()?.let { val list = mutableListOf<String>() - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes in drillPartTypes) { - val upgradeItem = extraAttributes.getString(attributes) - list.add(upgradeItem.uppercase()) - } + for (attributes in it.keySet) { + if (attributes in drillPartTypes) { + val upgradeItem = it.getString(attributes) + list.add(upgradeItem.uppercase()) } } - - return list + list } - fun ItemStack.getPowerScroll(): String? { - return tagCompound?.getCompoundTag("ExtraAttributes")?.getString("power_ability_scroll") - ?.takeUnless { it.isBlank() } - } + fun ItemStack.getPowerScroll() = getAttributeString("power_ability_scroll") - fun ItemStack.getHelmetSkin(): String? { - return tagCompound?.getCompoundTag("ExtraAttributes")?.getString("skin")?.takeUnless { it.isBlank() } - } + fun ItemStack.getHelmetSkin() = getAttributeString("skin") - fun ItemStack.getArmorDye(): String? { - return tagCompound?.getCompoundTag("ExtraAttributes")?.getString("dye_item")?.takeUnless { it.isBlank() } - } + fun ItemStack.getArmorDye() = getAttributeString("dye_item") - fun ItemStack.getAbilityScrolls(): List<String> { + fun ItemStack.getAbilityScrolls() = getExtraAttributes()?.let { val list = mutableListOf<String>() - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes == "ability_scroll") { - - val tagList = extraAttributes.getTagList(attributes, 8) - for (i in 0..3) { - val text = tagList.get(i).toString() - if (text == "END") break - var internalName = text.replace("\"", "") - list.add(internalName) - } + for (attributes in it.keySet) { + if (attributes == "ability_scroll") { + val tagList = it.getTagList(attributes, 8) + for (i in 0..3) { + val text = tagList.get(i).toString() + if (text == "END") break + val internalName = text.replace("\"", "") + list.add(internalName) } } } - - return list + list.toList() } - fun ItemStack.getReforgeName(): String? { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes != "modifier") continue - return extraAttributes.getString(attributes) - } - } - return null - } - - fun ItemStack.isRecombobulated(): Boolean { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - return extraAttributes.hasKey("rarity_upgrades") - } - - return false - } + fun ItemStack.getReforgeName() = getAttributeString("modifier") - fun ItemStack.hasJalapenoBook(): Boolean { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - return extraAttributes.hasKey("jalapeno_count") - } + fun ItemStack.isRecombobulated() = getAttributeBoolean("rarity_upgrades") - return false - } + fun ItemStack.hasJalapenoBook() = getAttributeBoolean("jalapeno_count") - fun ItemStack.hasEtherwarp(): Boolean { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - return extraAttributes.hasKey("ethermerge") - } + fun ItemStack.hasEtherwarp() = getAttributeBoolean("ethermerge") - return false - } - - fun ItemStack.hasWoodSingularity(): Boolean { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - return extraAttributes.hasKey("wood_singularity_count") - } - - return false - } - - fun ItemStack.hasArtOfWar(): Boolean { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - return extraAttributes.hasKey("art_of_war_count") - } + fun ItemStack.hasWoodSingularity() = getAttributeBoolean("wood_singularity_count") - return false - } + fun ItemStack.hasArtOfWar() = getAttributeBoolean("art_of_war_count") // TODO untested - fun ItemStack.hasBookOfStats(): Boolean { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - return extraAttributes.hasKey("stats_book") - } - - return false - } + fun ItemStack.hasBookOfStats() = getAttributeBoolean("stats_book") - fun ItemStack.hasArtOfPiece(): Boolean { - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - return extraAttributes.hasKey("artOfPeaceApplied") - } - - return false - } + fun ItemStack.hasArtOfPiece() = getAttributeBoolean("artOfPeaceApplied") - fun ItemStack.getEnchantments(): Map<String, Int> { + fun ItemStack.getEnchantments() = getExtraAttributes()?.let { val map = mutableMapOf<String, Int>() - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes != "enchantments") continue - val enchantments = extraAttributes.getCompoundTag(attributes) - for (key in enchantments.keySet) { - map[key] = enchantments.getInteger(key) - } + for (attributes in it.keySet) { + if (attributes != "enchantments") continue + val enchantments = it.getCompoundTag(attributes) + for (key in enchantments.keySet) { + map[key] = enchantments.getInteger(key) } } - return map + map } - fun ItemStack.getGemstones(): List<GemstoneSlot> { + fun ItemStack.getGemstones() = getExtraAttributes()?.let { val list = mutableListOf<GemstoneSlot>() - for (tags in tagCompound.keySet) { - if (tags != "ExtraAttributes") continue - val extraAttributes = tagCompound.getCompoundTag(tags) - for (attributes in extraAttributes.keySet) { - if (attributes != "gems") continue - val gemstones = extraAttributes.getCompoundTag(attributes) - for (key in gemstones.keySet) { - if (key.endsWith("_gem")) continue - if (key == "unlocked_slots") continue - val value = gemstones.getString(key) - if (value == "") continue - - val rawType = key.split("_")[0] - val type = GemstoneType.getByName(rawType) - - val tier = GemstoneTier.getByName(value) - if (tier == null) { - LorenzUtils.debug("Gemstone tier is null for item $name: ('$key' = '$value')") + for (attributes in it.keySet) { + if (attributes != "gems") continue + val gemstones = it.getCompoundTag(attributes) + for (key in gemstones.keySet) { + if (key.endsWith("_gem")) continue + if (key == "unlocked_slots") continue + val value = gemstones.getString(key) + if (value == "") continue + + val rawType = key.split("_")[0] + val type = GemstoneType.getByName(rawType) + + val tier = GemstoneTier.getByName(value) + if (tier == null) { + LorenzUtils.debug("Gemstone tier is null for item $name: ('$key' = '$value')") + continue + } + if (type != null) { + list.add(GemstoneSlot(type, tier)) + } else { + val newKey = gemstones.getString(key + "_gem") + val newType = GemstoneType.getByName(newKey) + if (newType == null) { + LorenzUtils.debug("Gemstone type is null for item $name: ('$newKey' with '$key' = '$value')") continue } - if (type != null) { - list.add(GemstoneSlot(type, tier)) - } else { - val newKey = gemstones.getString(key + "_gem") - val newType = GemstoneType.getByName(newKey) - if (newType == null) { - LorenzUtils.debug("Gemstone type is null for item $name: ('$newKey' with '$key' = '$value')") - continue - } - list.add(GemstoneSlot(newType, tier)) - } + list.add(GemstoneSlot(newType, tier)) } } } - return list + list } + private fun ItemStack.getAttributeString(label: String) = + getExtraAttributes()?.getString(label)?.takeUnless { it.isBlank() } + + private fun ItemStack.getAttributeInt(label: String) = + getExtraAttributes()?.getInteger(label)?.takeUnless { it == 0 } + + private fun ItemStack.getAttributeBoolean(label: String): Boolean { + return getExtraAttributes()?.hasKey(label) ?: false + } + + private fun ItemStack.getExtraAttributes() = tagCompound?.getCompoundTag("ExtraAttributes") + class GemstoneSlot(val type: GemstoneType, val tier: GemstoneTier) { fun getInternalName() = "${tier}_${type}_GEM" } |