From 9acb6e88fb868ce9d591fb98cfa80730681653f6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Tue, 10 Sep 2024 21:54:18 +0200 Subject: fixed profit per mineshaft corpse --- .../mining/glacitemineshaft/CorpseTracker.kt | 2 +- .../glacitemineshaft/MineshaftCorpseProfitPer.kt | 56 ---------------------- .../glacitemineshaft/ProfitPerMineshaftCorpse.kt | 55 +++++++++++++++++++++ .../utils/tracker/SkyHanniBucketedItemTracker.kt | 3 +- 4 files changed, 57 insertions(+), 59 deletions(-) delete mode 100644 src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/MineshaftCorpseProfitPer.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/ProfitPerMineshaftCorpse.kt (limited to 'src/main/java') diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/CorpseTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/CorpseTracker.kt index 77aabc1bd..c54315d7e 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/CorpseTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/CorpseTracker.kt @@ -34,7 +34,7 @@ object CorpseTracker { "Corpse Tracker", { BucketData() }, { it.mining.mineshaft.corpseProfitTracker }, - { drawDisplay(it) } + { drawDisplay(it) }, ) class BucketData : BucketedItemTrackerData() { diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/MineshaftCorpseProfitPer.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/MineshaftCorpseProfitPer.kt deleted file mode 100644 index eed5f2b9d..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/MineshaftCorpseProfitPer.kt +++ /dev/null @@ -1,56 +0,0 @@ -package at.hannibal2.skyhanni.features.mining.glacitemineshaft - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.events.mining.CorpseLootedEvent -import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule -import at.hannibal2.skyhanni.utils.ChatUtils -import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc -import at.hannibal2.skyhanni.utils.ItemUtils.itemName -import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUItems.getPrice -import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators -import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent - -@SkyHanniModule -object MineshaftCorpseProfitPer { - private val config get() = SkyHanniMod.feature.mining.mineshaft - - @SubscribeEvent - fun onFossilExcavation(event: CorpseLootedEvent) { - if (!config.profitPerCorpseLoot) return - val loot = event.loot - - var totalProfit = 0.0 - val map = mutableMapOf() - for ((name, amount) in loot) { - if (name == "§bGlacite Powder") continue - NEUInternalName.fromItemNameOrNull(name)?.let { - val pricePer = it.getPrice() - if (pricePer == -1.0) continue - val profit = amount * pricePer - val text = "§eFound $name §8${amount.addSeparators()}x §7(§6${profit.shortFormat()}§7)" - map[text] = profit - totalProfit += profit - } - } - - val corpseType = event.corpseType - val name = corpseType.displayName - - corpseType.key?.let { - val keyName = it.itemName - val price = it.getPrice() - - map["$keyName: §c-${price.shortFormat()}"] = -price - totalProfit -= price - } - - val hover = map.sortedDesc().keys.toMutableList() - val profitPrefix = if (totalProfit < 0) "§c" else "§6" - val totalMessage = "Profit for $name Corpse§e: $profitPrefix${totalProfit.shortFormat()}" - hover.add("") - hover.add("§e$totalMessage") - ChatUtils.hoverableChat(totalMessage, hover) - } -} diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/ProfitPerMineshaftCorpse.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/ProfitPerMineshaftCorpse.kt new file mode 100644 index 000000000..7eebeeaab --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/glacitemineshaft/ProfitPerMineshaftCorpse.kt @@ -0,0 +1,55 @@ +package at.hannibal2.skyhanni.features.mining.glacitemineshaft + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.mining.CorpseLootedEvent +import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.CollectionUtils.sortedDesc +import at.hannibal2.skyhanni.utils.ItemPriceUtils.getPriceOrNull +import at.hannibal2.skyhanni.utils.ItemUtils.itemName +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getPrice +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +@SkyHanniModule +object ProfitPerMineshaftCorpse { + private val config get() = SkyHanniMod.feature.mining.mineshaft + + @SubscribeEvent + fun onFossilExcavation(event: CorpseLootedEvent) { + if (!config.profitPerCorpseLoot) return + val loot = event.loot + + var totalProfit = 0.0 + val map = mutableMapOf() + for ((name, amount) in loot) { + if (name == "§bGlacite Powder") continue + val internalName = NEUInternalName.fromItemNameOrNull(name) ?: continue + val pricePer = internalName.getPriceOrNull() ?: continue + val profit = amount * pricePer + val text = "§eFound $name §8${amount.addSeparators()}x §7(§6${profit.shortFormat()}§7)" + map[text] = profit + totalProfit += profit + } + + val corpseType = event.corpseType + val name = corpseType.displayName + + corpseType.key?.let { + val keyName = it.itemName + val price = it.getPrice() + + map["§cCost: $keyName §7(§c-${price.shortFormat()}§7)"] = -price + totalProfit -= price + } + + val hover = map.sortedDesc().keys.toMutableList() + val profitPrefix = if (totalProfit < 0) "§c" else "§6" + val totalMessage = "Profit for $name Corpse§e: $profitPrefix${totalProfit.shortFormat()}" + hover.add("") + hover.add("§e$totalMessage") + ChatUtils.hoverableChat(totalMessage, hover) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniBucketedItemTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniBucketedItemTracker.kt index dcbab2b1b..2975d57e2 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniBucketedItemTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniBucketedItemTracker.kt @@ -98,8 +98,7 @@ class SkyHanniBucketedItemTracker, BucketedData : BucketedItemTracke if (!filter(internalName)) continue val amount = itemProfit.totalAmount - val pricePer = - if (internalName == SKYBLOCK_COIN) 1.0 else data.getCustomPricePer(internalName) + val pricePer = if (internalName == SKYBLOCK_COIN) 1.0 else data.getCustomPricePer(internalName) val price = (pricePer * amount).toLong() val hidden = itemProfit.hidden -- cgit