1
+ package com.lambda.client.module.modules.player
2
+
3
+ import com.lambda.client.event.events.PacketEvent
4
+ import com.lambda.client.event.listener.listener
5
+ import com.lambda.client.module.Category
6
+ import com.lambda.client.module.Module
7
+ import com.lambda.client.util.threads.runSafe
8
+ import net.minecraft.entity.player.EntityPlayer
9
+ import net.minecraft.inventory.ClickType
10
+ import net.minecraft.item.ItemStack
11
+ import net.minecraft.network.play.client.CPacketClickWindow
12
+ import net.minecraft.network.play.server.SPacketConfirmTransaction
13
+
14
+ object NoGhostItems : Module(
15
+ name = " NoGhostItems" ,
16
+ description = " Syncs inventory transactions for strict environments" ,
17
+ category = Category .PLAYER
18
+ ) {
19
+ private val timeout by setting(" Timeout in ticks" , 5 , 1 .. 50 , 1 )
20
+
21
+ private var pendingTransaction: InventoryTransaction ? = null
22
+ private var lastPending = System .currentTimeMillis()
23
+
24
+ init {
25
+ listener<PacketEvent .Receive > { event ->
26
+ if (event.packet is SPacketConfirmTransaction ) {
27
+ pendingTransaction?.let {
28
+ it.player.openContainer.slotClick(it.slotId, it.mouseButton, it.type, it.player)
29
+ pendingTransaction = null
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ fun handleWindowClick (windowId : Int , slotId : Int , mouseButton : Int , type : ClickType , player : EntityPlayer ) {
36
+ val transaction = InventoryTransaction (windowId, slotId, mouseButton, type, player)
37
+
38
+ if (pendingTransaction == null || System .currentTimeMillis() - lastPending > timeout * 50L ) {
39
+ val transactionID = transaction.player.openContainer.getNextTransactionID(transaction.player.inventory)
40
+ pendingTransaction = transaction
41
+ lastPending = System .currentTimeMillis()
42
+
43
+ runSafe {
44
+ connection.sendPacket(CPacketClickWindow (transaction.windowId, transaction.slotId, transaction.mouseButton, transaction.type, ItemStack .EMPTY , transactionID))
45
+ }
46
+ }
47
+ }
48
+
49
+ data class InventoryTransaction (val windowId : Int , val slotId : Int , val mouseButton : Int , val type : ClickType , val player : EntityPlayer ) {
50
+ override fun toString (): String {
51
+ return " windowId: $windowId slotId: $slotId mouseButton: $mouseButton type: ${type.name} player: ${player.name} "
52
+ }
53
+ }
54
+ }
0 commit comments