blob: 55239442fa26c9786f35525d6ee09aad5b6b9082 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
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.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
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 {
private var display = ""
@SubscribeEvent
fun onInventoryClose(event: InventoryCloseEvent) {
display = ""
}
@SubscribeEvent
fun onGuiDraw(event: GuiScreenEvent.DrawScreenEvent.Post) {
if (!isEnabled()) return
display = 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) ?: 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) {
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(display, posLabel = "Bazaar Best Sell Method")
}
private fun isEnabled(): Boolean {
return LorenzUtils.inSkyBlock && SkyHanniMod.feature.bazaar.bestSellMethod
}
}
|