blob: e7fa753319244eb7bcbda74d3e5b68b4bf3ddc68 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
package at.hannibal2.skyhanni.data
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.BlockClickEvent
import at.hannibal2.skyhanni.events.EntityClickEvent
import at.hannibal2.skyhanni.events.ItemClickEvent
import at.hannibal2.skyhanni.events.minecraft.packet.PacketSentEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.InventoryUtils
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
@SkyHanniModule
object ItemClickData {
@HandleEvent
fun onItemClickSend(event: PacketSentEvent) {
val packet = event.packet
val cancelled = 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()
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 (cancelled) {
event.cancel()
}
}
/* @SubscribeEvent
fun onEntityClick(event: InputEvent) {
if (!LorenzUtils.inSkyBlock) return
val minecraft = Minecraft.getMinecraft()
val attackKey = minecraft.gameSettings.keyBindAttack
val useKey = minecraft.gameSettings.keyBindUseItem
val clickType = when {
attackKey.isKeyDown -> ClickType.LEFT_CLICK
useKey.isKeyDown -> ClickType.RIGHT_CLICK
else -> return
}
val clickedEntity = minecraft.pointedEntity
if (minecraft.thePlayer == null) return
if (clickedEntity == null) return
EntityClickEvent(clickType, clickedEntity, InventoryUtils.getItemInHand()).postAndCatch()
} */
}
|