diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-09-29 19:11:29 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2022-09-29 19:11:29 +0200 |
commit | f94ed94adc7bb33d5a766e782f06a3ffc5730c78 (patch) | |
tree | 3a80731bb947e9353da9d3b55d9c0a6819b298ae /src/main | |
parent | 7a1d70b8abdaf65251c10d092875a425f7c39e69 (diff) | |
download | skyhanni-f94ed94adc7bb33d5a766e782f06a3ffc5730c78.tar.gz skyhanni-f94ed94adc7bb33d5a766e782f06a3ffc5730c78.tar.bz2 skyhanni-f94ed94adc7bb33d5a766e782f06a3ffc5730c78.zip |
made dagger helper react even faster
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/slayer/blaze/BlazeSlayerDaggerHelper.kt | 30 |
1 files changed, 12 insertions, 18 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 cdd3a44d0..bcdbbc8e2 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 @@ -2,15 +2,15 @@ package at.hannibal2.skyhanni.features.slayer.blaze 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.name import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.NumberUtil.roundToPrecision import net.minecraft.client.Minecraft -import net.minecraft.client.entity.EntityPlayerSP import net.minecraft.client.gui.ScaledResolution import net.minecraft.client.renderer.GlStateManager -import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement +import net.minecraft.item.ItemStack import net.minecraft.network.play.server.S45PacketTitle import net.minecraftforge.client.event.RenderGameOverlayEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -31,7 +31,8 @@ class BlazeSlayerDaggerHelper { fun onTick(event: TickEvent.ClientTickEvent) { if (!isEnabled()) return - val dagger = getDaggerInHand() + val player = Minecraft.getMinecraft().thePlayer + val dagger = getDaggerInHand(player.inventory.mainInventory[player.inventory.currentItem]) if (dagger != null) { setDaggerText(dagger) return @@ -88,9 +89,8 @@ class BlazeSlayerDaggerHelper { } } - private fun getDaggerInHand(): Dagger? { - val player = Minecraft.getMinecraft().thePlayer - val itemName = getName(player) + private fun getDaggerInHand(stack: ItemStack?): Dagger? { + val itemName = stack?.name ?: "" for (dagger in Dagger.values()) { if (dagger.daggerNames.any { itemName.contains(it) }) { return dagger @@ -100,11 +100,6 @@ class BlazeSlayerDaggerHelper { return null } - private fun getName(player: EntityPlayerSP): String { - val itemStack = player.inventory.mainInventory[player.inventory.currentItem] ?: return "" - return itemStack.name ?: "" - } - @SubscribeEvent fun onReceiveCurrentShield(event: PacketEvent.ReceiveEvent) { if (!isEnabled()) return @@ -133,17 +128,16 @@ class BlazeSlayerDaggerHelper { } @SubscribeEvent - fun onRightClick(event: PacketEvent.SendEvent) { + fun onItemClick(event: ItemClickInHandEvent) { if (!isEnabled()) return if (clientSideClicked) return + if (event.clickType != ItemClickInHandEvent.ClickType.RIGHT_CLICK) return - val packet = event.packet + val itemInHand = event.itemInHand ?: return + val dagger = getDaggerInHand(itemInHand) + dagger?.shields?.forEach { shield -> shield.active = !shield.active } + clientSideClicked = true - if (packet is C08PacketPlayerBlockPlacement) { - val dagger = getDaggerInHand() - dagger?.shields?.forEach { shield -> shield.active = !shield.active } - clientSideClicked = true - } } enum class Dagger(val daggerNames: List<String>, vararg val shields: HellionShield) { |