blob: eae5215ba4e6a28e724a3608d1816a275331237b (
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
package at.hannibal2.skyhanni.features.bingo
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.bingo.card.CommunityGoal
import at.hannibal2.skyhanni.features.bingo.card.PersonalGoal
import at.hannibal2.skyhanni.utils.InventoryUtils.getInventoryName
import at.hannibal2.skyhanni.utils.ItemUtils
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.RenderUtils.renderStrings
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiChat
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.inventory.ContainerChest
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import java.util.regex.Pattern
class BingoCardDisplay {
private val MAX_PERSONAL_GOALS = 20
private val MAX_COMMUNITY_GOALS = 5
private var tick = 0
private var display = listOf<String>()
private val config get() = SkyHanniMod.feature.bingo
private val goalCompletePattern = Pattern.compile("§6§lBINGO GOAL COMPLETE! §r§e(.*)")
init {
update()
}
companion object {
val personalGoals = mutableListOf<PersonalGoal>()
private val communityGoals = mutableListOf<CommunityGoal>()
private var dirty = true
fun command() {
reload()
}
private fun reload() {
personalGoals.clear()
communityGoals.clear()
dirty = true
}
}
@SubscribeEvent
fun onTick(event: TickEvent.ClientTickEvent) {
if (!LorenzUtils.isBingoProfile) return
if (!config.cardDisplay) return
if (event.phase != TickEvent.Phase.START) return
tick++
if (tick % 5 != 0) return
val gui = Minecraft.getMinecraft().currentScreen
if (gui !is GuiChest) {
dirty = true
return
}
val chest = gui.inventorySlots as ContainerChest
if (chest.getInventoryName() == "Bingo Card") {
if (dirty) {
readBingoCard(gui)
}
}
}
private fun readBingoCard(gui: GuiChest) {
personalGoals.clear()
communityGoals.clear()
for (slot in gui.inventorySlots.inventorySlots) {
val stack = slot?.stack ?: continue
val personalGoal = stack.getLore().any { it.endsWith("Personal Goal") }
val communityGoal = stack.getLore().any { it.endsWith("Community Goal") }
if (!personalGoal && !communityGoal) continue
val name = stack.name?.removeColor() ?: continue
val lore = stack.getLore()
var index = 0
val builder = StringBuilder()
for (s in lore) {
if (index > 1) {
if (s == "") break
builder.append(s)
builder.append(" ")
}
index++
}
var description = builder.toString()
if (description.endsWith(" ")) {
description = description.substring(0, description.length - 1)
}
if (description.startsWith("§7§7")) {
description = description.substring(2)
}
val done = stack.getLore().any { it.contains("GOAL REACHED") }
if (personalGoal) {
personalGoals.add(PersonalGoal(name, description, done))
} else {
communityGoals.add(CommunityGoal(name, description, done))
}
}
val a = personalGoals.size
val b = communityGoals.size
if (a == MAX_PERSONAL_GOALS && b == MAX_COMMUNITY_GOALS) {
dirty = false
update()
}
}
private fun update() {
display = drawDisplay()
}
private fun drawDisplay(): MutableList<String> {
val newList = mutableListOf<String>()
newList.add("Community Goals")
if (communityGoals.isEmpty()) {
newList.add("§cOpen the §e/bingo §ccard.")
} else {
communityGoals.mapTo(newList) { " " + it.description + if (it.done) " §aDONE" else "" }
val todo = personalGoals.filter { !it.done }
val done = MAX_PERSONAL_GOALS - todo.size
newList.add(" ")
newList.add("Personal Goals: ($done/$MAX_PERSONAL_GOALS done)")
todo.mapTo(newList) { " " + it.description }
}
return newList
}
private var lastSneak = false
private var displayMode = 0
@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) {
if (!LorenzUtils.isBingoProfile) return
if (!config.cardDisplay) return
val stack = Minecraft.getMinecraft().thePlayer.heldItem //TODO into ItemUtils or InventoryUtils
if (ItemUtils.isSkyBlockMenuItem(stack)) {
val sneaking = Minecraft.getMinecraft().thePlayer.isSneaking
if (lastSneak != sneaking) {
lastSneak = sneaking
if (sneaking) {
displayMode++
if (displayMode == 3) {
displayMode = 0
}
}
}
}
if (!config.stepHelper && displayMode == 1) {
displayMode = 2
}
if (displayMode == 0) {
if (Minecraft.getMinecraft().currentScreen !is GuiChat) {
config.bingoCardPos.renderStrings(display, posLabel = "Bingo Card")
}
} else if (displayMode == 1) {
config.bingoCardPos.renderStrings(BingoNextStepHelper.currentHelp, posLabel = "Bingo Card")
}
}
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!LorenzUtils.isBingoProfile) return
if (!config.cardDisplay) return
val matcher = goalCompletePattern.matcher(event.message)
if (matcher.matches()) {
val name = matcher.group(1)
personalGoals.filter { it.displayName == name }
.forEach {
it.done = true
update()
}
}
}
}
|