aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-12-21 17:30:32 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-12-21 17:30:32 +0100
commit0102ddc4946b2e197024ef828c14f3b7b298dcd5 (patch)
tree90cbbb3a18d52c8941208ecd60d6eead2ef567bf /src/main/java/at/hannibal2/skyhanni
parent31f4c69a17f1f935c7cca11d8c3331b6cc4d7897 (diff)
downloadskyhanni-0102ddc4946b2e197024ef828c14f3b7b298dcd5.tar.gz
skyhanni-0102ddc4946b2e197024ef828c14f3b7b298dcd5.tar.bz2
skyhanni-0102ddc4946b2e197024ef828c14f3b7b298dcd5.zip
Fixed SkyMart items showing wrong profit when having another items as cost.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
-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!!