From 0102ddc4946b2e197024ef828c14f3b7b298dcd5 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 21 Dec 2023 17:30:32 +0100 Subject: Fixed SkyMart items showing wrong profit when having another items as cost. --- .../garden/inventory/SkyMartCopperPrice.kt | 32 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni') 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 { + var found = false + val list = mutableListOf() + 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>() 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!! -- cgit