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 | |
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.
11 files changed, 228 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 5daad2cb2..8919635e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Features + Added **Time to Kill** - Show the time it takes to kill the Slayer boss. +### Garden Features ++ Added **Copper Price** - Show copper to coin prices inside the Sky Mart inventory. + ### Features from other Mods > *The following features are only there because I want them when testing SkyHanni features without other mods present.* + Added Hide explosions. diff --git a/FEATURES.md b/FEATURES.md index c64fef4c2..724f58dc3 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -156,13 +156,16 @@ + Area boss spawn timer. + Corleone highlighter. + Zealots, Bruisers and Special Zealot highlighter. -- Highlight corrupted mobs. ++ Highlight corrupted mobs. + +## Garden Features ++ **Copper Price** - Show copper to coin prices inside the Sky Mart inventory. ## Commands - /wiki (using hypixel-skyblock.fandom.com instead of Hypixel wiki) - /shmarkplayer <player> (marking a player with yellow color) - /shtrackcollection <item> - This tracks the number of items you collect, but it does not work with sacks. -- + ## Misc - Allow to copy, paste, and mark selected text in signs (not visual, but it's working still) - Pet Display (showing the currently selected pet as GUI element, without any fancy XP or level or percentage, but with auto-pet support) diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index e83191ceb..998185755 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -23,6 +23,7 @@ import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowHelper; import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowParticleFinder; import at.hannibal2.skyhanni.features.event.diana.SoopyGuessBurrow; import at.hannibal2.skyhanni.features.fishing.*; +import at.hannibal2.skyhanni.features.garden.SkyMartBestProfit; import at.hannibal2.skyhanni.features.inventory.*; import at.hannibal2.skyhanni.features.itemabilities.FireVeilWandParticles; import at.hannibal2.skyhanni.features.itemabilities.abilitycooldown.ItemAbilityCooldown; @@ -108,6 +109,7 @@ public class SkyHanniMod { loadModule(new ItemTipHelper()); loadModule(new RenderLivingEntityHelper()); loadModule(new SkillExperience()); + loadModule(new InventoryData()); //features loadModule(new BazaarOrderHelper()); @@ -194,6 +196,7 @@ public class SkyHanniMod { loadModule(new TpsCounter()); loadModule(new ParticleHider()); loadModule(new MiscFeatures()); + loadModule(new SkyMartBestProfit()); Commands.INSTANCE.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index f0a830624..633bc66c6 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -136,6 +136,11 @@ public class Features extends Config { editOverlay(activeConfigCategory, 200, 16, misc.tpsDisplayPosition); return; } + + if (runnableId.equals("skyMartCopperPrice")) { + editOverlay(activeConfigCategory, 200, 16, garden.skyMartCopperPricePos); + return; + } } @Expose @@ -203,6 +208,10 @@ public class Features extends Config { public Mobs mobs = new Mobs(); @Expose + @Category(name = "Garden", desc = "Features on the Garden island.") + public Garden garden = new Garden(); + + @Expose @Category(name = "Misc", desc = "Settings without a category.") public Misc misc = new Misc(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java new file mode 100644 index 000000000..9dec32d73 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -0,0 +1,25 @@ +package at.hannibal2.skyhanni.config.features; + +import at.hannibal2.skyhanni.config.core.config.Position; +import at.hannibal2.skyhanni.config.core.config.annotations.*; +import com.google.gson.annotations.Expose; + +public class Garden { + + @Expose + @ConfigOption(name = "Sky Mart", desc = "") + @ConfigEditorAccordion(id = 0) + public boolean skyMart = false; + + @Expose + @ConfigOption(name = "Copper Price", desc = "Show copper to coin prices inside the Sky Mart inventory.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 0) + public boolean skyMartCopperPrice = true; + + @Expose + @ConfigOption(name = "Copper Price Position", desc = "") + @ConfigEditorButton(runnableId = "skyMartCopperPrice", buttonText = "Edit") + @ConfigAccordionId(id = 0) + public Position skyMartCopperPricePos = new Position(44, -108, false, true); +} diff --git a/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt b/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt new file mode 100644 index 000000000..3495f2177 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/InventoryData.kt @@ -0,0 +1,72 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.events.InventoryCloseEvent +import at.hannibal2.skyhanni.events.InventoryOpenEvent +import at.hannibal2.skyhanni.events.PacketEvent +import net.minecraft.item.ItemStack +import net.minecraft.network.play.server.S2DPacketOpenWindow +import net.minecraft.network.play.server.S2FPacketSetSlot +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class InventoryData { + private var currentInventory: Inventory? = null + + @SubscribeEvent + fun onCloseWindow(event: GuiContainerEvent.CloseWindowEvent) { + close() + } + + private fun close() { + currentInventory?.let { + InventoryCloseEvent(it).postAndCatch() + currentInventory = null + } + } + + @SubscribeEvent + fun onChatPacket(event: PacketEvent.ReceiveEvent) { + val packet = event.packet + + if (packet is S2DPacketOpenWindow) { + val windowId = packet.windowId + val title = packet.windowTitle.unformattedText + val slotCount = packet.slotCount + close() + + currentInventory = Inventory(windowId, title, slotCount) + } + + if (packet is S2FPacketSetSlot) { + currentInventory?.let { + if (it.windowId != packet.func_149175_c()) return + + val slot = packet.func_149173_d() + if (slot < it.slotCount) { + val itemStack = packet.func_149174_e() + if (itemStack != null) { + it.items[slot] = itemStack + } + } else { + done(it) + return + } + + if (it.items.size == it.slotCount) { + done(it) + } + } + } + } + + private fun done(inventory: Inventory) { + InventoryOpenEvent(inventory).postAndCatch() + } + + class Inventory( + val windowId: Int, + val title: String, + val slotCount: Int, + val items: MutableMap<Int, ItemStack> = mutableMapOf() + ) +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt new file mode 100644 index 000000000..8ff1f481b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/InventoryCloseEvent.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.events + +import at.hannibal2.skyhanni.data.InventoryData + +class InventoryCloseEvent(val inventory: InventoryData.Inventory): LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt new file mode 100644 index 000000000..50387fa18 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/InventoryOpenEvent.kt @@ -0,0 +1,5 @@ +package at.hannibal2.skyhanni.events + +import at.hannibal2.skyhanni.data.InventoryData + +class InventoryOpenEvent(val inventory: InventoryData.Inventory): LorenzEvent()
\ No newline at end of file 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 diff --git a/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt b/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt index 7a5a44919..7adb36150 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/PacketTest.kt @@ -78,15 +78,17 @@ class PacketTest { // Entity if (packetName == "S13PacketDestroyEntities") return + + if (packetName == "S18PacketEntityTeleport") return + if (packetName == "S15PacketEntityRelMove") return + if (packetName == "S04PacketEntityEquipment") return + // if (packetName == "S0EPacketSpawnObject") return -// if (packetName == "S18PacketEntityTeleport") return // if (packetName == "S0BPacketAnimation") return // if (packetName == "S06PacketUpdateHealth") return // if (packetName == "S17PacketEntityLookMove") return -// if (packetName == "S15PacketEntityRelMove") return // if (packetName == "S16PacketEntityLook") return // if (packetName == "S19PacketEntityHeadLook") return -// if (packetName == "S04PacketEntityEquipment") return // if (packetName == "S1DPacketEntityEffect") return // if (packetName == "S12PacketEntityVelocity") return // if (packetName == "S19PacketEntityStatus") return @@ -119,7 +121,7 @@ class PacketTest { println("entity is null.") } - println("distance: $distance") +// println("distance: $distance") println("Receive: $packetName") println(" ") } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index ca79b2418..a72483cb1 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -460,7 +460,7 @@ object RenderUtils { if (list.isEmpty()) return var offsetY = 0 - for (s in list) { + for (s in list.toMutableList()) { renderString(s, offsetY = offsetY, center = center) offsetY += 10 + extraSpace } |