diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
9 files changed, 56 insertions, 59 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 } diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt index ed95ee8b4..78eb2bcaa 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/AnitaMedalProfit.kt @@ -8,7 +8,7 @@ import at.hannibal2.skyhanni.features.garden.visitor.GardenVisitorFeatures import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.name +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.NEUItems @@ -64,16 +64,12 @@ class AnitaMedalProfit { } private fun readItem(item: ItemStack, table: MutableMap<Pair<String, String>, Pair<Double, String>>) { - var itemName = item.name ?: return + val itemName = item.nameWithEnchantment ?: return if (itemName == " ") return if (itemName == "§cClose") return if (itemName == "§eUnique Gold Medals") return if (itemName == "§aMedal Trades") return - if (itemName.endsWith("Enchanted Book")) { - itemName = item.getLore()[0] - } - val fullCost = getFullCost(getRequiredItems(item)) if (fullCost < 0) return diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt index 1c0ab2b47..979f7d6b8 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/farming/CropMoneyDisplay.kt @@ -90,10 +90,8 @@ class CropMoneyDisplay { var extraNetherWartPrices = 0.0 GardenAPI.cropInHand?.let { - val heldItem = Minecraft.getMinecraft().thePlayer.heldItem - val reforgeName = heldItem.getReforgeName() - val bountiful = reforgeName == "bountiful" - toolHasBountiful[it] = bountiful + val reforgeName = Minecraft.getMinecraft().thePlayer.heldItem?.getReforgeName() + toolHasBountiful[it] = reforgeName == "bountiful" if (GardenAPI.mushroomCowPet && it != CropType.MUSHROOM) { if (!GardenCropMilestoneDisplay.mushroom_cow_nether_warts || it != CropType.NETHER_WART) { 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 946d40884..4aa36fd23 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 @@ -7,7 +7,7 @@ import at.hannibal2.skyhanni.events.InventoryOpenEvent import at.hannibal2.skyhanni.features.garden.GardenAPI import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.ItemUtils.getLore -import at.hannibal2.skyhanni.utils.ItemUtils.name +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.NEUItems @@ -47,11 +47,7 @@ class SkyMartCopperPrice { val priceFormat = NumberUtil.format(lowestBin) val amountFormat = NumberUtil.format(amount) - var name = stack.name!! - if (name == "§fEnchanted Book") { - name = stack.getLore()[0] - } - + val name = stack.nameWithEnchantment!! val advancedStats = if (config.skyMartCopperPriceAdvancedStats) { " §7(§6$priceFormat §7/ §c$amountFormat Copper§7)" } else "" diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 049caf3d1..83f3bd060 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -138,6 +138,18 @@ object ItemUtils { setStackDisplayName(value) } + val ItemStack.nameWithEnchantment: String? + get() { + val name = name + name?.let { + if (name.endsWith("Enchanted Book")) { + return getLore()[0] + } + } + + return name + } + fun isSkyBlockMenuItem(stack: ItemStack?): Boolean = stack?.getInternalName() == "SKYBLOCK_MENU" private val patternInFront = Pattern.compile("(?: *§8(?<amount>[\\d,]+)x )?(?<name>.*)") diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt index 5a2f1dc3a..71bcc2f09 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.utils import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal import io.github.moulberry.notenoughupdates.NEUManager import io.github.moulberry.notenoughupdates.NotEnoughUpdates import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe @@ -19,6 +20,7 @@ object NEUItems { private val itemNameCache = mutableMapOf<String, String>() // item name -> internal name private val multiplierCache = mutableMapOf<String, Pair<String, Int>>() private val recipesCache = mutableMapOf<String, Set<NeuRecipe>>() + private val turboBookPattern = "§fTurbo-(?<name>.*) (?<level>.)".toPattern() fun getInternalName(itemName: String): String { return getInternalNameOrNull(itemName) ?: throw Error("getInternalName is null for '$itemName'") @@ -28,7 +30,16 @@ object NEUItems { if (itemNameCache.containsKey(itemName)) { return itemNameCache[itemName]!! } - var internalName = ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null + + val matcher = turboBookPattern.matcher(itemName) + var internalName = if (matcher.matches()) { + val type = matcher.group("name") + val level = matcher.group("level").romanToDecimal() + val name = turboCheck(type).uppercase() + "TURBO_$name;$level" + } else { + ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null + } // This fixes a NEU bug with §9Hay Bale (cosmetic item) // TODO remove workaround when this is fixed in neu @@ -40,6 +51,12 @@ object NEUItems { return internalName } + private fun turboCheck(text: String): String { + if (text == "Cocoa") return "Coco" + if (text == "Cacti") return "Cactus" + return text + } + fun getInternalName(itemStack: ItemStack): String { return ItemResolutionQuery(manager) .withCurrentGuiContext() |