Skip to content

Commit

Permalink
feat: Quiver Display (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
TakoTheDev authored Mar 12, 2024
1 parent c548859 commit c263ed1
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 49 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/gg/skytils/skytilsmod/Skytils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class Skytils {
PotionEffectTimers,
PricePaid,
ProtectItems,
QuiverStuff,
RainTimer,
RandomStuff,
RelicWaypoints,
Expand Down
16 changes: 15 additions & 1 deletion src/main/kotlin/gg/skytils/skytilsmod/core/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,6 @@ object Config : Vigilant(
)
var creeperBeamsSolver = false


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

@Property(
type = PropertyType.SWITCH, name = "Quiver Display",
description = "Displays the amount of arrows in your quiver.",
category = "Miscellaneous", subcategory = "Quality of Life"
)
var quiverDisplay = false

@Property(
type = PropertyType.NUMBER, name = "Restock Arrows Warning",
description = "Shows a warning when your quiver is low on arrows. Set to 0 to disable.",
category = "Miscellaneous", subcategory = "Quality of Life",
min = 0, max = 1200, increment = 100
)
var restockArrowsWarning = 0

@Property(
type = PropertyType.SWITCH, name = "Spider's Den Rain Timer",
description = "Shows the duration of rain in the Spider's Den.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,13 @@ object ItemFeatures {
val bitCosts = HashMap<String, Int>()
val copperCosts = HashMap<String, Int>()
val hotbarRarityCache = arrayOfNulls<ItemRarity>(9)
var selectedArrow = ""
var soulflowAmount = ""
var stackingEnchantDisplayText = ""
var lowSoulFlowPinged = false
var lastShieldUse = -1L
var lastShieldClick = 0L

init {
SelectedArrowDisplay()
StackingEnchantDisplay()
SoulflowGuiElement()
WitherShieldDisplay()
Expand Down Expand Up @@ -452,11 +450,6 @@ object ItemFeatures {
val extraAttr = getExtraAttributes(item) ?: return
val itemId = getSkyBlockItemID(extraAttr) ?: return

if (itemId == "ARROW_SWAPPER") {
selectedArrow = getItemLore(item).find {
it.startsWith("§aSelected: §")
}?.substringAfter("§aSelected: ") ?: "§cUnknown"
}
if (equalsOneOf(itemId, "SOULFLOW_PILE", "SOULFLOW_BATTERY", "SOULFLOW_SUPERCELL")) {
getItemLore(item).find {
it.startsWith("§7Internalized: ")
Expand Down Expand Up @@ -769,47 +762,6 @@ object ItemFeatures {
}
}

class SelectedArrowDisplay : GuiElement("Arrow Swapper Display", x = 0.65f, y = 0.85f) {
override fun render() {
if (toggled && Utils.inSkyblock) {
val alignment =
if (scaleX < UResolution.scaledWidth / 2f) TextAlignment.LEFT_RIGHT else TextAlignment.RIGHT_LEFT
ScreenRenderer.fontRenderer.drawString(
selectedArrow,
if (scaleX < UResolution.scaledWidth / 2f) 0f else width.toFloat(),
0f,
CommonColors.WHITE,
alignment,
TextShadow.NORMAL
)
}
}

override fun demoRender() {
val alignment =
if (scaleX < UResolution.scaledWidth / 2f) TextAlignment.LEFT_RIGHT else TextAlignment.RIGHT_LEFT
ScreenRenderer.fontRenderer.drawString(
"§aSelected: §rSkytils Arrow",
if (scaleX < UResolution.scaledWidth / 2f) 0f else width.toFloat(),
0f,
CommonColors.RAINBOW,
alignment,
TextShadow.NORMAL
)
}

override val height: Int
get() = ScreenRenderer.fontRenderer.FONT_HEIGHT
override val width: Int
get() = ScreenRenderer.fontRenderer.getStringWidth("§aSelected: §rSkytils Arrow")
override val toggled: Boolean
get() = Skytils.config.showSelectedArrowDisplay

init {
Skytils.guiManager.registerElement(this)
}
}

class StackingEnchantDisplay : GuiElement("Stacking Enchant Display", x = 0.65f, y = 0.85f) {
override fun render() {
if (toggled && Utils.inSkyblock && stackingEnchantDisplayText.isNotBlank()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Skytils - Hypixel Skyblock Quality of Life Mod
* Copyright (C) 2020-2024 Skytils
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package gg.skytils.skytilsmod.features.impl.misc

import gg.essential.universal.UResolution
import gg.skytils.skytilsmod.Skytils
import gg.skytils.skytilsmod.core.GuiManager
import gg.skytils.skytilsmod.core.structure.GuiElement
import gg.skytils.skytilsmod.events.impl.MainReceivePacketEvent
import gg.skytils.skytilsmod.utils.ItemUtil
import gg.skytils.skytilsmod.utils.RenderUtil
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.graphics.ScreenRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
import gg.skytils.skytilsmod.utils.graphics.colors.CommonColors
import net.minecraft.init.Items
import net.minecraft.item.ItemStack
import net.minecraft.network.play.server.S2FPacketSetSlot
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object QuiverStuff {
private val activeArrowRegex = Regex("§7Active Arrow: (?<type>§.[\\w -]+) §7\\(§e(?<amount>\\d+)§7\\)")

private var selectedType: String = ""
private var arrowCount = -1
private var sentWarning = false

init {
QuiverDisplay
SelectedArrowDisplay
}

@SubscribeEvent
fun onReceivePacket(event: MainReceivePacketEvent<*, *>) {
if (!Utils.inSkyblock || event.packet !is S2FPacketSetSlot || event.packet.func_149173_d() != 44) return
val stack = event.packet.func_149174_e() ?: return
if (!Utils.equalsOneOf(stack.item, Items.arrow, Items.feather)) return
val line = ItemUtil.getItemLore(stack).getOrNull(4) ?: return
val match = activeArrowRegex.matchEntire(line) ?: return
selectedType = match.groups["type"]?.value ?: ""
arrowCount = match.groups["amount"]?.value?.toIntOrNull() ?: -1

if (sentWarning && Skytils.config.restockArrowsWarning != 0 && arrowCount >= Skytils.config.restockArrowsWarning) {
sentWarning = false
} else if (
!sentWarning && arrowCount != -1 &&
Skytils.config.restockArrowsWarning != 0 && arrowCount < Skytils.config.restockArrowsWarning
) {
GuiManager.createTitle("§c§lRESTOCK §r${selectedType.ifBlank { "§cUnknown" }}", 60)
sentWarning = true
}
}

object QuiverDisplay : GuiElement("Quiver Display", x = 0.05f, y = 0.4f) {
private val arrowItem = ItemStack(Items.arrow, 1, 0)

override fun render() {
if (!toggled || !Utils.inSkyblock) return

val color = when {
arrowCount < 400 -> CommonColors.RED
arrowCount < 1200 -> CommonColors.YELLOW
else -> CommonColors.GREEN
}

RenderUtil.renderItem(arrowItem, 0, 0)
ScreenRenderer.fontRenderer.drawString(
if (arrowCount == -1) "???" else arrowCount.toString(),
20f,
5f,
color,
SmartFontRenderer.TextAlignment.LEFT_RIGHT,
textShadow
)
}

override fun demoRender() {
RenderUtil.renderItem(arrowItem, 0, 0)
ScreenRenderer.fontRenderer.drawString(
"2000", 20f, 5f, CommonColors.GREEN, SmartFontRenderer.TextAlignment.LEFT_RIGHT, textShadow
)
}

override val height: Int
get() = 16
override val width: Int
get() = 20 + ScreenRenderer.fontRenderer.getStringWidth("2000")

override val toggled: Boolean
get() = Skytils.config.quiverDisplay

init {
Skytils.guiManager.registerElement(this)
}
}

object SelectedArrowDisplay : GuiElement("Selected Arrow Display", x = 0.65f, y = 0.85f) {
override fun render() {
if (!toggled || !Utils.inSkyblock) return
val alignment =
if (scaleX < UResolution.scaledWidth / 2f) SmartFontRenderer.TextAlignment.LEFT_RIGHT else SmartFontRenderer.TextAlignment.RIGHT_LEFT
val text = "Selected: §r${selectedType.ifBlank { "§cUnknown" }}"

ScreenRenderer.fontRenderer.drawString(
text,
if (scaleX < UResolution.scaledWidth / 2f) 0f else width.toFloat(),
0f,
CommonColors.GREEN,
alignment,
SmartFontRenderer.TextShadow.NORMAL
)

}

override fun demoRender() {
val alignment =
if (scaleX < UResolution.scaledWidth / 2f) SmartFontRenderer.TextAlignment.LEFT_RIGHT else SmartFontRenderer.TextAlignment.RIGHT_LEFT
ScreenRenderer.fontRenderer.drawString(
"Selected: Redstone-tipped Arrow",
if (scaleX < UResolution.scaledWidth / 2f) 0f else width.toFloat(),
0f,
CommonColors.GREEN,
alignment,
SmartFontRenderer.TextShadow.NORMAL
)
}

override val height: Int
get() = ScreenRenderer.fontRenderer.FONT_HEIGHT
override val width: Int
get() = ScreenRenderer.fontRenderer.getStringWidth("Selected: Redstone-tipped Arrow")
override val toggled: Boolean
get() = Skytils.config.showSelectedArrowDisplay

init {
Skytils.guiManager.registerElement(this)
}
}
}

0 comments on commit c263ed1

Please sign in to comment.