summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/items/abilitycooldown
diff options
context:
space:
mode:
authorLorenz <lo.scherf@gmail.com>2022-08-17 03:05:34 +0200
committerLorenz <lo.scherf@gmail.com>2022-08-17 03:05:34 +0200
commitef58a94bf31868c4b53218474f0be04c1cd93d97 (patch)
treecb56d5969f8bebf586298475a61c521229663fda /src/main/java/at/hannibal2/skyhanni/items/abilitycooldown
parent5669dbf6f68e7cacb2df6a4e37d703df8635353e (diff)
downloadskyhanni-ef58a94bf31868c4b53218474f0be04c1cd93d97.tar.gz
skyhanni-ef58a94bf31868c4b53218474f0be04c1cd93d97.tar.bz2
skyhanni-ef58a94bf31868c4b53218474f0be04c1cd93d97.zip
moving packets around
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/items/abilitycooldown')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/ItemAbilityCooldown.kt215
-rw-r--r--src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/WitherImpactDetection.kt74
2 files changed, 0 insertions, 289 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/ItemAbilityCooldown.kt b/src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/ItemAbilityCooldown.kt
deleted file mode 100644
index 7ddf1d2a5..000000000
--- a/src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/ItemAbilityCooldown.kt
+++ /dev/null
@@ -1,215 +0,0 @@
-package at.hannibal2.skyhanni.items.abilitycooldown
-
-import at.hannibal2.skyhanni.ItemRenderBackground.Companion.background
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.events.GuiRenderItemEvent
-import at.hannibal2.skyhanni.events.LorenzActionBarEvent
-import at.hannibal2.skyhanni.utils.ItemUtils
-import at.hannibal2.skyhanni.utils.ItemUtils.cleanName
-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.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import net.minecraftforge.fml.common.gameevent.TickEvent
-
-class ItemAbilityCooldown {
-
- var lastAbility = ""
- var tick = 0
- val items = mutableMapOf<ItemStack, ItemText>()
- val witherImpactDetection = WitherImpactDetection(this)
-
- init {
- MinecraftForge.EVENT_BUS.register(witherImpactDetection)
- }
-
- fun clickWitherImpact() {
- Ability.WITHER_IMPACT.click()
- }
-
- @SubscribeEvent
- fun onActionBar(event: LorenzActionBarEvent) {
- if (!isEnabled()) return
-
- val message: String = event.message
- if (message.contains(" (§6")) {
- if (message.contains("§b) ")) {
- val name: String = message.between(" (§6", "§b) ")
- if (name == lastAbility) return
- lastAbility = name
- for (ability in Ability.values()) {
- if (ability.abilityName == name) {
- click(ability)
- return
- }
- }
- return
- }
- }
- lastAbility = ""
- }
-
- private fun isEnabled(): Boolean {
- return LorenzUtils.inSkyblock && SkyHanniMod.feature.abilities.itemAbilityCooldown
- }
-
- private fun click(ability: Ability) {
-// if (ability.isActive()) return
- if (!ability.actionBarDetection) return
- ability.click()
- }
-
- @SubscribeEvent
- fun onTick(event: TickEvent.ClientTickEvent) {
- if (!isEnabled()) return
-
- tick++
- if (tick % 2 == 0) {
- checkHotbar()
- }
- }
-
- 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)
- if (ability != null) {
-
- if (ability.isOnCooldown()) {
- val duration: Long = ability.lastClick + ability.getCooldown() - System.currentTimeMillis()
- val color = if (duration < 600) LorenzColor.RED else LorenzColor.YELLOW
- items[stack] = ItemText(color, ability.getDurationText(), true)
- } else {
- items[stack] = ItemText(LorenzColor.GREEN, "R", false)
- }
- }
- }
-
- }
-
- @SubscribeEvent
- fun onRenderItemOverlayPost(event: GuiRenderItemEvent.RenderOverlayEvent.Post) {
- if (!isEnabled()) return
-
- val item = event.stack ?: return
- if (item.stackSize != 1) return
-
- var stackTip = ""
-
- val guiOpen = Minecraft.getMinecraft().currentScreen != null
- val itemText = items.filter { it.key == item }
- .firstNotNullOfOrNull { it.value } ?: return
- if (guiOpen && !itemText.onCooldown) return
-
- val color = itemText.color
- stackTip = color.getChatColor() + itemText.text
-
- if (SkyHanniMod.feature.abilities.itemAbilityCooldownBackground) {
- var opacity = 130
- if (color == LorenzColor.GREEN) {
- opacity = 80
- }
- item.background = color.addOpacity(opacity).rgb
- }
-
- if (stackTip.isNotEmpty()) {
- GlStateManager.disableLighting()
- GlStateManager.disableDepth()
- GlStateManager.disableBlend()
- //TODO add option to change the size
- event.fontRenderer.drawStringWithShadow(
- stackTip,
- (event.x + 17 - event.fontRenderer.getStringWidth(stackTip)).toFloat(),
- (event.y + 9).toFloat(),
- 16777215
- )
- GlStateManager.enableLighting()
- GlStateManager.enableDepth()
- }
- }
-
- private fun hasAbility(itemName: String): Ability? {
- for (ability in Ability.values()) {
- 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()
- }
-
- 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/items/abilitycooldown/WitherImpactDetection.kt b/src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/WitherImpactDetection.kt
deleted file mode 100644
index 4bc2939fd..000000000
--- a/src/main/java/at/hannibal2/skyhanni/items/abilitycooldown/WitherImpactDetection.kt
+++ /dev/null
@@ -1,74 +0,0 @@
-package at.hannibal2.skyhanni.items.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