diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-09-30 01:40:46 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-09-30 01:40:46 +0200 |
commit | b0c0a89625d5ec1e41199981ab5f94a363b808de (patch) | |
tree | bc1ddf7e138fb626f11bdb6df2e8134c2eed9a65 /src/main/java | |
parent | 333cb46f87c255663294cf0368b20839039cfe42 (diff) | |
download | skyhanni-b0c0a89625d5ec1e41199981ab5f94a363b808de.tar.gz skyhanni-b0c0a89625d5ec1e41199981ab5f94a363b808de.tar.bz2 skyhanni-b0c0a89625d5ec1e41199981ab5f94a363b808de.zip |
load shield from inventory
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt | 40 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/HellionShield.kt | 8 |
2 files changed, 42 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt index 80c28f2cf..c9a010cef 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.config.core.util.render.TextRenderUtils import at.hannibal2.skyhanni.events.ItemClickInHandEvent import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getLore import at.hannibal2.skyhanni.utils.ItemUtils.name import at.hannibal2.skyhanni.utils.LocationUtils import at.hannibal2.skyhanni.utils.LorenzUtils @@ -36,7 +37,7 @@ class BlazeSlayerDaggerHelper { if (!isEnabled()) return val player = Minecraft.getMinecraft().thePlayer - val dagger = getDaggerInHand(player.inventory.mainInventory[player.inventory.currentItem]) + val dagger = getDaggerFromStack(player.inventory.mainInventory[player.inventory.currentItem]) if (dagger != null) { setDaggerText(dagger) return @@ -113,14 +114,42 @@ class BlazeSlayerDaggerHelper { lastDaggerCheck = System.currentTimeMillis() for (dagger in Dagger.values()) { + if (dagger.updated) continue + val first = dagger.shields[0] if (!first.active && !dagger.shields[1].active) { - first.active = true + + val shield = readFromInventory(dagger) + if (shield != null) { + shield.active = true + dagger.updated = true + } else { + first.active = true + } + } + } + } + + private fun readFromInventory(dagger: Dagger): HellionShield? { + val player = Minecraft.getMinecraft().thePlayer + for (stack in player.inventory.mainInventory) { + val otherDagger = getDaggerFromStack(stack) ?: continue + if (dagger != otherDagger) continue + for (line in stack.getLore()) { + if (!line.contains("§7Attuned: ")) continue + + for (shield in dagger.shields) { + if (line.contains(shield.cleanName)) { + return shield + } + } } } + + return null } - private fun getDaggerInHand(stack: ItemStack?): Dagger? { + private fun getDaggerFromStack(stack: ItemStack?): Dagger? { val itemName = stack?.name ?: "" for (dagger in Dagger.values()) { if (dagger.daggerNames.any { itemName.contains(it) }) { @@ -145,6 +174,7 @@ class BlazeSlayerDaggerHelper { if (shield.formattedName + "§r" == formattedText) { Dagger.values().filter { shield in it.shields }.forEach { it.shields.forEach { shield -> shield.active = false } + it.updated = true } shield.active = true event.isCanceled = true @@ -165,13 +195,13 @@ class BlazeSlayerDaggerHelper { if (event.clickType != ItemClickInHandEvent.ClickType.RIGHT_CLICK) return val itemInHand = event.itemInHand ?: return - val dagger = getDaggerInHand(itemInHand) + val dagger = getDaggerFromStack(itemInHand) dagger?.shields?.forEach { shield -> shield.active = !shield.active } clientSideClicked = true } - enum class Dagger(val daggerNames: List<String>, vararg val shields: HellionShield) { + enum class Dagger(val daggerNames: List<String>, vararg val shields: HellionShield, var updated: Boolean = false) { TWILIGHT( listOf("Twilight Dagger", "Mawdredge Dagger", "Deathripper Dagger"), HellionShield.SPIRIT, diff --git a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/HellionShield.kt b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/HellionShield.kt index dffd1ca90..3fee1e92f 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/HellionShield.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/HellionShield.kt @@ -2,7 +2,13 @@ package at.hannibal2.skyhanni.features.slayer.blaze import at.hannibal2.skyhanni.utils.LorenzColor -enum class HellionShield(val formattedName: String, val cleanName: String, val color: LorenzColor, val chatColor: String = color.getChatColor(), var active: Boolean = false) { +enum class HellionShield( + val formattedName: String, + val cleanName: String, + val color: LorenzColor, + val chatColor: String = color.getChatColor(), + var active: Boolean = false, +) { AURIC("§e§lAURIC", "Auric", LorenzColor.YELLOW), ASHEN("§8§lASHEN", "Ashen", LorenzColor.DARK_GRAY), SPIRIT("§f§lSPIRIT", "Spirit", LorenzColor.WHITE), |