1+ /*
2+ * Skytils - Hypixel Skyblock Quality of Life Mod
3+ * Copyright (C) 2020-2024 Skytils
4+ *
5+ * This program is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU Affero General Public License as published
7+ * by the Free Software Foundation, either version 3 of the License, or
8+ * (at your option) any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU Affero General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU Affero General Public License
16+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17+ */
18+
19+ package gg.skytils.skytilsmod.features.impl.misc
20+
21+ import gg.essential.universal.UResolution
22+ import gg.skytils.skytilsmod.Skytils
23+ import gg.skytils.skytilsmod.core.GuiManager
24+ import gg.skytils.skytilsmod.core.structure.GuiElement
25+ import gg.skytils.skytilsmod.events.impl.MainReceivePacketEvent
26+ import gg.skytils.skytilsmod.utils.ItemUtil
27+ import gg.skytils.skytilsmod.utils.RenderUtil
28+ import gg.skytils.skytilsmod.utils.Utils
29+ import gg.skytils.skytilsmod.utils.graphics.ScreenRenderer
30+ import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
31+ import gg.skytils.skytilsmod.utils.graphics.colors.CommonColors
32+ import net.minecraft.init.Items
33+ import net.minecraft.item.ItemStack
34+ import net.minecraft.network.play.server.S2FPacketSetSlot
35+ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
36+
37+ object QuiverStuff {
38+ private val activeArrowRegex = Regex (" §7Active Arrow: (?<type>§.[\\ w -]+) §7\\ (§e(?<amount>\\ d+)§7\\ )" )
39+
40+ private var selectedType: String = " "
41+ private var arrowCount = - 1
42+ private var sentWarning = false
43+
44+ init {
45+ QuiverDisplay
46+ SelectedArrowDisplay
47+ }
48+
49+ @SubscribeEvent
50+ fun onReceivePacket (event : MainReceivePacketEvent <* , * >) {
51+ if (! Utils .inSkyblock || event.packet !is S2FPacketSetSlot || event.packet.func_149173_d() != 44 ) return
52+ val stack = event.packet.func_149174_e() ? : return
53+ if (! Utils .equalsOneOf(stack.item, Items .arrow, Items .feather)) return
54+ val line = ItemUtil .getItemLore(stack).getOrNull(4 ) ? : return
55+ val match = activeArrowRegex.matchEntire(line) ? : return
56+ selectedType = match.groups[" type" ]?.value ? : " "
57+ arrowCount = match.groups[" amount" ]?.value?.toIntOrNull() ? : - 1
58+
59+ if (sentWarning && Skytils .config.restockArrowsWarning != 0 && arrowCount >= Skytils .config.restockArrowsWarning) {
60+ sentWarning = false
61+ } else if (
62+ ! sentWarning && arrowCount != - 1 &&
63+ Skytils .config.restockArrowsWarning != 0 && arrowCount < Skytils .config.restockArrowsWarning
64+ ) {
65+ GuiManager .createTitle(" §c§lRESTOCK §r${selectedType.ifBlank { " §cUnknown" }} " , 60 )
66+ sentWarning = true
67+ }
68+ }
69+
70+ object QuiverDisplay : GuiElement(" Quiver Display" , x = 0.05f , y = 0.4f ) {
71+ private val arrowItem = ItemStack (Items .arrow, 1 , 0 )
72+
73+ override fun render () {
74+ if (! toggled || ! Utils .inSkyblock) return
75+
76+ val color = when {
77+ arrowCount < 400 -> CommonColors .RED
78+ arrowCount < 1200 -> CommonColors .YELLOW
79+ else -> CommonColors .GREEN
80+ }
81+
82+ RenderUtil .renderItem(arrowItem, 0 , 0 )
83+ ScreenRenderer .fontRenderer.drawString(
84+ if (arrowCount == - 1 ) " ???" else arrowCount.toString(),
85+ 20f ,
86+ 5f ,
87+ color,
88+ SmartFontRenderer .TextAlignment .LEFT_RIGHT ,
89+ textShadow
90+ )
91+ }
92+
93+ override fun demoRender () {
94+ RenderUtil .renderItem(arrowItem, 0 , 0 )
95+ ScreenRenderer .fontRenderer.drawString(
96+ " 2000" , 20f , 5f , CommonColors .GREEN , SmartFontRenderer .TextAlignment .LEFT_RIGHT , textShadow
97+ )
98+ }
99+
100+ override val height: Int
101+ get() = 16
102+ override val width: Int
103+ get() = 20 + ScreenRenderer .fontRenderer.getStringWidth(" 2000" )
104+
105+ override val toggled: Boolean
106+ get() = Skytils .config.quiverDisplay
107+
108+ init {
109+ Skytils .guiManager.registerElement(this )
110+ }
111+ }
112+
113+ object SelectedArrowDisplay : GuiElement(" Selected Arrow Display" , x = 0.65f , y = 0.85f ) {
114+ override fun render () {
115+ if (! toggled || ! Utils .inSkyblock) return
116+ val alignment =
117+ if (scaleX < UResolution .scaledWidth / 2f ) SmartFontRenderer .TextAlignment .LEFT_RIGHT else SmartFontRenderer .TextAlignment .RIGHT_LEFT
118+ val text = " Selected: §r${selectedType.ifBlank { " §cUnknown" }} "
119+
120+ ScreenRenderer .fontRenderer.drawString(
121+ text,
122+ if (scaleX < UResolution .scaledWidth / 2f ) 0f else width.toFloat(),
123+ 0f ,
124+ CommonColors .GREEN ,
125+ alignment,
126+ SmartFontRenderer .TextShadow .NORMAL
127+ )
128+
129+ }
130+
131+ override fun demoRender () {
132+ val alignment =
133+ if (scaleX < UResolution .scaledWidth / 2f ) SmartFontRenderer .TextAlignment .LEFT_RIGHT else SmartFontRenderer .TextAlignment .RIGHT_LEFT
134+ ScreenRenderer .fontRenderer.drawString(
135+ " Selected: Redstone-tipped Arrow" ,
136+ if (scaleX < UResolution .scaledWidth / 2f ) 0f else width.toFloat(),
137+ 0f ,
138+ CommonColors .GREEN ,
139+ alignment,
140+ SmartFontRenderer .TextShadow .NORMAL
141+ )
142+ }
143+
144+ override val height: Int
145+ get() = ScreenRenderer .fontRenderer.FONT_HEIGHT
146+ override val width: Int
147+ get() = ScreenRenderer .fontRenderer.getStringWidth(" Selected: Redstone-tipped Arrow" )
148+ override val toggled: Boolean
149+ get() = Skytils .config.showSelectedArrowDisplay
150+
151+ init {
152+ Skytils .guiManager.registerElement(this )
153+ }
154+ }
155+ }
0 commit comments