diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-16 19:51:53 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-16 19:51:53 +0200 |
commit | d82f1a825da599650ee2b6aab84a97e90abf4745 (patch) | |
tree | d12df6794deb7aedea8ba620dc611e7423012fca /src/main/java/at/hannibal2/skyhanni/features/bazaar | |
parent | f01195b5cf091dedbddd5e76b3a7e273b89fe2db (diff) | |
download | skyhanni-d82f1a825da599650ee2b6aab84a97e90abf4745.tar.gz skyhanni-d82f1a825da599650ee2b6aab84a97e90abf4745.tar.bz2 skyhanni-d82f1a825da599650ee2b6aab84a97e90abf4745.zip |
Fixed bazaar detection with turbo books again
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/bazaar')
4 files changed, 20 insertions, 42 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt index 4ed8f6255..b1c909f03 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt @@ -17,24 +17,6 @@ class BazaarApi { val holder = BazaarDataHolder() var inBazaarInventory = false - fun getCleanBazaarName(name: String): String { - var newName = name - if (newName.endsWith(" Gemstone")) { - return newName.substring(6) - } - if (newName.contains("Turbo-Cocoa ")) { - newName = newName.replace("Cocoa", "Coco") - } - if (newName.contains("Turbo-Cacti ")) { - newName = newName.replace("Cacti", "Cactus") - } - newName = newName.removeColor() - if (!name.contains("Tightly-Tied")) { - newName = newName.replace("-", " ") - } - return newName - } - fun getBazaarDataByName(name: String): BazaarData? = NEUItems.getInternalNameOrNull(name)?.let { getBazaarDataByInternalName(it) } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt index 94ee30d6e..fa11ee786 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt @@ -2,8 +2,10 @@ package at.hannibal2.skyhanni.features.bazaar import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.InventoryCloseEvent -import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.ItemUtils.nameWithEnchantment import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems import at.hannibal2.skyhanni.utils.NumberUtil import at.hannibal2.skyhanni.utils.RenderUtils.renderString import net.minecraft.client.gui.inventory.GuiChest @@ -36,30 +38,26 @@ class BazaarBestSellMethod { val buyInstantly = inv.getStackInSlot(10) if (buyInstantly == null || buyInstantly.displayName != "§aBuy Instantly") return "" val bazaarItem = inv.getStackInSlot(13) ?: return "" - var name = bazaarItem.displayName - name = BazaarApi.getCleanBazaarName(name) - val data = BazaarApi.getBazaarDataByName(name) ?: return "" + + val internalName = NEUItems.getInternalNameOrNull(bazaarItem.displayName) ?: return "" var having = 0 for (slot in chest.inventorySlots) { if (slot == null) continue if (slot.slotNumber == slot.slotIndex) continue val stack = slot.stack ?: continue - - var displayName = stack.displayName - if (displayName.endsWith("Enchanted Book")) { - displayName = stack.getLore()[0] - } - if (BazaarApi.getCleanBazaarName(displayName) == name) { + if (internalName == stack.getInternalName()) { having += stack.stackSize } } if (having <= 0) return "" + val data = BazaarApi.getBazaarDataByInternalName(internalName) ?: return "" val totalDiff = (data.buyPrice - data.sellPrice) * having val result = NumberUtil.format(totalDiff.toInt()) + val name = NEUItems.getItemStack(internalName).nameWithEnchantment return "§b$name§f sell difference: §e$result coins" } catch (e: Error) { e.printStackTrace() diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt index 226e368a7..4e7bb1f0c 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataHolder.kt @@ -55,7 +55,9 @@ class BazaarDataHolder { val buyPrice = NEUItems.getPrice(internalName, false) val npcPrice = npcPrices[internalName].let { if (it == null) { - LorenzUtils.debug("NPC price not found for item '$internalName'") + if (!internalName.startsWith("TURBO_") && internalName != "PURPLE_CANDY") { + LorenzUtils.debug("NPC price not found for item '$internalName'") + } 0.0 } else it } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt index 2d5284790..8c5355920 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarOrderHelper.kt @@ -13,6 +13,7 @@ import net.minecraft.inventory.ContainerChest import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class BazaarOrderHelper { + private val bazaarItemNamePattern = "§.§l(?<type>BUY|SELL) (?<name>.*)".toPattern() companion object { fun isBazaarOrderInventory(inventoryName: String): Boolean = when (inventoryName) { @@ -41,21 +42,16 @@ class BazaarOrderHelper { val stack = slot.stack val itemName = stack.name ?: continue - val isSelling = itemName.startsWith("§6§lSELL ") - val isBuying = itemName.startsWith("§a§lBUY ") - if (!isSelling && !isBuying) continue + val matcher = bazaarItemNamePattern.matcher(itemName) + if (!matcher.matches()) continue - val rawName = itemName.split(if (isBuying) "BUY " else "SELL ")[1] - val bazaarName = BazaarApi.getCleanBazaarName(rawName) - val data = BazaarApi.getBazaarDataByName(bazaarName) + val (isBuying, isSelling) = matcher.group("type").let { (it == "BUY") to (it == "SELL") } + if (!isBuying && !isSelling) continue + + val bazaarItemName = matcher.group("name") + val data = BazaarApi.getBazaarDataByName(bazaarItemName) if (data == null) { - LorenzUtils.debug("Bazaar data is null!") - println("Bazaar data is null for '$rawName'/'$bazaarName'") -// for (key in BazaarApi.bazaarMap.keys) { -// if (key.lowercase().contains("hay")) { -// println("key: '$key'") -// } -// } + LorenzUtils.debug("Bazaar data is null for bazaarItemName '$bazaarItemName'") continue } |