diff options
author | Lorenz <lo.scherf@gmail.com> | 2022-09-15 17:20:50 +0200 |
---|---|---|
committer | Lorenz <lo.scherf@gmail.com> | 2022-09-15 17:20:50 +0200 |
commit | 38854e7b03ab06cb37096fff6b72a82472513581 (patch) | |
tree | 3ba29edb7f7f5ac13a5b6b3753aaafda00d4516f /src/main/java/at/hannibal2/skyhanni | |
parent | e55b5458459d79c267b105334d3d54d4340f2161 (diff) | |
download | skyhanni-38854e7b03ab06cb37096fff6b72a82472513581.tar.gz skyhanni-38854e7b03ab06cb37096fff6b72a82472513581.tar.bz2 skyhanni-38854e7b03ab06cb37096fff6b72a82472513581.zip |
made ability cooldown work better
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni')
3 files changed, 173 insertions, 157 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 new file mode 100644 index 000000000..61b1597a3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbility.kt @@ -0,0 +1,92 @@ +package at.hannibal2.skyhanni.features.itemabilities.abilitycooldown + +import at.hannibal2.skyhanni.utils.LorenzUtils + +enum class ItemAbility( + val abilityName: String, + val cooldownInSeconds: Long, + vararg val itemNames: String, + var lastClick: Long = 0L, + var lastNewClick: Long = 0L, + val actionBarDetection: Boolean = true, +) { + //TODO add into repo + + HYPERION(5, "SCYLLA", "VALKYRIE", "ASTREA"), + GYROKINETIC_WAND(30), + GIANTS_SWORD(30), + ICE_SPRAY_WAND(5), + ATOMSPLIT_KATANA(4, "VORPAL_KATANA", "VOIDEDGE_KATANA"), + + + // Old logic, need to replace in the future + + HEAL_1("Small Heal", 7, "Wand of Healing"), + HEAL_2("Medium Heal", 7, "Wand of Mending"), + HEAL_3("Big Heal", 7, "Wand of Restoration"), + HEAL_4("Huge Heal", 7, "Wand of Atonement"), + + STAR_FALL("Starfall", 2, "Starlight Wand"), + VODOO_DOLL("Acupuncture", 5, "Voodoo Doll"), + INK_WAND("Ink Bomb", 30, "Ink Wand"), + GOLEM_SWORD("Iron Punch", 3, "Golem Sword"), + EMBER_ROD("Fire Blast", 30, "Ember Rod"), + ENDER_BOW("Ender Warp", 30, "Ender Bow"), + + LIVID_DAGGER("Throw", 5, "Livid Dagger"), + WEIRD_TUBA("Howl", 20, "Weird Tuba"), + + ENDSTONE_SWORD("Extreme Focus", 5, "End Stone Sword"), + PIGMAN_SWORD("Burning Souls", 5, "Pigman Sword"), + + SOULWARD("Soulward", 20, "Soul Esoward"), + ECHO("Echo", 3, "Ancestral Spade"), + + FIRE_VEIL("Fire Veil", 5, "Fire Veil Wand"), + //TODO add new crimson isle weapons + + ; + + var newVariant = false + var internalNames = mutableListOf<String>() + + constructor(cooldownInSeconds: Int, vararg alternateInternalNames: String) : this("no name", cooldownInSeconds.toLong(), actionBarDetection = false) { + newVariant = true + internalNames.addAll(alternateInternalNames) + internalNames.add(name) + } + + fun oldClick() { + lastClick = System.currentTimeMillis() + } + + fun isOnCooldown(): Boolean = lastClick + getCooldown() > System.currentTimeMillis() + + fun getCooldown(): Long = cooldownInSeconds * 1000 + + fun getDurationText(): String { + var duration: Long = lastClick + getCooldown() - System.currentTimeMillis() + return if (duration < 1600) { + duration /= 100 + var d = duration.toDouble() + d /= 10.0 + LorenzUtils.formatDouble(d) + } else { + duration /= 1000 + duration++ + LorenzUtils.formatInteger(duration.toInt()) + } + } + + fun newClick() { +// println("newClick $this") + lastNewClick = System.currentTimeMillis() + } + + companion object { + fun getByInternalName(internalName: String): ItemAbility? { + return values().firstOrNull { it.newVariant && internalName in it.internalNames } + } + } + +}
\ No newline at end of file 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 01bef358f..cb82e1a90 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 @@ -4,15 +4,20 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ItemRenderBackground.Companion.background import at.hannibal2.skyhanni.events.GuiRenderItemEvent import at.hannibal2.skyhanni.events.LorenzActionBarEvent +import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.utils.ItemUtils import at.hannibal2.skyhanni.utils.ItemUtils.cleanName +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 net.minecraft.client.Minecraft import net.minecraft.client.renderer.GlStateManager import net.minecraft.item.ItemStack -import net.minecraftforge.common.MinecraftForge +import net.minecraft.network.play.client.C07PacketPlayerDigging +import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement +import net.minecraft.network.play.server.S29PacketSoundEffect +import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import net.minecraftforge.fml.common.gameevent.TickEvent @@ -21,14 +26,57 @@ class ItemAbilityCooldown { var lastAbility = "" var tick = 0 val items = mutableMapOf<ItemStack, ItemText>() - val witherImpactDetection = WitherImpactDetection(this) - init { - MinecraftForge.EVENT_BUS.register(witherImpactDetection) + @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true) + fun onChatPacket(event: PacketEvent.ReceiveEvent) { + val packet = event.packet + if (packet is S29PacketSoundEffect) { + if (packet.soundName == "mob.zombie.remedy") { + if (packet.pitch == 0.6984127f && packet.volume == 1f) { + ItemAbility.HYPERION.sound() + } + } + if (packet.soundName == "mob.enderdragon.growl") { + if (packet.pitch == 1f && packet.volume == 1f) { + ItemAbility.ICE_SPRAY_WAND.sound() + } + } + if (packet.soundName == "mob.endermen.portal") { + if (packet.pitch == 0.61904764f && packet.volume == 1f) { + ItemAbility.GYROKINETIC_WAND.sound() + } + } + if (packet.soundName == "random.anvil_land") { + if (packet.pitch == 0.4920635f && packet.volume == 1f) { + ItemAbility.GIANTS_SWORD.sound() + } + } + if (packet.soundName == "mob.ghast.affectionate_scream") { + if (packet.pitch == 0.4920635f && packet.volume == 0.15f) { + ItemAbility.ATOMSPLIT_KATANA.sound() + } + } + } } - fun clickWitherImpact() { - Ability.WITHER_IMPACT.click() + @SubscribeEvent + fun onItemClickSend(event: PacketEvent.SendEvent) { + if (!LorenzUtils.inSkyblock) return + + val packet = event.packet + if (packet is C07PacketPlayerDigging) { + if (packet.status == C07PacketPlayerDigging.Action.START_DESTROY_BLOCK) { + val heldItem = Minecraft.getMinecraft().thePlayer.heldItem ?: return + val internalName = heldItem.getInternalName() + ItemAbility.getByInternalName(internalName)?.newClick() +// println("internalName: $internalName") + } + } + if (packet is C08PacketPlayerBlockPlacement) { + val heldItem = Minecraft.getMinecraft().thePlayer.heldItem ?: return + val internalName = heldItem.getInternalName() + ItemAbility.getByInternalName(internalName)?.newClick() + } } @SubscribeEvent @@ -41,7 +89,7 @@ class ItemAbilityCooldown { val name: String = message.between(" (§6", "§b) ") if (name == lastAbility) return lastAbility = name - for (ability in Ability.values()) { + for (ability in ItemAbility.values()) { if (ability.abilityName == name) { click(ability) return @@ -57,10 +105,10 @@ class ItemAbilityCooldown { return LorenzUtils.inSkyblock && SkyHanniMod.feature.itemAbilities.itemAbilityCooldown } - private fun click(ability: Ability) { -// if (ability.isActive()) return - if (!ability.actionBarDetection) return - ability.click() + private fun click(ability: ItemAbility) { + if (ability.actionBarDetection) { + ability.oldClick() + } } @SubscribeEvent @@ -75,11 +123,8 @@ class ItemAbilityCooldown { private fun checkHotbar() { items.clear() - for ((stack, slot) in ItemUtils.getItemsInInventoryWithSlots(true)) { -// val inHotbar = slot in 36..43 - - val itemName: String = stack.cleanName() - val ability = hasAbility(itemName) + for ((stack, _) in ItemUtils.getItemsInInventoryWithSlots(true)) { + val ability = hasAbility(stack) if (ability != null) { if (ability.isOnCooldown()) { @@ -134,81 +179,34 @@ class ItemAbilityCooldown { } } - private fun hasAbility(itemName: String): Ability? { - for (ability in Ability.values()) { - for (name in ability.itemNames) { - if (itemName.contains(name)) { + private fun hasAbility(stack: ItemStack): ItemAbility? { + val itemName: String = stack.cleanName() + val internalName = stack.getInternalName() + + for (ability in ItemAbility.values()) { + if (ability.newVariant) { + if (ability.internalNames.contains(internalName)) { return ability } + } else { + for (name in ability.itemNames) { + if (itemName.contains(name)) { + return ability + } + } } } return null } - enum class Ability( - val abilityName: String, - val cooldownInSeconds: Long, - vararg val itemNames: String, - var lastClick: Long = 0L, - val actionBarDetection: Boolean = true, - ) { - //TODO add into repo - ATOMSPLIT("Soulcry", 4, "Atomsplit Katana", "Vorpal Katana", "Voidedge Katana"), - WITHER_IMPACT("Wither Impact", 5, "Hyperion", "Scylla", "Valkyrie", "Astrea", actionBarDetection = false), - - HEAL_1("Small Heal", 7, "Wand of Healing"), - HEAL_2("Medium Heal", 7, "Wand of Mending"), - HEAL_3("Big Heal", 7, "Wand of Restoration"), - HEAL_4("Huge Heal", 7, "Wand of Atonement"), - - ICE_SPRAY("Ice Spray", 5, "Ice Spray Wand"), - GYRO("Gravity Storm", 30, "Gyrokinetic Wand"), - GIANTS_SWORD("Giant's Slam", 30, "Giant's Sword"), - - STAR_FALL("Starfall", 2, "Starlight Wand"), - VODOO_DOLL("Acupuncture", 5, "Voodoo Doll"), - INK_WAND("Ink Bomb", 30, "Ink Wand"), - GOLEM_SWORD("Iron Punch", 3, "Golem Sword"), - EMBER_ROD("Fire Blast", 30, "Ember Rod"), - ENDER_BOW("Ender Warp", 30, "Ender Bow"), - - LIVID_DAGGER("Throw", 5, "Livid Dagger"), - WEIRD_TUBA("Howl", 20, "Weird Tuba"), - - ENDSTONE_SWORD("Extreme Focus", 5, "End Stone Sword"), - PIGMAN_SWORD("Burning Souls", 5, "Pigman Sword"), - - SOULWARD("Soulward", 20, "Soul Esoward"), - ECHO("Echo", 3, "Ancestral Spade"), - - FIRE_VEIL("Fire Veil", 5, "Fire Veil Wand"), - //TODO add new crimson isle weapons - - ; - - fun click() { - lastClick = System.currentTimeMillis() + private fun ItemAbility.sound() { + val lastNewClick = lastNewClick + val ping = System.currentTimeMillis() - lastNewClick +// println("$this click ($ping)") + if (ping < 400) { + oldClick() } - - fun isOnCooldown(): Boolean = lastClick + getCooldown() > System.currentTimeMillis() - - fun getCooldown(): Long = cooldownInSeconds * 1000 - - fun getDurationText(): String { - var duration: Long = lastClick + getCooldown() - System.currentTimeMillis() - return if (duration < 1600) { - duration /= 100 - var d = duration.toDouble() - d /= 10.0 - LorenzUtils.formatDouble(d) - } else { - duration /= 1000 - duration++ - LorenzUtils.formatInteger(duration.toInt()) - } - } - } class ItemText(val color: LorenzColor, val text: String, val onCooldown: Boolean) -}
\ No newline at end of file +} diff --git a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/WitherImpactDetection.kt b/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/WitherImpactDetection.kt deleted file mode 100644 index 5ad5a4bb0..000000000 --- a/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/WitherImpactDetection.kt +++ /dev/null @@ -1,74 +0,0 @@ -package at.hannibal2.skyhanni.features.itemabilities.abilitycooldown - -import at.hannibal2.skyhanni.events.PacketEvent -import at.hannibal2.skyhanni.utils.LorenzUtils -import net.minecraft.client.Minecraft -import net.minecraft.init.Items -import net.minecraft.item.ItemStack -import net.minecraft.nbt.NBTTagCompound -import net.minecraft.nbt.NBTTagList -import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement -import net.minecraft.network.play.server.S1CPacketEntityMetadata -import net.minecraft.network.play.server.S2APacketParticles -import net.minecraft.util.EnumParticleTypes -import net.minecraftforge.common.util.Constants -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent - -/** - * Taken from Skytils under AGPL 3.0 - * Modified - * https://github.com/Skytils/SkytilsMod/blob/1.x/LICENSE.md - * @author Skytils - */ -class WitherImpactDetection(private val itemAbilityCooldown: ItemAbilityCooldown) { - - val S2APacketParticles.type: EnumParticleTypes - get() = this.particleType - var lastShieldUse = -1L - var lastShieldClick = 0L - - @SubscribeEvent - fun onReceivePacket(event: PacketEvent.ReceiveEvent) { - val mc = Minecraft.getMinecraft() - if (!LorenzUtils.inSkyblock || mc.theWorld == null) return - - event.packet.apply { - - if (this is S1CPacketEntityMetadata && lastShieldClick != -1L && entityId == mc.thePlayer?.entityId && System.currentTimeMillis() - lastShieldClick <= 500 && func_149376_c()?.any { it.dataValueId == 17 } == true) { - lastShieldUse = System.currentTimeMillis() - lastShieldClick = -1 - itemAbilityCooldown.clickWitherImpact() - } - } - } - - @SubscribeEvent - fun onSendPacket(event: PacketEvent.SendEvent) { - val mc = Minecraft.getMinecraft() - if (!LorenzUtils.inSkyblock || lastShieldUse != -1L || mc.thePlayer?.heldItem == null) return - if (event.packet is C08PacketPlayerBlockPlacement && mc.thePlayer.heldItem.item == Items.iron_sword && getExtraAttributes( - mc.thePlayer.heldItem - )?.getTagList("ability_scroll", Constants.NBT.TAG_STRING)?.asStringSet() - ?.contains("WITHER_SHIELD_SCROLL") == true - ) { - lastShieldClick = System.currentTimeMillis() - } - } - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (lastShieldUse != -1L) { - val diff = ((lastShieldUse + 5000 - System.currentTimeMillis()) / 1000f) - if (diff < 0) lastShieldUse = -1 - } - } - - private fun getExtraAttributes(item: ItemStack?): NBTTagCompound? { - return if (item == null || !item.hasTagCompound()) { - null - } else item.getSubCompound("ExtraAttributes", false) - } - - private fun NBTTagList.asStringSet() = (0..tagCount()).mapTo(hashSetOf()) { getStringTagAt(it) } -}
\ No newline at end of file |