diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-02-16 20:31:04 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-02-16 20:31:04 +0100 |
commit | 07351036391533533cd059ef6910c6bc1efeb36f (patch) | |
tree | 723c655ac358227b98548a4e81f1eafd00636265 /src/main/java/at/hannibal2/skyhanni/features/garden | |
parent | 67011d64534f855959ab33abc56e83eec713e924 (diff) | |
download | skyhanni-07351036391533533cd059ef6910c6bc1efeb36f.tar.gz skyhanni-07351036391533533cd059ef6910c6bc1efeb36f.tar.bz2 skyhanni-07351036391533533cd059ef6910c6bc1efeb36f.zip |
Show copper to coin prices inside the Sky Mart inventory.
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/garden')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt new file mode 100644 index 000000000..8e9cc3dfa --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/SkyMartBestProfit.kt @@ -0,0 +1,94 @@ +package at.hannibal2.skyhanni.features.garden + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.IslandType +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent +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.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.sortedDesc +import at.hannibal2.skyhanni.utils.NumberUtil +import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import io.github.moulberry.notenoughupdates.NotEnoughUpdates +import net.minecraft.client.Minecraft +import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.util.regex.Pattern + +class SkyMartBestProfit { + + private val display = mutableListOf<String>() + + @SubscribeEvent + fun onChatPacket(event: InventoryOpenEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!SkyHanniMod.feature.garden.skyMartCopperPrice) return + if (LorenzUtils.skyBlockIsland != IslandType.GARDEN) return + + val inventory = event.inventory + if (inventory.title != "SkyMart") return + + val pattern = Pattern.compile("§c(.*) Copper") + val priceMap = mutableMapOf<Pair<String, String>, Double>() + + val auctionManager = NotEnoughUpdates.INSTANCE.manager.auctionManager + for (stack in inventory.items.values) { + for (line in stack.getLore()) { + val matcher = pattern.matcher(line) + if (!matcher.matches()) continue + + val internalName = stack.getInternalName() + val lowestBin = auctionManager.getBazaarOrBin(internalName, false) + if (lowestBin == -1.0) continue + + val amount = matcher.group(1).replace(",", "").toInt() + val factor = lowestBin / amount + val perFormat = NumberUtil.format(factor) + val priceFormat = NumberUtil.format(lowestBin) + val amountFormat = NumberUtil.format(amount) + + var name = stack.name!! + if (name == "§fEnchanted Book") { + name = "§9Sunder I" + } + + val pair = Pair("$name§f:", "§6§l$perFormat §f(§6$priceFormat coins §f/ §c$amountFormat copper§f)") + priceMap[pair] = factor + } + } + + display.clear() + + display.add("Coins per §ccopper") + display.add(" ") + + val keys = priceMap.sortedDesc().keys + val renderer = Minecraft.getMinecraft().fontRendererObj + val longest = keys.map { it.first }.maxOfOrNull { renderer.getStringWidth(it.removeColor()) } ?: 0 + + for ((first, second) in keys) { + var name = first + while (renderer.getStringWidth(name.removeColor()) < longest) { + name += " " + } + display.add("$name $second") + } + } + + @SubscribeEvent + fun onInventoryClose(event: InventoryCloseEvent) { + display.clear() + } + + @SubscribeEvent + fun onBackgroundDraw(event: GuiScreenEvent.BackgroundDrawnEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!SkyHanniMod.feature.garden.skyMartCopperPrice) return + if (LorenzUtils.skyBlockIsland != IslandType.GARDEN) return + + SkyHanniMod.feature.garden.skyMartCopperPricePos.renderStrings(display) + } +}
\ No newline at end of file |