From f64a5a336cfb488a5c97190f22dee00d949f42a4 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 13 Apr 2024 22:27:21 +0200 Subject: [PATCH 1/4] Add Profit Per Excavation --- .../mining/FossilExcavatorConfig.java | 11 +++++ .../fossilexcavator/ProfitPerExcavation.kt | 45 +++++++++++++++++++ .../utils/tracker/SkyHanniItemTracker.kt | 7 +++ 3 files changed, 63 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorConfig.java index f1b70c6b3681..43f863e94fe3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/mining/FossilExcavatorConfig.java @@ -1,7 +1,9 @@ package at.hannibal2.skyhanni.config.features.mining; +import at.hannibal2.skyhanni.config.FeatureToggle; import com.google.gson.annotations.Expose; import io.github.notenoughupdates.moulconfig.annotations.Accordion; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; public class FossilExcavatorConfig { @@ -16,4 +18,13 @@ public class FossilExcavatorConfig { @Accordion public ExcavatorProfitTrackerConfig profitTracker = new ExcavatorProfitTrackerConfig(); + @Expose + @ConfigOption( + name = "Profit Per", + desc = "Show profit/loss in chat after each excavation. Also include breakdown information on hover." + ) + @ConfigEditorBoolean + @FeatureToggle + public boolean profitPerExcavation = false; + } diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt new file mode 100644 index 000000000000..a779d7a20aa1 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt @@ -0,0 +1,45 @@ +package at.hannibal2.skyhanni.features.mining.fossilexcavator + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.mining.FossilExcavationEvent +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.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems.getPrice +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ProfitPerExcavation { + private val config get() = SkyHanniMod.feature.mining.fossilExcavator + + @SubscribeEvent + fun onFossilExcavation(event: FossilExcavationEvent) { + if (!config.profitPerExcavation) return + val loot = event.loot + + val scrapItem = "SUSPICIOUS_SCRAP".asInternalName() + + var totalProfit = 0.0 + val map = mutableMapOf() + loot.forEach { (name, amount) -> + NEUInternalName.fromItemNameOrNull(name)?.let { + val profit = amount * it.getPrice() + val text = "Found $name §8${amount.addSeparators()}x §7(§6${NumberUtil.format(profit)}§7)" + map[text] = profit + totalProfit += profit + } + } + + val scrapPrice = scrapItem.getPrice() + map["${scrapItem.itemName}: §c-${NumberUtil.format(scrapPrice)}"] = -scrapPrice + totalProfit -= scrapPrice + + val hover = map.sortedDesc().keys.toList() + val profitPrefix = if (totalProfit < 0) "§c" else "§6" + val totalMessage = "Total profit this run: $profitPrefix${NumberUtil.format(totalProfit)}" + ChatUtils.hoverableChat(totalMessage, hover) + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt index 46bb84f04db7..0fbd052fa362 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt @@ -182,6 +182,8 @@ class SkyHanniItemTracker( } } + private var lastPer = "" + fun addTotalProfit(profit: Double, totalAmount: Long, action: String): Renderable { val profitFormat = profit.toInt().addSeparators() val profitPrefix = if (profit < 0) "§c" else "§6" @@ -189,6 +191,11 @@ class SkyHanniItemTracker( val tips = if (totalAmount > 0) { val profitPerCatch = profit / totalAmount val profitPerCatchFormat = NumberUtil.format(profitPerCatch) + val element = "§7Profit per $action: $profitPrefix${profitPerCatch.toInt().addSeparators()}" + if (lastPer != element) { + lastPer = element + ChatUtils.debug(lastPer) + } listOf("§7Profit per $action: $profitPrefix$profitPerCatchFormat") } else emptyList() From 311386cec461fb6ab183ebfc0ddd48ce547c0566 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 13 Apr 2024 22:38:23 +0200 Subject: [PATCH 2/4] fix --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 2 ++ .../features/mining/fossilexcavator/ProfitPerExcavation.kt | 6 ++++-- .../skyhanni/utils/tracker/SkyHanniItemTracker.kt | 7 ------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 248d5fb50e04..1f0581e46fe0 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -273,6 +273,7 @@ import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventDisplay import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventTracker import at.hannibal2.skyhanni.features.mining.fossilexcavator.ExcavatorProfitTracker import at.hannibal2.skyhanni.features.mining.fossilexcavator.FossilExcavatorAPI +import at.hannibal2.skyhanni.features.mining.fossilexcavator.ProfitPerExcavation import at.hannibal2.skyhanni.features.mining.fossilexcavator.solver.FossilSolverDisplay import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker import at.hannibal2.skyhanni.features.minion.InfernoMinionFeatures @@ -668,6 +669,7 @@ class SkyHanniMod { loadModule(ChickenHeadTimer()) loadModule(FossilSolverDisplay) loadModule(ExcavatorProfitTracker()) + loadModule(ProfitPerExcavation()) loadModule(GardenOptimalSpeed()) loadModule(GardenLevelDisplay()) loadModule(FarmingWeightDisplay()) diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt index a779d7a20aa1..0b46c971d22b 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt @@ -37,9 +37,11 @@ class ProfitPerExcavation { map["${scrapItem.itemName}: §c-${NumberUtil.format(scrapPrice)}"] = -scrapPrice totalProfit -= scrapPrice - val hover = map.sortedDesc().keys.toList() + val hover = map.sortedDesc().keys.toMutableList() val profitPrefix = if (totalProfit < 0) "§c" else "§6" - val totalMessage = "Total profit this run: $profitPrefix${NumberUtil.format(totalProfit)}" + val totalMessage = "Profit this excavation: $profitPrefix${NumberUtil.format(totalProfit)}" + hover.add("") + hover.add("§e$totalMessage") ChatUtils.hoverableChat(totalMessage, hover) } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt index 0fbd052fa362..46bb84f04db7 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/tracker/SkyHanniItemTracker.kt @@ -182,8 +182,6 @@ class SkyHanniItemTracker( } } - private var lastPer = "" - fun addTotalProfit(profit: Double, totalAmount: Long, action: String): Renderable { val profitFormat = profit.toInt().addSeparators() val profitPrefix = if (profit < 0) "§c" else "§6" @@ -191,11 +189,6 @@ class SkyHanniItemTracker( val tips = if (totalAmount > 0) { val profitPerCatch = profit / totalAmount val profitPerCatchFormat = NumberUtil.format(profitPerCatch) - val element = "§7Profit per $action: $profitPrefix${profitPerCatch.toInt().addSeparators()}" - if (lastPer != element) { - lastPer = element - ChatUtils.debug(lastPer) - } listOf("§7Profit per $action: $profitPrefix$profitPerCatchFormat") } else emptyList() From a458f4e85a6f6c71555f26e6f01761f17775a9b6 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 13 Apr 2024 22:42:16 +0200 Subject: [PATCH 3/4] caching scrapItem --- .../skyhanni/features/inventory/HideNotClickableItems.kt | 2 +- .../mining/fossilexcavator/ExcavatorProfitTracker.kt | 5 ++--- .../features/mining/fossilexcavator/FossilExcavatorAPI.kt | 3 +++ .../features/mining/fossilexcavator/ProfitPerExcavation.kt | 5 ++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt index 20c042f64390..e043f9d577c3 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/inventory/HideNotClickableItems.kt @@ -214,7 +214,7 @@ class HideNotClickableItems { showGreenLine = true val internalName = stack.getInternalNameOrNull() ?: return true - if (internalName == "SUSPICIOUS_SCRAP".asInternalName()) { + if (internalName == FossilExcavatorAPI.scrapItem) { return false } diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt index b2bc4a9106d8..f0a3fcaa82aa 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ExcavatorProfitTracker.kt @@ -11,7 +11,6 @@ import at.hannibal2.skyhanni.utils.ItemUtils.itemName import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland import at.hannibal2.skyhanni.utils.NEUInternalName -import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -63,7 +62,7 @@ class ExcavatorProfitTracker { var fossilDustGained = 0L } - private val scrapItem = "SUSPICIOUS_SCRAP".asInternalName() + private val scrapItem get() = FossilExcavatorAPI.scrapItem private fun drawDisplay(data: Data): List> = buildList { addAsSingletonList("§e§lFossil Excavation Profit Tracker") @@ -137,7 +136,7 @@ class ExcavatorProfitTracker { val name = StringUtils.pluralize(timesExcavated.toInt(), scrapItem.itemName) addAsSingletonList( Renderable.hoverTips( - "${scrapItem.itemName} §7price: §c-${NumberUtil.format(scrapPrice)}", + "$name §7price: §c-${NumberUtil.format(scrapPrice)}", listOf( "§7You paid §c${NumberUtil.format(scrapPrice)} coins §7in total", "§7for all §e$timesExcavated $name", diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt index 40971c87e49d..d2e50bd1cabf 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/FossilExcavatorAPI.kt @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.events.mining.FossilExcavationEvent import at.hannibal2.skyhanni.utils.InventoryUtils import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor @@ -47,6 +48,8 @@ object FossilExcavatorAPI { var inInventory = false var inExcavatorMenu = false + val scrapItem = "SUSPICIOUS_SCRAP".asInternalName() + @SubscribeEvent fun onInventoryOpen(event: InventoryFullyOpenedEvent) { if (!IslandType.DWARVEN_MINES.isInIsland()) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt index 0b46c971d22b..b131a3186dad 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt @@ -6,7 +6,6 @@ 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.NEUInternalName.Companion.asInternalName import at.hannibal2.skyhanni.utils.NEUItems.getPrice import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators @@ -20,8 +19,6 @@ class ProfitPerExcavation { if (!config.profitPerExcavation) return val loot = event.loot - val scrapItem = "SUSPICIOUS_SCRAP".asInternalName() - var totalProfit = 0.0 val map = mutableMapOf() loot.forEach { (name, amount) -> @@ -33,6 +30,8 @@ class ProfitPerExcavation { } } + val scrapItem = FossilExcavatorAPI.scrapItem + val scrapPrice = scrapItem.getPrice() map["${scrapItem.itemName}: §c-${NumberUtil.format(scrapPrice)}"] = -scrapPrice totalProfit -= scrapPrice From 85d8b4c755f9fc7b241964e1550a937915c0265c Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Sat, 13 Apr 2024 22:44:54 +0200 Subject: [PATCH 4/4] fixed fossil dust --- .../features/mining/fossilexcavator/ProfitPerExcavation.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt index b131a3186dad..4ac8dd4ff927 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt @@ -23,7 +23,9 @@ class ProfitPerExcavation { val map = mutableMapOf() loot.forEach { (name, amount) -> NEUInternalName.fromItemNameOrNull(name)?.let { - val profit = amount * it.getPrice() + val pricePer = it.getPrice() + if (pricePer == -1.0) return@forEach + val profit = amount * pricePer val text = "Found $name §8${amount.addSeparators()}x §7(§6${NumberUtil.format(profit)}§7)" map[text] = profit totalProfit += profit