blob: 6a42fe214e74f22bc1959a5efafc515555d7b1fd (
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
88
89
90
91
92
|
package at.hannibal2.skyhanni.features.bazaar
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiContainerEvent
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
import net.minecraft.inventory.Slot
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class BazaarOrderHelper {
private val patternGroup = RepoPattern.group("bazaar.orderhelper")
private val bazaarItemNamePattern by patternGroup.pattern(
"itemname",
"§.§l(?<type>BUY|SELL) (?<name>.*)"
)
private val filledPattern by patternGroup.pattern(
"filled",
"§7Filled: §[a6].*§7/.* §a§l100%!"
)
private val pricePattern by patternGroup.pattern(
"price",
"§7Price per unit: §6(?<number>.*) coins"
)
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 (!LorenzUtils.inSkyBlock) return
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.getInventoryName()
if (!isBazaarOrderInventory(inventoryName)) return
for (slot in chest.inventorySlots) {
if (slot == null) continue
if (slot.slotNumber != slot.slotIndex) continue
if (slot.stack == null) continue
val itemName = slot.stack.name ?: continue
bazaarItemNamePattern.matchMatcher(itemName) {
val buyOrSell = group("type").let { (it == "BUY") to (it == "SELL") }
if (buyOrSell.let { !it.first && !it.second }) return
highlightItem(group("name"), slot, buyOrSell)
}
}
}
private fun highlightItem(itemName: String, slot: Slot, buyOrSell: Pair<Boolean, Boolean>) {
val data = BazaarApi.getBazaarDataByName(itemName)
if (data == null) {
ChatUtils.debug("Bazaar data is null for bazaarItemName '$itemName'")
return
}
val itemLore = slot.stack.getLore()
for (line in itemLore) {
filledPattern.matchMatcher(line) {
slot highlight LorenzColor.GREEN
return
}
pricePattern.matchMatcher(line) {
val price = group("number").replace(",", "").toDouble()
if (buyOrSell.first && price < data.sellPrice || buyOrSell.second && price > data.buyPrice) {
slot highlight LorenzColor.GOLD
return
}
}
}
}
}
|