diff options
author | Serhan <serhanduzce@gmail.com> | 2023-09-02 11:52:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-02 10:52:43 +0200 |
commit | 3971a5bff7b1ad8c57fb00d1920acbc94309801a (patch) | |
tree | 2c38d10d58d3fbbe98fdd35913b4d65623affbf4 /src/main/java | |
parent | 24326997aa39c566cc2c23b2b796a63dafc9f566 (diff) | |
download | skyhanni-3971a5bff7b1ad8c57fb00d1920acbc94309801a.tar.gz skyhanni-3971a5bff7b1ad8c57fb00d1920acbc94309801a.tar.bz2 skyhanni-3971a5bff7b1ad8c57fb00d1920acbc94309801a.zip |
new Gemstone Slot Unlock Cost line for Estimated Item Value feature (#408)
new Gemstone Slot Unlock Cost line for Estimated Item Value feature #408
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt | 71 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt | 24 |
2 files changed, 95 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt index 464b45762..4e29ca596 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/items/EstimatedItemValue.kt @@ -20,15 +20,18 @@ import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NEUItems.getPriceOrNull import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NEUItems.manager import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators import at.hannibal2.skyhanni.utils.OSUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems +import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.GemstoneSlotType import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getAbilityScrolls import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getArmorDye import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getAttributes import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getDrillUpgrades import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getDungeonStarCount import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments +import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getExtraAttributes import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getFarmingForDummiesCount import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getGemstones import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getHelmetSkin @@ -49,10 +52,17 @@ import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.hasWoodSingularity import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.isRecombobulated import at.hannibal2.skyhanni.utils.StringUtils.firstLetterUppercase import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken +import io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent +import io.github.moulberry.notenoughupdates.recipes.Ingredient import io.github.moulberry.notenoughupdates.util.Constants import net.minecraft.init.Items import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.io.File +import java.util.* +import kotlin.collections.HashMap import kotlin.math.roundToLong object EstimatedItemValue { @@ -60,6 +70,18 @@ object EstimatedItemValue { private var display = emptyList<List<Any>>() private val cache = mutableMapOf<ItemStack, List<List<Any>>>() private var lastToolTipTime = 0L + private var gemstoneUnlockCosts = HashMap<String, HashMap<String, List<String>>>() + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + val data = manager.getJsonFromFile(File(manager.repoLocation, "constants/gemstonecosts.json")) + + if (data != null) + // item_internal_names -> gemstone_slots -> ingredients_array + gemstoneUnlockCosts = Gson().fromJson(data, object : TypeToken<HashMap<String, HashMap<String, List<String>>>>() {}.getType()) + else + LorenzUtils.error("Gemstone Slot Unlock Costs failed to load") + } @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.ChestBackgroundRenderEvent) { @@ -188,6 +210,7 @@ object EstimatedItemValue { // dynamic totalPrice += addAbilityScrolls(stack, list) totalPrice += addDrillUpgrades(stack, list) + totalPrice += addGemstoneSlotUnlockCost(stack, list) totalPrice += addGemstones(stack, list) totalPrice += addEnchantments(stack, list) return Pair(totalPrice, basePrice) @@ -641,4 +664,52 @@ object EstimatedItemValue { } return totalPrice } + + private fun addGemstoneSlotUnlockCost(stack: ItemStack, list: MutableList<String>): Double { + val internalName = stack.getInternalName_old() + + // item have to contains gems.unlocked_slots NBT array for unlocked slot detection + val unlockedSlots = stack.getExtraAttributes()?.getCompoundTag("gems")?.getTag("unlocked_slots").toString() + + var totalPrice = 0.0 + val priceMap = mutableMapOf<String, Double>() + + if (gemstoneUnlockCosts.isNotEmpty() && gemstoneUnlockCosts.contains(internalName)) { + for (slot in gemstoneUnlockCosts.get(internalName)!!) { + if (unlockedSlots.contains(slot.key)) { + val previousTotal = totalPrice + + for (ingredients in slot.value) { + val ingredient = Ingredient(manager, ingredients) + + totalPrice += if (ingredient.isCoins) { + ingredient.count + } else { + getPrice(ingredient.internalItemId) * ingredient.count + } + } + + val splitSlot = slot.key.split("_") // eg. SAPPHIRE_1 + val colorCode = GemstoneSlotType.getColorCode(splitSlot[0]) + val formattedPrice = NumberUtil.format(totalPrice - previousTotal) + + // eg. SAPPHIRE_1 -> Sapphire Slot 2 + val displayName = splitSlot[0].lowercase(Locale.ENGLISH).replaceFirstChar(Char::uppercase) + " Slot" + + // If the slot index is 0, we don't need to specify + if (!splitSlot[1].equals("0")) { + " " + (splitSlot[1].toInt() + 1) + } else { "" } + + priceMap[" §$colorCode $displayName §7(§6$formattedPrice§7)"] = totalPrice - previousTotal + } + } + + // TODO detection for old items which doesnt have gems.unlocked_slots NBT array + if (!unlockedSlots.equals("null")) { + list.add("§7Gemstone Slot Unlock Cost: §6" + NumberUtil.format(totalPrice)) + list += priceMap.sortedDesc().keys + } + } + return totalPrice + } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt index c87941766..0cf1d3b32 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/SkyBlockItemModifierUtils.kt @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import com.google.gson.JsonObject import net.minecraft.item.ItemStack +import java.util.* object SkyBlockItemModifierUtils { private val drillPartTypes = listOf("drill_part_upgrade_module", "drill_part_engine", "drill_part_fuel_tank") @@ -263,4 +264,27 @@ object SkyBlockItemModifierUtils { fun getByName(name: String) = entries.firstOrNull { it.name == name } } } + + enum class GemstoneSlotType(val colorCode: Char) { + JADE('a'), + AMBER('6'), + TOPAZ('e'), + SAPPHIRE('b'), + AMETHYST('5'), + JASPER('d'), + RUBY('c'), + OPAL('f'), + COMBAT('4'), + OFFENSIVE('9'), + DEFENSIVE('a'), + MINING('5'), + UNIVERSAL('f') + ; + + companion object { + fun getColorCode(name: String) = entries.stream().filter { + name.uppercase(Locale.ENGLISH).contains(it.name) + }.findFirst().get().colorCode + } + } }
\ No newline at end of file |