-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Feature: Profit Per Excavation (#1439)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
- Loading branch information
1 parent
c78914d
commit 7943286
Showing
6 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/at/hannibal2/skyhanni/features/mining/fossilexcavator/ProfitPerExcavation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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.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 | ||
|
||
var totalProfit = 0.0 | ||
val map = mutableMapOf<String, Double>() | ||
loot.forEach { (name, amount) -> | ||
NEUInternalName.fromItemNameOrNull(name)?.let { | ||
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 | ||
} | ||
} | ||
|
||
val scrapItem = FossilExcavatorAPI.scrapItem | ||
|
||
val scrapPrice = scrapItem.getPrice() | ||
map["${scrapItem.itemName}: §c-${NumberUtil.format(scrapPrice)}"] = -scrapPrice | ||
totalProfit -= scrapPrice | ||
|
||
val hover = map.sortedDesc().keys.toMutableList() | ||
val profitPrefix = if (totalProfit < 0) "§c" else "§6" | ||
val totalMessage = "Profit this excavation: $profitPrefix${NumberUtil.format(totalProfit)}" | ||
hover.add("") | ||
hover.add("§e$totalMessage") | ||
ChatUtils.hoverableChat(totalMessage, hover) | ||
} | ||
} |