diff options
author | Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> | 2024-03-07 11:26:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-07 11:26:26 +0100 |
commit | 1181ef837104b4a5f68de6cf5793b21ad7573e03 (patch) | |
tree | fe58885a8cfb5d2b6544278af98b960b9379eb84 /src/main/java/at | |
parent | 6c0bf6dc7e9abea87c446e65d4a95e499ee572b6 (diff) | |
download | skyhanni-1181ef837104b4a5f68de6cf5793b21ad7573e03.tar.gz skyhanni-1181ef837104b4a5f68de6cf5793b21ad7573e03.tar.bz2 skyhanni-1181ef837104b4a5f68de6cf5793b21ad7573e03.zip |
Fix: EntityClick cancellability (#1072)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt index bac3b6594..acd331cc8 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt @@ -5,42 +5,60 @@ import at.hannibal2.skyhanni.events.EntityClickEvent import at.hannibal2.skyhanni.events.ItemClickEvent import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.utils.InventoryUtils -import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.toLorenzVec import net.minecraft.client.Minecraft +import net.minecraft.network.play.client.C02PacketUseEntity import net.minecraft.network.play.client.C07PacketPlayerDigging import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement import net.minecraft.network.play.client.C0APacketAnimation import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.InputEvent class ItemClickData { @SubscribeEvent fun onItemClickSend(event: PacketEvent.SendEvent) { val packet = event.packet - if (packet is C08PacketPlayerBlockPlacement) { - if (packet.placedBlockDirection != 255) { + event.isCanceled = when { + packet is C08PacketPlayerBlockPlacement -> { + if (packet.placedBlockDirection != 255) { + val position = packet.position.toLorenzVec() + BlockClickEvent(ClickType.RIGHT_CLICK, position, packet.stack).postAndCatch() + } else { + ItemClickEvent(InventoryUtils.getItemInHand(), ClickType.RIGHT_CLICK).postAndCatch() + } + } + + packet is C07PacketPlayerDigging && packet.status == C07PacketPlayerDigging.Action.START_DESTROY_BLOCK -> { val position = packet.position.toLorenzVec() - event.isCanceled = BlockClickEvent(ClickType.RIGHT_CLICK, position, packet.stack).postAndCatch() - } else { - event.isCanceled = ItemClickEvent(InventoryUtils.getItemInHand(), ClickType.RIGHT_CLICK).postAndCatch() + val blockClickCancelled = + BlockClickEvent(ClickType.LEFT_CLICK, position, InventoryUtils.getItemInHand()).postAndCatch() + ItemClickEvent(InventoryUtils.getItemInHand(), ClickType.LEFT_CLICK).also { + it.isCanceled = blockClickCancelled + }.postAndCatch() + } + + packet is C0APacketAnimation -> { + ItemClickEvent(InventoryUtils.getItemInHand(), ClickType.LEFT_CLICK).postAndCatch() + } + + packet is C02PacketUseEntity -> { + val clickType = when (packet.action) { + C02PacketUseEntity.Action.INTERACT -> ClickType.RIGHT_CLICK + C02PacketUseEntity.Action.ATTACK -> ClickType.LEFT_CLICK + C02PacketUseEntity.Action.INTERACT_AT -> ClickType.RIGHT_CLICK + else -> return + } + val clickedEntity = packet.getEntityFromWorld(Minecraft.getMinecraft().theWorld) ?: return + EntityClickEvent(clickType, clickedEntity, InventoryUtils.getItemInHand()).postAndCatch() + } + + else -> { + return } - } - if (packet is C07PacketPlayerDigging && packet.status == C07PacketPlayerDigging.Action.START_DESTROY_BLOCK) { - val position = packet.position.toLorenzVec() - val blockClickCancelled = - BlockClickEvent(ClickType.LEFT_CLICK, position, InventoryUtils.getItemInHand()).postAndCatch() - event.isCanceled = ItemClickEvent(InventoryUtils.getItemInHand(), ClickType.LEFT_CLICK).also { - it.isCanceled = blockClickCancelled - }.postAndCatch() - } - if (packet is C0APacketAnimation) { - event.isCanceled = ItemClickEvent(InventoryUtils.getItemInHand(), ClickType.LEFT_CLICK).postAndCatch() } } - @SubscribeEvent + /* @SubscribeEvent fun onEntityClick(event: InputEvent) { if (!LorenzUtils.inSkyBlock) return @@ -60,5 +78,5 @@ class ItemClickData { if (clickedEntity == null) return EntityClickEvent(clickType, clickedEntity, InventoryUtils.getItemInHand()).postAndCatch() - } + } */ } |