Skip to content

Commit c263ed1

Browse files
authored
feat: Quiver Display (#449)
1 parent c548859 commit c263ed1

File tree

4 files changed

+171
-49
lines changed

4 files changed

+171
-49
lines changed

src/main/kotlin/gg/skytils/skytilsmod/Skytils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ class Skytils {
322322
PotionEffectTimers,
323323
PricePaid,
324324
ProtectItems,
325+
QuiverStuff,
325326
RainTimer,
326327
RandomStuff,
327328
RelicWaypoints,

src/main/kotlin/gg/skytils/skytilsmod/core/Config.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ object Config : Vigilant(
817817
)
818818
var creeperBeamsSolver = false
819819

820-
821820
@Property(
822821
type = PropertyType.SWITCH, name = "Ice Fill Solver",
823822
description = "§b[WIP] §rShows the path to take on the Ice Fill puzzle.",
@@ -2191,6 +2190,21 @@ object Config : Vigilant(
21912190
)
21922191
var protectStarredItems = false
21932192

2193+
@Property(
2194+
type = PropertyType.SWITCH, name = "Quiver Display",
2195+
description = "Displays the amount of arrows in your quiver.",
2196+
category = "Miscellaneous", subcategory = "Quality of Life"
2197+
)
2198+
var quiverDisplay = false
2199+
2200+
@Property(
2201+
type = PropertyType.NUMBER, name = "Restock Arrows Warning",
2202+
description = "Shows a warning when your quiver is low on arrows. Set to 0 to disable.",
2203+
category = "Miscellaneous", subcategory = "Quality of Life",
2204+
min = 0, max = 1200, increment = 100
2205+
)
2206+
var restockArrowsWarning = 0
2207+
21942208
@Property(
21952209
type = PropertyType.SWITCH, name = "Spider's Den Rain Timer",
21962210
description = "Shows the duration of rain in the Spider's Den.",

src/main/kotlin/gg/skytils/skytilsmod/features/impl/misc/ItemFeatures.kt

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,13 @@ object ItemFeatures {
9595
val bitCosts = HashMap<String, Int>()
9696
val copperCosts = HashMap<String, Int>()
9797
val hotbarRarityCache = arrayOfNulls<ItemRarity>(9)
98-
var selectedArrow = ""
9998
var soulflowAmount = ""
10099
var stackingEnchantDisplayText = ""
101100
var lowSoulFlowPinged = false
102101
var lastShieldUse = -1L
103102
var lastShieldClick = 0L
104103

105104
init {
106-
SelectedArrowDisplay()
107105
StackingEnchantDisplay()
108106
SoulflowGuiElement()
109107
WitherShieldDisplay()
@@ -452,11 +450,6 @@ object ItemFeatures {
452450
val extraAttr = getExtraAttributes(item) ?: return
453451
val itemId = getSkyBlockItemID(extraAttr) ?: return
454452

455-
if (itemId == "ARROW_SWAPPER") {
456-
selectedArrow = getItemLore(item).find {
457-
it.startsWith("§aSelected: §")
458-
}?.substringAfter("§aSelected: ") ?: "§cUnknown"
459-
}
460453
if (equalsOneOf(itemId, "SOULFLOW_PILE", "SOULFLOW_BATTERY", "SOULFLOW_SUPERCELL")) {
461454
getItemLore(item).find {
462455
it.startsWith("§7Internalized: ")
@@ -769,47 +762,6 @@ object ItemFeatures {
769762
}
770763
}
771764

772-
class SelectedArrowDisplay : GuiElement("Arrow Swapper Display", x = 0.65f, y = 0.85f) {
773-
override fun render() {
774-
if (toggled && Utils.inSkyblock) {
775-
val alignment =
776-
if (scaleX < UResolution.scaledWidth / 2f) TextAlignment.LEFT_RIGHT else TextAlignment.RIGHT_LEFT
777-
ScreenRenderer.fontRenderer.drawString(
778-
selectedArrow,
779-
if (scaleX < UResolution.scaledWidth / 2f) 0f else width.toFloat(),
780-
0f,
781-
CommonColors.WHITE,
782-
alignment,
783-
TextShadow.NORMAL
784-
)
785-
}
786-
}
787-
788-
override fun demoRender() {
789-
val alignment =
790-
if (scaleX < UResolution.scaledWidth / 2f) TextAlignment.LEFT_RIGHT else TextAlignment.RIGHT_LEFT
791-
ScreenRenderer.fontRenderer.drawString(
792-
"§aSelected: §rSkytils Arrow",
793-
if (scaleX < UResolution.scaledWidth / 2f) 0f else width.toFloat(),
794-
0f,
795-
CommonColors.RAINBOW,
796-
alignment,
797-
TextShadow.NORMAL
798-
)
799-
}
800-
801-
override val height: Int
802-
get() = ScreenRenderer.fontRenderer.FONT_HEIGHT
803-
override val width: Int
804-
get() = ScreenRenderer.fontRenderer.getStringWidth("§aSelected: §rSkytils Arrow")
805-
override val toggled: Boolean
806-
get() = Skytils.config.showSelectedArrowDisplay
807-
808-
init {
809-
Skytils.guiManager.registerElement(this)
810-
}
811-
}
812-
813765
class StackingEnchantDisplay : GuiElement("Stacking Enchant Display", x = 0.65f, y = 0.85f) {
814766
override fun render() {
815767
if (toggled && Utils.inSkyblock && stackingEnchantDisplayText.isNotBlank()) {
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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

Comments
 (0)