aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt
index a2e6a91c7..0aba4b861 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/inventory/SkyMartCopperPrice.kt
@@ -11,10 +11,13 @@ import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.NEUInternalName
+import at.hannibal2.skyhanni.utils.NEUItems
+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.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class SkyMartCopperPrice {
@@ -26,6 +29,25 @@ class SkyMartCopperPrice {
var inInventory = false
}
+ private fun ItemStack.loreCosts(): MutableList<NEUInternalName> {
+ var found = false
+ val list = mutableListOf<NEUInternalName>()
+ for (lines in getLore()) {
+ if (lines == "ยง7Cost") {
+ found = true
+ continue
+ }
+
+ if (!found) continue
+ if (lines.isEmpty()) return list
+
+ NEUItems.getInternalNameOrNull(lines)?.let {
+ list.add(it)
+ }
+ }
+ return list
+ }
+
@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!isEnabled()) return
@@ -34,16 +56,20 @@ class SkyMartCopperPrice {
inInventory = true
val table = mutableMapOf<Pair<String, String>, Pair<Double, NEUInternalName>>()
for (stack in event.inventoryItems.values) {
- for (line in stack.getLore()) {
+ val lore = stack.getLore()
+ val otherItemsPrice = stack.loreCosts().sumOf { it.getPrice() }
+
+ for (line in lore) {
val internalName = stack.getInternalName()
val lowestBin = internalName.getPriceOrNull() ?: continue
+ val profit = lowestBin - otherItemsPrice
val amount = copperPattern.matchMatcher(line) {
group("amount").replace(",", "").toInt()
} ?: continue
- val factor = lowestBin / amount
+ val factor = profit / amount
val perFormat = NumberUtil.format(factor)
- val priceFormat = NumberUtil.format(lowestBin)
+ val priceFormat = NumberUtil.format(profit)
val amountFormat = NumberUtil.format(amount)
val name = stack.nameWithEnchantment!!