diff options
author | Empa <42304516+ItsEmpa@users.noreply.github.com> | 2024-04-13 08:35:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-13 08:35:51 +0200 |
commit | 0d41a281c8d87128a0004fed96dada8b1b5e950a (patch) | |
tree | 1f4492d4dfb646178c3e7409e519abaea5543efd /src/main/java/at/hannibal2/skyhanni/features | |
parent | 2d3368725ea962d8ff42d17cf1623a2229da7b4f (diff) | |
download | skyhanni-0d41a281c8d87128a0004fed96dada8b1b5e950a.tar.gz skyhanni-0d41a281c8d87128a0004fed96dada8b1b5e950a.tar.bz2 skyhanni-0d41a281c8d87128a0004fed96dada8b1b5e950a.zip |
Feature: Quiver Display (#1190)
Co-authored-by: Cal <cwolfson58@gmail.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
3 files changed, 216 insertions, 26 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverDisplay.kt new file mode 100644 index 000000000..608b66b2b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverDisplay.kt @@ -0,0 +1,98 @@ +package at.hannibal2.skyhanni.features.gui.quiver + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.features.combat.QuiverDisplayConfig.ShowWhen +import at.hannibal2.skyhanni.data.ArrowType +import at.hannibal2.skyhanni.data.QuiverAPI +import at.hannibal2.skyhanni.data.QuiverAPI.NONE_ARROW_TYPE +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.GuiRenderEvent +import at.hannibal2.skyhanni.events.ProfileJoinEvent +import at.hannibal2.skyhanni.events.QuiverUpdateEvent +import at.hannibal2.skyhanni.utils.ConditionalUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NEUItems +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.RenderUtils +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables +import at.hannibal2.skyhanni.utils.StringUtils +import at.hannibal2.skyhanni.utils.renderables.Renderable +import net.minecraft.init.Items +import net.minecraft.item.ItemStack +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class QuiverDisplay { + + private val config get() = SkyHanniMod.feature.combat.quiverConfig.quiverDisplay + + private var display = emptyList<Renderable>() + private var arrow: ArrowType? = null + private var amount = QuiverAPI.currentAmount + private var hideAmount = false + + @SubscribeEvent + fun onProfileJoin(event: ProfileJoinEvent) { + display = emptyList() + arrow = QuiverAPI.currentArrow + amount = QuiverAPI.currentAmount + updateDisplay() + } + + private fun updateDisplay() { + display = drawDisplay() + } + + private fun drawDisplay() = buildList { + val arrow = arrow ?: return@buildList + val itemStack = NEUItems.getItemStackOrNull(arrow.internalName.asString()) ?: ItemStack(Items.arrow) + + val rarity = itemStack.getItemRarityOrNull()?.chatColorCode ?: "§f" + val arrowDisplayName = + if (hideAmount || arrow == NONE_ARROW_TYPE) arrow.arrow else StringUtils.pluralize(amount, arrow.arrow) + + if (config.showIcon.get()) { + add(Renderable.itemStack(itemStack, 1.0)) + } + if (!hideAmount) { + add(Renderable.string("§b${amount.addSeparators()}x")) + } + add(Renderable.string(" $rarity$arrowDisplayName")) + } + + @SubscribeEvent + fun onQuiverUpdate(event: QuiverUpdateEvent) { + arrow = event.currentArrow + amount = event.currentAmount + hideAmount = event.hideAmount + + updateDisplay() + } + + @SubscribeEvent + fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) { + if (!isEnabled()) return + if (display.isEmpty()) updateDisplay() + val whenToShow = config.whenToShow.get() + if (whenToShow == ShowWhen.ALWAYS || + whenToShow == ShowWhen.ONLY_BOW_INVENTORY && QuiverAPI.hasBowInInventory() || + whenToShow == ShowWhen.ONLY_BOW_HAND && QuiverAPI.isHoldingBow() + ) { + val content = + Renderable.horizontalContainer(display, 1, verticalAlign = RenderUtils.VerticalAlignment.CENTER) + config.quiverDisplayPos.renderRenderables(listOf(content), posLabel = "Quiver Display") + } + } + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + ConditionalUtils.onToggle( + config.whenToShow, + config.showIcon + ) { + updateDisplay() + } + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverWarning.kt b/src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverWarning.kt new file mode 100644 index 000000000..7ee69c9c8 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverWarning.kt @@ -0,0 +1,118 @@ +package at.hannibal2.skyhanni.features.gui.quiver + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator +import at.hannibal2.skyhanni.data.ArrowType +import at.hannibal2.skyhanni.data.QuiverAPI +import at.hannibal2.skyhanni.data.QuiverAPI.arrowAmount +import at.hannibal2.skyhanni.data.TitleManager +import at.hannibal2.skyhanni.events.DungeonCompleteEvent +import at.hannibal2.skyhanni.events.DungeonEnterEvent +import at.hannibal2.skyhanni.events.KuudraCompleteEvent +import at.hannibal2.skyhanni.events.KuudraEnterEvent +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.QuiverUpdateEvent +import at.hannibal2.skyhanni.utils.ChatUtils +import at.hannibal2.skyhanni.utils.DelayedRun +import at.hannibal2.skyhanni.utils.ItemUtils.getItemRarityOrNull +import at.hannibal2.skyhanni.utils.NEUItems.getItemStackOrNull +import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators +import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.SoundUtils +import at.hannibal2.skyhanni.utils.StringUtils.createCommaSeparatedList +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import kotlin.time.Duration.Companion.seconds + +class QuiverWarning { + + private val config get() = SkyHanniMod.feature.combat.quiverConfig + + private var arrow: ArrowType? = null + private var amount = QuiverAPI.currentAmount + private var lastLowQuiverReminder = SimpleTimeMark.farPast() + private var arrowsUsedInRun = mutableListOf<ArrowType>() + private var arrowsToAlert = mutableListOf<String>() + private var inInstance = false + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + arrowsUsedInRun = mutableListOf() + arrowsToAlert = mutableListOf() + inInstance = false + } + + @SubscribeEvent + fun onDungeonEnter(event: DungeonEnterEvent) { + onInstanceEnter() + } + + @SubscribeEvent + fun onKuudraEnter(event: KuudraEnterEvent) { + onInstanceEnter() + } + + private fun onInstanceEnter() { + arrowsUsedInRun = mutableListOf() + arrowsToAlert = mutableListOf() + inInstance = true + } + + @SubscribeEvent + fun onDungeonComplete(event: DungeonCompleteEvent) { + onInstanceComplete() + } + + @SubscribeEvent + fun onKuudraComplete(event: KuudraCompleteEvent) { + onInstanceComplete() + } + + private fun onInstanceComplete() { + if (!config.reminderAfterRun) return + if (arrowsUsedInRun.isEmpty()) return + for (arrow in arrowsUsedInRun) { + val internalName = arrow.internalName + val amount = arrowAmount[internalName] ?: continue + if (amount > config.lowQuiverAmount) continue + val rarity = internalName.getItemStackOrNull()?.getItemRarityOrNull()?.chatColorCode ?: "§f" + arrowsToAlert.add(rarity + arrow.arrow) + } + if (arrowsToAlert.isNotEmpty()) instanceAlert() + } + + private fun instanceAlert() { + DelayedRun.runNextTick { + TitleManager.sendTitle("§cLow on arrows!", 5.seconds, 3.6, 7f) + ChatUtils.chat("Low on ${arrowsToAlert.createCommaSeparatedList()}!") + SoundUtils.repeatSound(100, 30, SoundUtils.plingSound) + } + } + + private fun lowQuiverAlert() { + if (lastLowQuiverReminder.passedSince() < 30.seconds) return + lastLowQuiverReminder = SimpleTimeMark.now() + val itemStack = getItemStackOrNull(arrow?.internalName?.asString() ?: return) ?: return + val rarity = itemStack.getItemRarityOrNull()?.chatColorCode ?: "§f" + TitleManager.sendTitle("§cLow on $rarity${arrow?.arrow}!", 5.seconds, 3.6, 7f) + ChatUtils.chat("Low on $rarity${arrow?.arrow} §e(${amount.addSeparators()} left)") + } + + @SubscribeEvent + fun onQuiverUpdate(event: QuiverUpdateEvent) { + val lastArrow = arrow + val lastAmount = amount + + if (config.lowQuiverNotification && amount <= config.lowQuiverAmount) { + if (arrow != lastArrow || (arrow == lastArrow && amount <= lastAmount)) lowQuiverAlert() + } + + if (inInstance) { + if (!arrowsUsedInRun.contains(arrow)) arrowsUsedInRun.add(arrow ?: return) + } + } + + @SubscribeEvent + fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) { + event.move(35, "inventory.quiverAlert", "combat.quiverConfig.lowQuiverNotification") + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuiverNotification.kt b/src/main/java/at/hannibal2/skyhanni/features/inventory/QuiverNotification.kt deleted file mode 100644 index 9063fcb0d..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/inventory/QuiverNotification.kt +++ /dev/null @@ -1,26 +0,0 @@ -package at.hannibal2.skyhanni.features.inventory - -import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.TitleManager -import at.hannibal2.skyhanni.events.LorenzChatEvent -import at.hannibal2.skyhanni.utils.SoundUtils -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher -import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import kotlin.time.Duration.Companion.seconds - -object QuiverNotification { - private val quiverChatPattern by RepoPattern.pattern( - "inventory.quiver.chat.low", - "§cYou only have (?<arrowsLeft>.*) arrows left in your Quiver!" - ) - - @SubscribeEvent - fun onChat(event: LorenzChatEvent) { - if (!SkyHanniMod.configManager.features.inventory.quiverAlert) return - quiverChatPattern.matchMatcher(event.message) { - TitleManager.sendTitle("§c${group("arrowsLeft")} arrows left!", 3.seconds, 3.6, 7f) - SoundUtils.repeatSound(100, 30, SoundUtils.plingSound) - } - } -} |