aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/QuiverAPI.kt30
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/QuiverUpdateEvent.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverDisplay.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverWarning.kt55
4 files changed, 57 insertions, 32 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/QuiverAPI.kt b/src/main/java/at/hannibal2/skyhanni/data/QuiverAPI.kt
index b13538c9b..c40b291e6 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/QuiverAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/QuiverAPI.kt
@@ -1,7 +1,6 @@
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.data.jsonobjects.repo.ArrowTypeJson
-import at.hannibal2.skyhanni.data.jsonobjects.repo.ItemsJson
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
@@ -9,7 +8,6 @@ import at.hannibal2.skyhanni.events.OwnInventoryItemUpdateEvent
import at.hannibal2.skyhanni.events.QuiverUpdateEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.test.command.ErrorManager
-import at.hannibal2.skyhanni.utils.CollectionUtils.addOrPut
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemCategory
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
@@ -45,9 +43,14 @@ object QuiverAPI {
storage?.arrows?.arrowAmount = value
}
var currentAmount: Int
- get() = arrowAmount[currentArrow?.internalName]?.toInt() ?: 0
+ get() = currentArrow?.amount ?: 0
set(value) {
- arrowAmount[currentArrow?.internalName ?: return] = value
+ currentArrow?.amount = value
+ }
+ var ArrowType.amount: Int
+ get() = arrowAmount[this.internalName] ?: 0
+ set(value) {
+ arrowAmount[this.internalName] = value
}
private var arrows: List<ArrowType> = listOf()
@@ -120,7 +123,7 @@ object QuiverAPI {
"Unknown arrow type: $type",
"message" to message,
)
- arrowAmount[ranOutType.internalName] = 0
+ ranOutType.amount = 0
postUpdateEvent(ranOutType)
}
@@ -134,19 +137,17 @@ object QuiverAPI {
"message" to message,
)
- arrowAmount.addOrPut(filledUpType.internalName, amount)
+ filledUpType.amount += amount
if (filledUpType == currentArrow) {
postUpdateEvent()
}
return
-
}
fillUpPattern.matchMatcher(message) {
val flintAmount = group("flintAmount").formatInt()
- FLINT_ARROW_TYPE?.let { arrowAmount.addOrPut(it.internalName, flintAmount) }
-
+ FLINT_ARROW_TYPE?.let { it.amount += flintAmount }
if (currentArrow == FLINT_ARROW_TYPE) {
postUpdateEvent()
}
@@ -156,7 +157,6 @@ object QuiverAPI {
addedToQuiverPattern.matchMatcher(message) {
val type = group("type")
val amount = group("amount").formatInt()
-
val filledUpType = getArrowByNameOrNull(type)
?: return ErrorManager.logErrorWithData(
UnknownArrowType("Unknown arrow type: $type"),
@@ -164,7 +164,7 @@ object QuiverAPI {
"message" to message,
)
- arrowAmount.addOrPut(filledUpType.internalName, amount)
+ filledUpType.amount += amount
if (filledUpType == currentArrow) {
postUpdateEvent()
}
@@ -202,8 +202,7 @@ object QuiverAPI {
if (stack.getItemCategoryOrNull() != ItemCategory.ARROW) continue
val arrow = stack.getInternalNameOrNull() ?: continue
val arrowType = getArrowByNameOrNull(arrow) ?: continue
-
- arrowAmount.addOrPut(arrowType.internalName, stack.stackSize)
+ arrowType.amount += stack.stackSize
}
}
@@ -270,7 +269,7 @@ object QuiverAPI {
}
private fun postUpdateEvent(arrowType: ArrowType? = currentArrow) {
- QuiverUpdateEvent(arrowType, currentAmount, wearingSkeletonMasterChestplate).postAndCatch()
+ QuiverUpdateEvent(arrowType, currentAmount).postAndCatch()
}
@SubscribeEvent
@@ -285,9 +284,6 @@ object QuiverAPI {
// Load arrows from repo
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
- val itemData = event.getConstant<ItemsJson>("Items")
- infinityQuiverLevelMultiplier = itemData.enchant_multiplier["infinite_quiver"] ?: 0.03f
-
val arrowData = event.getConstant<ArrowTypeJson>("ArrowTypes")
arrows = arrowData.arrows.map { ArrowType(it.value.arrow, it.key.asInternalName()) }
diff --git a/src/main/java/at/hannibal2/skyhanni/events/QuiverUpdateEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/QuiverUpdateEvent.kt
index a084a1741..d0c0e5b0b 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/QuiverUpdateEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/QuiverUpdateEvent.kt
@@ -2,4 +2,4 @@ package at.hannibal2.skyhanni.events
import at.hannibal2.skyhanni.data.ArrowType
-class QuiverUpdateEvent(val currentArrow: ArrowType?, val currentAmount: Int, val hideAmount: Boolean) : LorenzEvent()
+class QuiverUpdateEvent(val currentArrow: ArrowType?, val currentAmount: Int) : LorenzEvent()
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
index 608b66b2b..049cbc35c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverDisplay.kt
@@ -64,7 +64,7 @@ class QuiverDisplay {
fun onQuiverUpdate(event: QuiverUpdateEvent) {
arrow = event.currentArrow
amount = event.currentAmount
- hideAmount = event.hideAmount
+ hideAmount = QuiverAPI.wearingSkeletonMasterChestplate
updateDisplay()
}
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
index 59fd5e51d..40ef08c6a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverWarning.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/gui/quiver/QuiverWarning.kt
@@ -2,15 +2,24 @@ 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.amount
import at.hannibal2.skyhanni.data.TitleManager
import at.hannibal2.skyhanni.events.DungeonCompleteEvent
import at.hannibal2.skyhanni.events.KuudraCompleteEvent
+import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.QuiverUpdateEvent
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
+import at.hannibal2.skyhanni.features.nether.kuudra.KuudraAPI
import at.hannibal2.skyhanni.utils.ChatUtils
-import at.hannibal2.skyhanni.utils.LorenzUtils
+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
@@ -19,8 +28,7 @@ class QuiverWarning {
private val config get() = SkyHanniMod.feature.combat.quiverConfig
private var lastLowQuiverReminder = SimpleTimeMark.farPast()
- private var lowDuringInstance = false
- private var amount = 0
+ private var arrowsInInstance = mutableSetOf<ArrowType>()
@SubscribeEvent
fun onDungeonComplete(event: DungeonCompleteEvent) {
@@ -33,15 +41,28 @@ class QuiverWarning {
}
private fun onInstanceComplete() {
- if (!lowDuringInstance) return
- lowDuringInstance = false
+ val arrows = arrowsInInstance
+ arrowsInInstance.clear()
+ arrows.filter { it.amount <= config.lowQuiverAmount }
- if (config.reminderAfterRun) {
- lowQuiverAlert()
+ if (arrows.isNotEmpty() && config.reminderAfterRun) {
+ DelayedRun.runNextTick {
+ instanceAlert(arrows)
+ }
}
}
- private fun lowQuiverAlert() {
+ private fun instanceAlert(arrows: Set<ArrowType>) {
+ val arrowsText = arrows.map { arrowType ->
+ val rarity = arrowType.internalName.getItemStackOrNull()?.getItemRarityOrNull()?.chatColorCode ?: "§f"
+ "$rarity${arrowType.arrow}"
+ }.createCommaSeparatedList()
+ TitleManager.sendTitle("§cLow on arrows!", 5.seconds, 3.6, 7f)
+ ChatUtils.chat("Low on $arrowsText!")
+ SoundUtils.repeatSound(100, 30, SoundUtils.plingSound)
+ }
+
+ private fun lowQuiverAlert(amount: Int) {
if (lastLowQuiverReminder.passedSince() < 30.seconds) return
lastLowQuiverReminder = SimpleTimeMark.now()
TitleManager.sendTitle("§cLow on arrows!", 5.seconds, 3.6, 7f)
@@ -50,18 +71,26 @@ class QuiverWarning {
@SubscribeEvent
fun onQuiverUpdate(event: QuiverUpdateEvent) {
- amount = event.currentAmount
+ val amount = event.currentAmount
+ val arrow = event.currentArrow ?: return
+ if (arrow == QuiverAPI.NONE_ARROW_TYPE) return
+
+ if (inInstance()) arrowsInInstance.add(arrow)
if (amount > config.lowQuiverAmount) return
- if (DungeonAPI.inDungeon() || LorenzUtils.inKuudraFight) {
- lowDuringInstance = true
- }
if (config.lowQuiverNotification) {
- lowQuiverAlert()
+ lowQuiverAlert(amount)
}
}
@SubscribeEvent
+ fun onWorldSwitch(event: LorenzWorldChangeEvent) {
+ arrowsInInstance.clear()
+ }
+
+ private fun inInstance() = DungeonAPI.inDungeon() || KuudraAPI.inKuudra()
+
+ @SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.move(35, "inventory.quiverAlert", "combat.quiverConfig.lowQuiverNotification")
}