summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-12 03:37:37 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-12 03:37:37 +0200
commit7f7ad4a745c584892b773732ab84557ca4596470 (patch)
treebf3e6f0a4e6fc91d5c796c528707943bcf81ad62 /src/main/java/at/hannibal2/skyhanni/utils
parent9373bdfcdee6f9202bbda328585734b90c14fc45 (diff)
downloadskyhanni-7f7ad4a745c584892b773732ab84557ca4596470.tar.gz
skyhanni-7f7ad4a745c584892b773732ab84557ca4596470.tar.bz2
skyhanni-7f7ad4a745c584892b773732ab84557ca4596470.zip
Made SkyBlockItemModifierUtils great again
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt303
1 files changed, 82 insertions, 221 deletions
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"
}