diff options
author | Lorenz <ESs95s3P5z8Pheb> | 2022-07-15 13:40:01 +0200 |
---|---|---|
committer | Lorenz <ESs95s3P5z8Pheb> | 2022-07-15 13:40:01 +0200 |
commit | 7ccc7c7ca5e6323a44694adadb8f6f3b77a687ba (patch) | |
tree | 34678795e621dae07d6d1ee61c704ea7dbf4f3aa | |
parent | c56bf3fe55ac2d93be20ba042996fc6ebdd51e5c (diff) | |
download | skyhanni-7ccc7c7ca5e6323a44694adadb8f6f3b77a687ba.tar.gz skyhanni-7ccc7c7ca5e6323a44694adadb8f6f3b77a687ba.tar.bz2 skyhanni-7ccc7c7ca5e6323a44694adadb8f6f3b77a687ba.zip |
add bazaar best sell method
3 files changed, 96 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index b100e5b36..71f7c736c 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni; import at.hannibal2.skyhanni.bazaar.BazaarApi; +import at.hannibal2.skyhanni.bazaar.BazaarBestSellMethod; import at.hannibal2.skyhanni.bazaar.BazaarOrderHelper; import at.hannibal2.skyhanni.chat.ChatFilter; import at.hannibal2.skyhanni.chat.ChatManager; @@ -67,6 +68,7 @@ public class SkyHanniMod { MinecraftForge.EVENT_BUS.register(new DungeonCleanEnd()); MinecraftForge.EVENT_BUS.register(new DungeonBossMessages()); MinecraftForge.EVENT_BUS.register(new TrophyFishMessages()); + MinecraftForge.EVENT_BUS.register(new BazaarBestSellMethod()); Commands.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/bazaar/BazaarBestSellMethod.kt new file mode 100644 index 000000000..56c264312 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/bazaar/BazaarBestSellMethod.kt @@ -0,0 +1,79 @@ +package at.hannibal2.skyhanni.bazaar + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.utils.GuiRender.renderString +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.inventory.ContainerChest +import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class BazaarBestSellMethod { + + companion object { + private var textToRender = "" + } + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.CloseWindowEvent) { + textToRender = "" + } + + @SubscribeEvent + fun onGuiDrawEvent(event: GuiScreenEvent.DrawScreenEvent.Post) { + if (!isEnabled()) return + textToRender = getNewText(event) + } + + private fun getNewText(event: GuiScreenEvent.DrawScreenEvent.Post): String { + try { + if (event.gui !is GuiChest) return "" + val chest = (event.gui as GuiChest).inventorySlots as ContainerChest + + val inv = chest.lowerChestInventory ?: return "" + + 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.getBazaarDataForName(name) + + var having = 0 + for (slot in chest.inventorySlots) { + if (slot == null) continue + if (slot.slotNumber == slot.slotIndex) continue + if (slot.stack == null) continue + val stack = slot.stack + val displayName = stack.displayName + if (BazaarApi.getCleanBazaarName(displayName) == name) { + having += stack.stackSize + } + } + + if (having <= 0) return "" + + val totalDiff = (data.buyPrice - data.sellPrice) * having + val result = NumberUtil.format(totalDiff.toInt()) + + return "§b$name§f sell difference: §e$result coins" + } catch (e: Error) { + e.printStackTrace() + return "" + } + } + + @SubscribeEvent(priority = EventPriority.LOWEST) + fun renderOverlay(event: GuiScreenEvent.BackgroundDrawnEvent) { + if (!isEnabled()) return + + SkyHanniMod.feature.bazaar.bestSellMethodPos.renderString(textToRender) + } + + private fun isEnabled(): Boolean { + return LorenzUtils.inSkyblock && SkyHanniMod.feature.bazaar.bestSellMethod + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index 33332deaf..252b456d7 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -45,6 +45,11 @@ public class Features { editOverlay(activeConfigCategory, 200, 16, dungeon.deathCounterDisplay); return; } + + if (runnableId.equals("bestSellMethod")) { + editOverlay(activeConfigCategory, 200, 16, bazaar.bestSellMethodPos); + return; + } } @Expose @@ -241,6 +246,16 @@ public class Features { @ConfigOption(name = "Order Helper", desc = "Show visual hints inside the Bazaar Manage Order view when items are ready to pickup or outbid.") @ConfigEditorBoolean public boolean orderHelper = false; + + @Expose + @ConfigOption(name = "Best Sell Method", desc = "Difference between sell instantly and sell offer.") + @ConfigEditorBoolean + public boolean bestSellMethod = false; + + @Expose + @ConfigOption(name = "Best Sell Method Position", desc = "") + @ConfigEditorButton(runnableId = "bestSellMethod", buttonText = "Edit") + public Position bestSellMethodPos = new Position(10, 10, false, true); } public static class Fishing { |