diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-06-15 14:14:13 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-06-15 14:14:13 +0200 |
commit | 57246cc1053215bd4a4e66857eeefc9c83b399f4 (patch) | |
tree | 97679c99b2ce47ad489a282abca8292a658df828 /src/main/java/at/hannibal2/skyhanni/features | |
parent | 6b3e7ef0c4b56c36f62b48a4b93ae3186623e4cb (diff) | |
download | skyhanni-57246cc1053215bd4a4e66857eeefc9c83b399f4.tar.gz skyhanni-57246cc1053215bd4a4e66857eeefc9c83b399f4.tar.bz2 skyhanni-57246cc1053215bd4a4e66857eeefc9c83b399f4.zip |
Added cells alignment ability cooldown
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
2 files changed, 71 insertions, 35 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbility.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbility.kt index 69f5742b7..fa6d63578 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbility.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbility.kt @@ -7,6 +7,7 @@ enum class ItemAbility( val abilityName: String, private val cooldownInSeconds: Int, vararg val itemNames: String, + val alternativePosition: Boolean = false, var lastActivation: Long = 0L, var specialColor: LorenzColor? = null, var lastItemClick: Long = 0L, @@ -15,7 +16,8 @@ enum class ItemAbility( //TODO add into repo HYPERION(5, "SCYLLA", "VALKYRIE", "ASTREA"), - GYROKINETIC_WAND(30), + GYROKINETIC_WAND_LEFT(30, "GYROKINETIC_WAND", alternativePosition = true), + GYROKINETIC_WAND_RIGHT(10, "GYROKINETIC_WAND"), GIANTS_SWORD(30), ICE_SPRAY_WAND(5), ATOMSPLIT_KATANA(4, "VORPAL_KATANA", "VOIDEDGE_KATANA"), @@ -47,7 +49,7 @@ enum class ItemAbility( var newVariant = false var internalNames = mutableListOf<String>() - constructor(cooldownInSeconds: Int, vararg alternateInternalNames: String) : this("no name", cooldownInSeconds, actionBarDetection = false) { + constructor(cooldownInSeconds: Int, vararg alternateInternalNames: String, alternativePosition: Boolean = false) : this("no name", cooldownInSeconds, actionBarDetection = false, alternativePosition = alternativePosition) { newVariant = true internalNames.addAll(alternateInternalNames) internalNames.add(name) diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt index 9ae351da2..8ba7eca09 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbilityCooldown.kt @@ -9,16 +9,17 @@ import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzUtils.between +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher import net.minecraft.client.Minecraft import net.minecraft.item.ItemStack import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent class ItemAbilityCooldown { - - var lastAbility = "" + private var lastAbility = "" var tick = 0 - val items = mutableMapOf<ItemStack, ItemText>() + var items = mapOf<ItemStack, List<ItemText>>() + private val youAlignedOthersPattern = "§eYou aligned §r§a.* §r§eother player(s)?!".toPattern() @SubscribeEvent fun onSoundEvent(event: PlaySoundEvent) { @@ -34,7 +35,7 @@ class ItemAbilityCooldown { } if (event.soundName == "mob.endermen.portal") { if (event.pitch == 0.61904764f && event.volume == 1f) { - ItemAbility.GYROKINETIC_WAND.sound() + ItemAbility.GYROKINETIC_WAND_LEFT.sound() } } if (event.soundName == "random.anvil_land") { @@ -169,27 +170,44 @@ class ItemAbilityCooldown { tick++ if (tick % 2 == 0) { - checkHotbar() + checkHotBar() } } - private fun checkHotbar() { - items.clear() + private fun checkHotBar() { + val items = mutableMapOf<ItemStack, MutableList<ItemText>>() for ((stack, _) in ItemUtils.getItemsInInventoryWithSlots(true)) { - val ability = hasAbility(stack) - if (ability != null) { + for (ability in hasAbility(stack)) { + items.getOrPut(stack) { mutableListOf() }.add(createItemText(ability)) + } + } + this.items = items + } - if (ability.isOnCooldown()) { - val duration: Long = ability.lastActivation + ability.getCooldown() - System.currentTimeMillis() - val color = ability.specialColor ?: if (duration < 600) LorenzColor.RED else LorenzColor.YELLOW - items[stack] = ItemText(color, ability.getDurationText(), true) - } else { - ability.specialColor = null - items[stack] = ItemText(LorenzColor.GREEN, "R", false) - } + private fun createItemText(ability: ItemAbility): ItemText { + val specialColor = ability.specialColor + return if (ability.isOnCooldown()) { + val duration: Long = + ability.lastActivation + ability.getCooldown() - System.currentTimeMillis() + val color = + specialColor ?: if (duration < 600) LorenzColor.RED else LorenzColor.YELLOW + ItemText(color, ability.getDurationText(), true, ability.alternativePosition) + } else { + if (specialColor != null) { + ability.specialColor = null + tryHandleNextPhase(ability, specialColor) + return createItemText(ability) } + ItemText(LorenzColor.GREEN, "R", false, ability.alternativePosition) } + } + private fun tryHandleNextPhase(ability: ItemAbility, specialColor: LorenzColor) { + if (ability == ItemAbility.GYROKINETIC_WAND_RIGHT) { + if (specialColor == LorenzColor.BLUE) { + ability.activate(null, -4_000) + } + } } @SubscribeEvent @@ -199,19 +217,27 @@ class ItemAbilityCooldown { val stack = event.stack val guiOpen = Minecraft.getMinecraft().currentScreen != null - val itemText = items.filter { it.key == stack } + val list = items.filter { it.key == stack } .firstNotNullOfOrNull { it.value } ?: return - if (guiOpen && !itemText.onCooldown) return - val color = itemText.color - event.stackTip = color.getChatColor() + itemText.text + for (itemText in list) { + if (guiOpen && !itemText.onCooldown) continue + val color = itemText.color + val renderObject = RenderObject(color.getChatColor() + itemText.text) + if (itemText.alternativePosition) { + renderObject.offsetX = -8 + renderObject.offsetY = -10 + } + event.renderObjects.add(renderObject) - if (SkyHanniMod.feature.itemAbilities.itemAbilityCooldownBackground) { - var opacity = 130 - if (color == LorenzColor.GREEN) { - opacity = 80 + // fix multiple problems when having multiple abilities + if (SkyHanniMod.feature.itemAbilities.itemAbilityCooldownBackground) { + var opacity = 130 + if (color == LorenzColor.GREEN) { + opacity = 80 + } + stack.background = color.addOpacity(opacity).rgb } - stack.background = color.addOpacity(opacity).rgb } } @@ -221,34 +247,42 @@ class ItemAbilityCooldown { if (message == "§dCreeper Veil §r§aActivated!") { ItemAbility.WITHER_CLOAK.activate(LorenzColor.LIGHT_PURPLE) } - if (message == "§dCreeper Veil §r§cDe-activated! §r§8(Expired)" || - message == "§cNot enough mana! §r§dCreeper Veil §r§cDe-activated!" + if (message == "§dCreeper Veil §r§cDe-activated! §r§8(Expired)" + || message == "§cNot enough mana! §r§dCreeper Veil §r§cDe-activated!" ) { ItemAbility.WITHER_CLOAK.activate() } if (message == "§dCreeper Veil §r§cDe-activated!") { ItemAbility.WITHER_CLOAK.activate(null, -5000L) } + + youAlignedOthersPattern.matchMatcher(message) { + ItemAbility.GYROKINETIC_WAND_RIGHT.activate(LorenzColor.BLUE, -4_000) + } + if (message == "§eYou §r§aaligned §r§eyourself!") { + ItemAbility.GYROKINETIC_WAND_RIGHT.activate(LorenzColor.BLUE, -4_000) + } } - private fun hasAbility(stack: ItemStack): ItemAbility? { + private fun hasAbility(stack: ItemStack): MutableList<ItemAbility> { val itemName: String = stack.cleanName() val internalName = stack.getInternalName() + val list = mutableListOf<ItemAbility>() for (ability in ItemAbility.values()) { if (ability.newVariant) { if (ability.internalNames.contains(internalName)) { - return ability + list.add(ability) } } else { for (name in ability.itemNames) { if (itemName.contains(name)) { - return ability + list.add(ability) } } } } - return null + return list } private fun ItemAbility.sound() { @@ -258,5 +292,5 @@ class ItemAbilityCooldown { } } - class ItemText(val color: LorenzColor, val text: String, val onCooldown: Boolean) + class ItemText(val color: LorenzColor, val text: String, val onCooldown: Boolean, val alternativePosition: Boolean) } |