blob: eec055253f84945d207220013cb91cddc8e4c58f (
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
81
82
83
84
85
86
87
|
package at.hannibal2.skyhanni.bazaar
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.inventory.ContainerChest
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.lwjgl.opengl.GL11
class BazaarOrderHelper {
companion object {
fun isBazaarOrderInventory(inventoryName: String): Boolean = when (inventoryName) {
"Your Bazaar Orders" -> true
"Co-op Bazaar Orders" -> true
else -> false
}
}
@SubscribeEvent
fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) {
if (!SkyHanniMod.feature.bazaar.orderHelper) return
if (event.gui !is GuiChest) return
val guiChest = event.gui
val chest = guiChest.inventorySlots as ContainerChest
val inventoryName = chest.lowerChestInventory.displayName.unformattedText.trim()
if (!isBazaarOrderInventory(inventoryName)) return
val lightingState = GL11.glIsEnabled(GL11.GL_LIGHTING)
GlStateManager.disableLighting()
GlStateManager.color(1f, 1f, 1f, 1f)
out@ 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
val isSelling = displayName.startsWith("§6§lSELL§7: ")
val isBuying = displayName.startsWith("§a§lBUY§7: ")
if (!isSelling && !isBuying) continue
val text = displayName.split("§7: ")[1]
val name = BazaarApi.getCleanBazaarName(text)
val data = BazaarApi.getBazaarDataForName(name)
val buyPrice = data.buyPrice
val sellPrice = data.sellPrice
val itemLore = stack.getLore()
for (line in itemLore) {
if (line.startsWith("§7Filled:")) {
if (line.endsWith(" §a§l100%!")) {
slot highlight LorenzColor.GREEN
continue@out
}
}
}
for (line in itemLore) {
if (line.startsWith("§7Price per unit:")) {
var text = line.split(": §6")[1]
text = text.substring(0, text.length - 6)
text = text.replace(",", "")
val price = text.toDouble()
if (isSelling) {
if (buyPrice < price) {
slot highlight LorenzColor.GOLD
continue@out
}
} else {
if (sellPrice > price) {
slot highlight LorenzColor.GOLD
continue@out
}
}
}
}
}
if (lightingState) GlStateManager.enableLighting()
}
}
|