LiquidSense Dev ChestStealer module 2 files, 684 lines

LiquidSense Dev ChestStealer: Full Source Analysis

LiquidSense Dev's ChestStealer drains chests from a Render3DEvent that fires every frame: while a GuiChest is open and the randomized delay has passed, it shift-clicks one slot through…

net/ccbluex/liquidbounce/features/module/modules/world/ChestStealer.kt · GitHub source ↗

Published 2026-08-12 · Updated 2026-08-12

Analysis

Overview

LiquidSense Dev's ChestStealer drains chests from a Render3DEvent that fires every frame: while a GuiChest is open and the randomized delay has passed, it shift-clicks one slot through GuiContainer.handleMouseClick, which emits C0EPacketClickWindow mode-1 packets against the chest window. Filters gate the steal: NoCompass skips while holding a compass, ChestTitle requires the container name to contain Chest, OnlyItems skips block stacks, Useful runs every stack through InventoryCleaner.isUseful, and CloseOnFull stops when the player's 36 main-inventory slots are full. The close and the silent-stealer mode are keyed off the window id reported by S30PacketWindowItems so the GUI is only released for the window the server actually opened.

Frame-driven steal loop

onRender3D is a render-frame handler, not a tick handler, so the steal cadence is bounded by the delay gate rather than the frame rate. nextDelay is drawn from TimeUtils.randomDelay(minDelay, maxDelay), defaults 150-200ms over a clamped 0-400ms range with cross-clamping on either value changing. In the randomized mode the module collects every stealable slot, picks one with kotlin.random.Random, and moves it, repeating in a do-while as long as the delay keeps passing, so several slots can move within one frame when the delay is at the floor. The non-random mode walks the chest rows in order and moves every slot whose gate is open. Only the chest's own rows are scanned (inventoryRows times 9), never the player's bottom slots.

Filters

noCompass returns early while the held item's unlocalized name is item.compass; chestTitle requires the lower inventory's name to contain the display name of a minecraft:chest item stack; onlyItems skips ItemBlock stacks; useful runs InventoryCleaner.isUseful(stack, -1), which classifies swords and tools against the equipped slot and rejects junk; closeOnFull reads fullInventory, true when every one of the 36 main-inventory slots is non-null. isEmpty mirrors the useful filter over the chest rows and feeds the auto-close branch. The chestTitle filter reads lowerChestInventory, which in the chest screen is the player's own inventory section titled with the fixed container.inventory string, so the contains-Chest test effectively never matches and enabling that toggle stalls the stealer entirely.

Window id matching and silent close

onPacket stores the window id from every S30PacketWindowItems into contentReceived. The auto-close branch only fires when screen.inventorySlots.windowId equals contentReceived and the close delay has passed, so the GUI is released only after the server refreshed the very contents the client is looking at. The silent mode (spelled slientstealer in the source) closes the GUI as soon as that match holds, which drops the chest screen before the player presses a key; because the steal gate requires a live GuiChest, clicking stops at the close. The module imports C03PacketPlayer but never references it; the only packet it actually sends is the C0E generated inside handleMouseClick.

source ChestStealer.kt

ChestStealer.kt199 lines · JavaOriginal ↗
1
/*
2
 * LiquidBounce Hacked Client
3
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
4
 * https://github.com/CCBlueX/LiquidBounce/
5
 */
6
package net.ccbluex.liquidbounce.features.module.modules.world
7
8
import net.ccbluex.liquidbounce.LiquidBounce
9
import net.ccbluex.liquidbounce.event.EventTarget
10
import net.ccbluex.liquidbounce.event.PacketEvent
11
import net.ccbluex.liquidbounce.event.Render3DEvent
12
import net.ccbluex.liquidbounce.features.module.Module
13
import net.ccbluex.liquidbounce.features.module.ModuleCategory
14
import net.ccbluex.liquidbounce.features.module.ModuleInfo
15
import net.ccbluex.liquidbounce.features.module.modules.player.InventoryCleaner
16
import net.ccbluex.liquidbounce.utils.timer.MSTimer
17
import net.ccbluex.liquidbounce.utils.timer.TimeUtils
18
import net.ccbluex.liquidbounce.value.BoolValue
19
import net.ccbluex.liquidbounce.value.IntegerValue
20
import net.minecraft.client.gui.inventory.GuiChest
21
import net.minecraft.inventory.Slot
22
import net.minecraft.item.Item
23
import net.minecraft.item.ItemBlock
24
import net.minecraft.item.ItemStack
25
import net.minecraft.network.play.client.C03PacketPlayer
26
import net.minecraft.network.play.server.S30PacketWindowItems
27
import net.minecraft.util.ResourceLocation
28
import kotlin.random.Random
29
30
@ModuleInfo(name = "ChestStealer", description = "Automatically steals all items from a chest.", category = ModuleCategory.WORLD)
31
class ChestStealer : Module() {
32
33
    /**
34
     * OPTIONS
35
     */
36
37
    private val maxDelayValue: IntegerValue = object : IntegerValue("MaxDelay", 200, 0, 400) {
38
        override fun onChanged(oldValue: Int, newValue: Int) {
39
            val i = minDelayValue.get()
40
            if (i > newValue)
41
                set(i)
42
43
            nextDelay = TimeUtils.randomDelay(minDelayValue.get(), get())
44
        }
45
    }
46
47
    private val minDelayValue: IntegerValue = object : IntegerValue("MinDelay", 150, 0, 400) {
48
        override fun onChanged(oldValue: Int, newValue: Int) {
49
            val i = maxDelayValue.get()
50
51
            if (i < newValue)
52
                set(i)
53
54
            nextDelay = TimeUtils.randomDelay(get(), maxDelayValue.get())
55
        }
56
    }
57
58
    private val takeRandomizedValue = BoolValue("TakeRandomized", false)
59
    private val onlyItemsValue = BoolValue("OnlyItems", false)
60
    private val noCompassValue = BoolValue("NoCompass", false)
61
    private val usefulValue = BoolValue("Useful", true)
62
    private val autoCloseValue = BoolValue("AutoClose", true)
63
    private val slientstealer = BoolValue("SlientStealer",false)
64
65
    private val autoCloseMaxDelayValue: IntegerValue = object : IntegerValue("AutoCloseMaxDelay", 0, 0, 400) {
66
        override fun onChanged(oldValue: Int, newValue: Int) {
67
            val i = autoCloseMinDelayValue.get()
68
            if (i > newValue) set(i)
69
            nextCloseDelay = TimeUtils.randomDelay(autoCloseMinDelayValue.get(), this.get())
70
        }
71
    }
72
73
    private val autoCloseMinDelayValue: IntegerValue = object : IntegerValue("AutoCloseMinDelay", 0, 0, 400) {
74
        override fun onChanged(oldValue: Int, newValue: Int) {
75
            val i = autoCloseMaxDelayValue.get()
76
            if (i < newValue) set(i)
77
            nextCloseDelay = TimeUtils.randomDelay(this.get(), autoCloseMaxDelayValue.get())
78
        }
79
    }
80
81
    private val closeOnFullValue = BoolValue("CloseOnFull", true)
82
    private val chestTitleValue = BoolValue("ChestTitle", false)
83
84
    /**
85
     * VALUES
86
     */
87
88
    private val delayTimer = MSTimer()
89
    private var nextDelay = TimeUtils.randomDelay(minDelayValue.get(), maxDelayValue.get())
90
91
    private val autoCloseTimer = MSTimer()
92
    private var nextCloseDelay = TimeUtils.randomDelay(autoCloseMinDelayValue.get(), autoCloseMaxDelayValue.get())
93
94
    private var contentReceived = 0
95
96
    override val tag: String?
97
        get() = when {
98
            slientstealer.get() -> "SlientStealer"
99
            else -> "Vanilla"
100
        }
101
102
103
    @EventTarget
104
    fun onRender3D(event: Render3DEvent?) {
105
        val screen = mc.currentScreen
106
107
        if (screen !is GuiChest || !delayTimer.hasTimePassed(nextDelay)) {
108
            autoCloseTimer.reset()
109
            return
110
        }
111
112
        // No Compass
113
        if (noCompassValue.get() && mc.thePlayer.inventory.getCurrentItem()?.item?.unlocalizedName == "item.compass")
114
            return
115
116
        // Chest title
117
        if (chestTitleValue.get() && (screen.lowerChestInventory == null || !screen.lowerChestInventory.name.contains(ItemStack(Item.itemRegistry.getObject(ResourceLocation("minecraft:chest"))).displayName)))
118
            return
119
120
        // inventory cleaner
121
        val inventoryCleaner = LiquidBounce.moduleManager[InventoryCleaner::class.java] as InventoryCleaner
122
123
        // Is empty?
124
        if (!isEmpty(screen) && !(closeOnFullValue.get() && fullInventory)) {
125
            autoCloseTimer.reset()
126
127
            // Randomized
128
            if (takeRandomizedValue.get()) {
129
                do {
130
                    val items = mutableListOf<Slot>()
131
132
                    for (slotIndex in 0 until screen.inventoryRows * 9) {
133
                        val slot = screen.inventorySlots.inventorySlots[slotIndex]
134
135
                        if (slot.stack != null && (!onlyItemsValue.get() || slot.stack.item !is ItemBlock) && (!usefulValue.get() || inventoryCleaner.isUseful(slot.stack, -1)))
136
                            items.add(slot)
137
                    }
138
139
                    val randomSlot = Random.nextInt(items.size)
140
                    val slot = items[randomSlot]
141
142
                    move(screen, slot)
143
                } while (delayTimer.hasTimePassed(nextDelay) && items.isNotEmpty())
144
                return
145
            }
146
147
            // Non randomized
148
            for (slotIndex in 0 until screen.inventoryRows * 9) {
149
                val slot = screen.inventorySlots.inventorySlots[slotIndex]
150
151
                if (delayTimer.hasTimePassed(nextDelay) && slot.stack != null &&
152
                        (!onlyItemsValue.get() || slot.stack.item !is ItemBlock) && (!usefulValue.get() || inventoryCleaner.isUseful(slot.stack, -1))) {
153
                    move(screen, slot)
154
                }
155
            }
156
        } else if (autoCloseValue.get() && screen.inventorySlots.windowId == contentReceived && autoCloseTimer.hasTimePassed(nextCloseDelay)) {
157
            mc.thePlayer.closeScreen()
158
            nextCloseDelay = TimeUtils.randomDelay(autoCloseMinDelayValue.get(), autoCloseMaxDelayValue.get())
159
        }
160
        if (slientstealer.get() && screen.inventorySlots.windowId == contentReceived && autoCloseTimer.hasTimePassed(nextCloseDelay)) {
161
            mc.thePlayer.closeScreen()
162
            nextCloseDelay = TimeUtils.randomDelay(autoCloseMinDelayValue.get(), autoCloseMaxDelayValue.get())
163
        }
164
    }
165
166
    fun getTrue(): BoolValue {
167
        return slientstealer
168
    }
169
170
    @EventTarget
171
    private fun onPacket(event: PacketEvent) {
172
        val packet = event.packet
173
174
        if (packet is S30PacketWindowItems)
175
            contentReceived = packet.func_148911_c()
176
    }
177
178
    private fun move(screen: GuiChest, slot: Slot) {
179
        screen.handleMouseClick(slot, slot.slotNumber, 0, 1)
180
        delayTimer.reset()
181
        nextDelay = TimeUtils.randomDelay(minDelayValue.get(), maxDelayValue.get())
182
    }
183
184
    private fun isEmpty(chest: GuiChest): Boolean {
185
        val inventoryCleaner = LiquidBounce.moduleManager[InventoryCleaner::class.java] as InventoryCleaner
186
187
        for (i in 0 until chest.inventoryRows * 9) {
188
            val slot = chest.inventorySlots.inventorySlots[i]
189
190
            if (slot.stack != null && (!onlyItemsValue.get() || slot.stack.item !is ItemBlock) && (!usefulValue.get() || inventoryCleaner.isUseful(slot.stack, -1)))
191
                return false
192
        }
193
194
        return true
195
    }
196
197
    private val fullInventory: Boolean
198
        get() = mc.thePlayer.inventory.mainInventory.none { it == null }
199
}

What this file does

The whole module is two event handlers and a move helper. onRender3D performs the steal: delay gate, filter chain, slot selection, then move() which calls screen.handleMouseClick(slot, slot.slotNumber, 0, 1); that is the vanilla shift-click path and the source of every C0EPacketClickWindow the module emits. onPacket consumes S30PacketWindowItems for the window-id match that guards the close branches. The value objects cross-clamp min/max on change and redraw nextDelay so the band never inverts.

The dead C03PacketPlayer import is a telling detail: the module is pure container manipulation and never touches movement packets, so its server-side signature is a stream of window clicks, not position changes. The ChestTitle filter reading lowerChestInventory (the player inventory section) instead of the upper chest section makes that toggle effectively inert, and the silent mode is simply an early close rather than a true continue-stealing-after-close, because every handler returns when the screen is no longer a GuiChest.

source InventoryCleaner.kt (useful filter)

InventoryCleaner.kt485 lines · JavaOriginal ↗
1
/*
2
 * LiquidBounce Hacked Client
3
 * A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
4
 * https://github.com/CCBlueX/LiquidBounce/
5
 */
6
package net.ccbluex.liquidbounce.features.module.modules.player
7
8
import net.ccbluex.liquidbounce.event.EventTarget
9
import net.ccbluex.liquidbounce.event.UpdateEvent
10
import net.ccbluex.liquidbounce.features.module.Module
11
import net.ccbluex.liquidbounce.features.module.ModuleCategory
12
import net.ccbluex.liquidbounce.features.module.ModuleInfo
13
import net.ccbluex.liquidbounce.features.module.modules.combat.AutoArmor
14
import net.ccbluex.liquidbounce.injection.implementations.IItemStack
15
import net.ccbluex.liquidbounce.utils.ClientUtils
16
import net.ccbluex.liquidbounce.utils.InventoryUtils
17
import net.ccbluex.liquidbounce.utils.MovementUtils
18
import net.ccbluex.liquidbounce.utils.item.ArmorPiece
19
import net.ccbluex.liquidbounce.utils.item.ItemUtils
20
import net.ccbluex.liquidbounce.utils.timer.TimeUtils
21
import net.ccbluex.liquidbounce.value.BoolValue
22
import net.ccbluex.liquidbounce.value.IntegerValue
23
import net.ccbluex.liquidbounce.value.ListValue
24
import net.minecraft.client.gui.inventory.GuiInventory
25
import net.minecraft.enchantment.Enchantment
26
import net.minecraft.init.Blocks
27
import net.minecraft.item.*
28
import net.minecraft.network.play.client.C0DPacketCloseWindow
29
import net.minecraft.network.play.client.C16PacketClientStatus
30
import net.minecraft.potion.Potion
31
32
33
@ModuleInfo(name = "InventoryCleaner", description = "Automatically throws away useless items.", category = ModuleCategory.PLAYER)
34
class InventoryCleaner : Module() {
35
36
    /**
37
     * OPTIONS
38
     */
39
40
    private val maxDelayValue: IntegerValue = object : IntegerValue("MaxDelay", 600, 0, 1000) {
41
        override fun onChanged(oldValue: Int, newValue: Int) {
42
            val minCPS = minDelayValue.get()
43
            if (minCPS > newValue) set(minCPS)
44
        }
45
    }
46
47
    private val minDelayValue: IntegerValue = object : IntegerValue("MinDelay", 400, 0, 1000) {
48
        override fun onChanged(oldValue: Int, newValue: Int) {
49
            val maxDelay = maxDelayValue.get()
50
            if (maxDelay < newValue) set(maxDelay)
51
        }
52
    }
53
54
    private val maxBlockStacksValue = object : IntegerValue("MaxBlockStacks", 5, 0, 10) {
55
        override fun onChanged(oldValue: Int, newValue: Int) {
56
            if (newValue < minimum) {
57
                set(minimum)
58
            }
59
        }
60
    }
61
    private val maxEnchantedBooksValue = object : IntegerValue("MaxEnchantedBooks", 5, 0, 10) {
62
        override fun onChanged(oldValue: Int, newValue: Int) {
63
            if (newValue < minimum) {
64
                set(minimum)
65
            }
66
        }
67
    }
68
    private val maxWaterBucketsValue = object : IntegerValue("MaxWaterBuckets", 3, 0, 10) {
69
        override fun onChanged(oldValue: Int, newValue: Int) {
70
            if (newValue < minimum) {
71
                set(minimum)
72
            }
73
        }
74
    }
75
    private val maxLavaBucketsValue = object : IntegerValue("MaxLavaBuckets", 3, 0, 10) {
76
        override fun onChanged(oldValue: Int, newValue: Int) {
77
            if (newValue < minimum) {
78
                set(minimum)
79
            }
80
        }
81
    }
82
83
84
    private val invOpenValue = BoolValue("InvOpen", false)
85
    private val simulateInventory = BoolValue("SimulateInventory", true)
86
    private val noMoveValue = BoolValue("NoMove", false)
87
    private val ignoreVehiclesValue = BoolValue("IgnoreVehicles", false)
88
    private val hotbarValue = BoolValue("Hotbar", true)
89
    private val randomSlotValue = BoolValue("RandomSlot", false)
90
    private val cleanValue = BoolValue("Clean", true)
91
    private val sortValue = BoolValue("Sort", true)
92
    private val itemDelayValue = IntegerValue("ItemDelay", 0, 0, 5000)
93
94
    private val items = arrayOf("None", "Ignore", "Sword", "Bow", "Pickaxe", "Axe", "Food", "Block", "Water", "Gapple", "Pearl", "SpeedPotion", "HealPotion")
95
    private val sortSlot1Value = ListValue("SortSlot-1", items, "Sword")
96
    private val sortSlot2Value = ListValue("SortSlot-2", items, "Bow")
97
    private val sortSlot3Value = ListValue("SortSlot-3", items, "Pickaxe")
98
    private val sortSlot4Value = ListValue("SortSlot-4", items, "Axe")
99
    private val sortSlot5Value = ListValue("SortSlot-5", items, "None")
100
    private val sortSlot6Value = ListValue("SortSlot-6", items, "None")
101
    private val sortSlot7Value = ListValue("SortSlot-7", items, "Food")
102
    private val sortSlot8Value = ListValue("SortSlot-8", items, "Block")
103
    private val sortSlot9Value = ListValue("SortSlot-9", items, "Block")
104
105
    /**
106
     * VALUES
107
     */
108
109
    private var delay = 0L
110
111
    @EventTarget
112
    fun onUpdate(event: UpdateEvent) {
113
        if ((mc.thePlayer!!.capabilities.allowFlying && mc.thePlayer!!.capabilities.isFlying) || !InventoryUtils.CLICK_TIMER.hasTimePassed(delay) ||
114
                mc.currentScreen !is GuiInventory && invOpenValue.get() ||
115
                noMoveValue.get() && MovementUtils.isMoving() ||
116
                mc.thePlayer.openContainer != null && mc.thePlayer.openContainer.windowId != 0)
117
            return
118
119
        if (sortValue.get())
120
            sortHotbar()
121
122
        while (InventoryUtils.CLICK_TIMER.hasTimePassed(delay) && cleanValue.get()) {
123
            val garbageItems = items(9, if (hotbarValue.get()) 45 else 36)
124
                    .filter { !isUseful(it.value, it.key) }
125
                    .keys
126
                    .toMutableList()
127
128
            // Shuffle items
129
            if (randomSlotValue.get())
130
                garbageItems.shuffle()
131
132
            val garbageItem = garbageItems.firstOrNull() ?: break
133
134
            // Drop all useless items
135
            val openInventory = mc.currentScreen !is GuiInventory && simulateInventory.get()
136
137
            if (openInventory)
138
                mc.netHandler.addToSendQueue(C16PacketClientStatus(C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT))
139
140
            mc.playerController.windowClick(mc.thePlayer.openContainer.windowId, garbageItem, 4, 4, mc.thePlayer)
141
142
            if (openInventory)
143
                mc.netHandler.addToSendQueue(C0DPacketCloseWindow())
144
145
            delay = TimeUtils.randomDelay(minDelayValue.get(), maxDelayValue.get())
146
        }
147
    }
148
149
    /**
150
     * Checks if the item is useful
151
     *
152
     * @param slot Slot id of the item. If the item isn't in the inventory -1
153
     * @return Returns true when the item is useful
154
     */
155
    fun isUseful(itemStack: ItemStack, slot: Int): Boolean {
156
        return try {
157
            val item = itemStack.item
158
159
            if (item is ItemSword || item is ItemTool) {
160
                if (slot >= 36 && findBetterItem(slot - 36, mc.thePlayer.inventory.getStackInSlot(slot - 36)) == slot - 36)
161
                    return true
162
163
                for (i in 0..8) {
164
                    if (type(i).equals("sword", true) && item is ItemSword
165
                            || type(i).equals("pickaxe", true) && item is ItemPickaxe
166
                            || type(i).equals("axe", true) && item is ItemAxe) {
167
                        if (findBetterItem(i, mc.thePlayer.inventory.getStackInSlot(i)) == null) {
168
                            return true
169
                        }
170
                    }
171
                }
172
173
                val damage = (itemStack.attributeModifiers["generic.attackDamage"].firstOrNull()?.amount
174
                        ?: 0.0) + 1.25 * ItemUtils.getEnchantment(itemStack, Enchantment.sharpness)
175
176
                items(0, 45).none { (_, stack) ->
177
                    stack != itemStack && stack.javaClass == itemStack.javaClass
178
                            && damage <= (stack.attributeModifiers["generic.attackDamage"].firstOrNull()?.amount
179
                            ?: 0.0) + 1.25 * ItemUtils.getEnchantment(stack, Enchantment.sharpness)
180
                }
181
            } else if (item is ItemBow) {
182
                val currPower = ItemUtils.getEnchantment(itemStack, Enchantment.power)
183
184
                items().none { (_, stack) ->
185
                    itemStack != stack && stack.item is ItemBow &&
186
                            currPower <= ItemUtils.getEnchantment(stack, Enchantment.power)
187
                }
188
            } else if (item is ItemArmor) {
189
                val currArmor = ArmorPiece(itemStack, slot)
190
191
                items().none { (slot, stack) ->
192
                    if (stack != itemStack && stack.item is ItemArmor) {
193
                        val armor = ArmorPiece(stack, slot)
194
195
                        if (armor.armorType != currArmor.armorType)
196
                            false
197
                        else
198
                            AutoArmor.ARMOR_COMPARATOR.compare(currArmor, armor) <= 0
199
                    } else
200
                        false
201
                }
202
            } else if (itemStack.unlocalizedName == "item.compass") {
203
                items(0, 45).none { (_, stack) -> itemStack != stack && stack.unlocalizedName == "item.compass" }
204
            } else item is ItemFood || itemStack.unlocalizedName == "item.arrow" ||
205
                    (item is ItemBlock && getBlockStacksAmount() <= maxBlockStacksValue.get() && !itemStack.unlocalizedName.contains("flower")) || //TODO
206
                    item is ItemBed || itemStack.unlocalizedName == "item.diamond" || itemStack.unlocalizedName == "item.ingotIron" ||
207
                    item is ItemPotion || item is ItemEnderPearl ||
208
                    (itemStack.unlocalizedName == "item.enchantedBook" && getEnchantedBooksAmount() <= maxEnchantedBooksValue.get()) ||
209
                    (itemStack.unlocalizedName == "item.bucketWater" && getWaterBucketsAmount() <= maxWaterBucketsValue.get()) ||
210
                    (itemStack.unlocalizedName == "item.bucketLava" && getLavaBucketsAmount() <= maxLavaBucketsValue.get()) ||
211
                    itemStack.unlocalizedName == "item.bucket" ||
212
                    itemStack.unlocalizedName == "item.stick" ||
213
                    ignoreVehiclesValue.get() && (item is ItemBoat || item is ItemMinecart)
214
        } catch (ex: Exception) {
215
            ClientUtils.getLogger().error("(InventoryCleaner) Failed to check item: ${itemStack.unlocalizedName}.", ex)
216
217
            true
218
        }
219
    }
220
221
    private fun getBlocksAmount(): Int {
222
        var amount = 0
223
        for (i in 9..44) {
224
            val itemStack = mc.thePlayer.inventoryContainer.getSlot(i).stack
225
            if (itemStack != null && itemStack.item is ItemBlock && !itemStack.unlocalizedName.contains("flower")) amount += itemStack.stackSize
226
        }
227
        return amount
228
    }
229
230
    private fun getBlockStacksAmount(): Int {
231
        var amount = 0
232
        for (i in 9..44) {
233
            val itemStack = mc.thePlayer.inventoryContainer.getSlot(i).stack
234
            if (itemStack != null && itemStack.item is ItemBlock && !itemStack.unlocalizedName.contains("flower")) amount += 1
235
        }
236
        return amount
237
    }
238
239
    private fun getEnchantedBooksAmount(): Int {
240
        var amount = 0
241
        for (i in 9..44) {
242
            val itemStack = mc.thePlayer.inventoryContainer.getSlot(i).stack
243
            if (itemStack != null && itemStack.unlocalizedName == "item.enchantedBook") amount += 1
244
        }
245
        return amount
246
    }
247
248
    private fun getWaterBucketsAmount(): Int {
249
        var amount = 0
250
        for (i in 9..44) {
251
            val itemStack = mc.thePlayer.inventoryContainer.getSlot(i).stack
252
            if (itemStack != null && itemStack.unlocalizedName == "item.bucketWater") amount += 1
253
        }
254
        return amount
255
    }
256
257
    private fun getLavaBucketsAmount(): Int {
258
        var amount = 0
259
        for (i in 9..44) {
260
            val itemStack = mc.thePlayer.inventoryContainer.getSlot(i).stack
261
            if (itemStack != null && itemStack.unlocalizedName == "item.bucketLava") amount += 1
262
        }
263
        return amount
264
    }
265
266
    /**
267
     * INVENTORY SORTER
268
     */
269
270
    /**
271
     * Sort hotbar
272
     */
273
    private fun sortHotbar() {
274
        for (index in 0..8) {
275
            val bestItem = findBetterItem(index, mc.thePlayer.inventory.getStackInSlot(index)) ?: continue
276
277
            if (bestItem != index) {
278
                val openInventory = mc.currentScreen !is GuiInventory && simulateInventory.get()
279
280
                if (openInventory)
281
                    mc.netHandler.addToSendQueue(C16PacketClientStatus(C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT))
282
283
                mc.playerController.windowClick(0, if (bestItem < 9) bestItem + 36 else bestItem, index,
284
                        2, mc.thePlayer)
285
286
                if (openInventory)
287
                    mc.netHandler.addToSendQueue(C0DPacketCloseWindow())
288
289
                delay = TimeUtils.randomDelay(minDelayValue.get(), maxDelayValue.get())
290
                break
291
            }
292
        }
293
    }
294
295
    private fun findBetterItem(targetSlot: Int, slotStack: ItemStack?): Int? {
296
        val type = type(targetSlot)
297
298
        when (type.toLowerCase()) {
299
            "sword", "pickaxe", "axe" -> {
300
                val currentType: Class<out Item> = when {
301
                    type.equals("Sword", ignoreCase = true) -> ItemSword::class.java
302
                    type.equals("Pickaxe", ignoreCase = true) -> ItemPickaxe::class.java
303
                    type.equals("Axe", ignoreCase = true) -> ItemAxe::class.java
304
                    else -> return null
305
                }
306
307
                var bestWeapon = if (slotStack?.item?.javaClass == currentType)
308
                    targetSlot
309
                else -1
310
311
                mc.thePlayer.inventory.mainInventory.forEachIndexed { index, itemStack ->
312
                    if (itemStack?.item?.javaClass == currentType && !type(index).equals(type, ignoreCase = true)) {
313
                        if (bestWeapon == -1) {
314
                            bestWeapon = index
315
                        } else {
316
                            val currDamage = (itemStack.attributeModifiers["generic.attackDamage"].firstOrNull()?.amount
317
                                    ?: 0.0) + 1.25 * ItemUtils.getEnchantment(itemStack, Enchantment.sharpness)
318
319
                            val bestStack = mc.thePlayer.inventory.getStackInSlot(bestWeapon)
320
                                    ?: return@forEachIndexed
321
                            val bestDamage = (bestStack.attributeModifiers["generic.attackDamage"].firstOrNull()?.amount
322
                                    ?: 0.0) + 1.25 * ItemUtils.getEnchantment(bestStack, Enchantment.sharpness)
323
324
                            if (bestDamage < currDamage)
325
                                bestWeapon = index
326
                        }
327
                    }
328
                }
329
330
                return if (bestWeapon != -1 || bestWeapon == targetSlot) bestWeapon else null
331
            }
332
333
            "bow" -> {
334
                var bestBow = if (slotStack?.item is ItemBow) targetSlot else -1
335
                var bestPower = if (bestBow != -1)
336
                    ItemUtils.getEnchantment(slotStack, Enchantment.power)
337
                else
338
                    0
339
340
                mc.thePlayer.inventory.mainInventory.forEachIndexed { index, itemStack ->
341
                    if (itemStack?.item is ItemBow && !type(index).equals(type, ignoreCase = true)) {
342
                        if (bestBow == -1) {
343
                            bestBow = index
344
                        } else {
345
                            val power = ItemUtils.getEnchantment(itemStack, Enchantment.power)
346
347
                            if (ItemUtils.getEnchantment(itemStack, Enchantment.power) > bestPower) {
348
                                bestBow = index
349
                                bestPower = power
350
                            }
351
                        }
352
                    }
353
                }
354
355
                return if (bestBow != -1) bestBow else null
356
            }
357
358
            "food" -> {
359
                mc.thePlayer.inventory.mainInventory.forEachIndexed { index, stack ->
360
                    val item = stack?.item
361
362
                    if (item is ItemFood && item !is ItemAppleGold && !type(index).equals("Food", ignoreCase = true)) {
363
                        val replaceCurr = slotStack == null || slotStack.item !is ItemFood
364
365
                        return if (replaceCurr) index else null
366
                    }
367
                }
368
            }
369
370
            "block" -> {
371
                mc.thePlayer.inventory.mainInventory.forEachIndexed { index, stack ->
372
                    val item = stack?.item
373
374
                    if (item is ItemBlock && !InventoryUtils.BLOCK_BLACKLIST.contains(item.block) &&
375
                            !type(index).equals("Block", ignoreCase = true)) {
376
                        val replaceCurr = slotStack == null || slotStack.item !is ItemBlock
377
378
                        return if (replaceCurr) index else null
379
                    }
380
                }
381
            }
382
383
            "water" -> {
384
                mc.thePlayer.inventory.mainInventory.forEachIndexed { index, stack ->
385
                    val item = stack?.item
386
387
                    if (item is ItemBucket && item.isFull == Blocks.flowing_water && !type(index).equals("Water", ignoreCase = true)) {
388
                        val replaceCurr = slotStack == null || slotStack.item !is ItemBucket || (slotStack.item as ItemBucket).isFull != Blocks.flowing_water
389
390
                        return if (replaceCurr) index else null
391
                    }
392
                }
393
            }
394
395
            "gapple" -> {
396
                mc.thePlayer.inventory.mainInventory.forEachIndexed { index, stack ->
397
                    val item = stack?.item
398
399
                    if (item is ItemAppleGold && !type(index).equals("Gapple", ignoreCase = true)) {
400
                        val replaceCurr = slotStack == null || slotStack.item !is ItemAppleGold
401
402
                        return if (replaceCurr) index else null
403
                    }
404
                }
405
            }
406
407
            "pearl" -> {
408
                mc.thePlayer.inventory.mainInventory.forEachIndexed { index, stack ->
409
                    val item = stack?.item
410
411
                    if (item is ItemEnderPearl && !type(index).equals("Pearl", ignoreCase = true)) {
412
                        val replaceCurr = slotStack == null || slotStack.item !is ItemEnderPearl
413
414
                        return if (replaceCurr) index else null
415
                    }
416
                }
417
            }
418
419
            "healpotion" -> {
420
                mc.thePlayer.inventory.mainInventory.forEachIndexed { index, stack ->
421
                    val item = stack?.item
422
423
                    if (item is ItemPotion && !type(index).equals("HealPotion", ignoreCase = true)) {
424
                        val replaceCurr = slotStack == null || slotStack.item !is ItemPotion
425
                        for (potionEffect in item.getEffects(stack))
426
                            if (potionEffect.potionID == Potion.heal.id || potionEffect.potionID == Potion.regeneration.id)
427
                                return if (replaceCurr) index else null
428
                    }
429
                }
430
            }
431
432
            "speedpotion" -> {
433
                mc.thePlayer.inventory.mainInventory.forEachIndexed { index, stack ->
434
                    val item = stack?.item
435
436
                    if (item is ItemPotion && !type(index).equals("SpeedPotion", ignoreCase = true)) {
437
                        val replaceCurr = slotStack == null || slotStack.item !is ItemPotion
438
                        for (potionEffect in item.getEffects(stack))
439
                            if (potionEffect.potionID == Potion.moveSpeed.id)
440
                                return if (replaceCurr) index else null
441
                    }
442
                }
443
            }
444
445
        }
446
447
        return null
448
    }
449
450
    /**
451
     * Get items in inventory
452
     */
453
    private fun items(start: Int = 0, end: Int = 45): Map<Int, ItemStack> {
454
        val items = mutableMapOf<Int, ItemStack>()
455
456
        for (i in end - 1 downTo start) {
457
            val itemStack = mc.thePlayer.inventoryContainer.getSlot(i).stack ?: continue
458
            itemStack.item ?: continue
459
460
            if (i in 36..44 && type(i).equals("Ignore", ignoreCase = true))
461
                continue
462
463
            if (System.currentTimeMillis() - (itemStack as IItemStack).itemDelay >= itemDelayValue.get())
464
                items[i] = itemStack
465
        }
466
467
        return items
468
    }
469
470
    /**
471
     * Get type of [targetSlot]
472
     */
473
    private fun type(targetSlot: Int) = when (targetSlot) {
474
        0 -> sortSlot1Value.get()
475
        1 -> sortSlot2Value.get()
476
        2 -> sortSlot3Value.get()
477
        3 -> sortSlot4Value.get()
478
        4 -> sortSlot5Value.get()
479
        5 -> sortSlot6Value.get()
480
        6 -> sortSlot7Value.get()
481
        7 -> sortSlot8Value.get()
482
        8 -> sortSlot9Value.get()
483
        else -> ""
484
    }
485
}

What this file does

InventoryCleaner is a sibling player module whose isUseful(itemStack, slot) method ChestStealer borrows as its junk classifier. The method accepts swords and tools only when they beat the equipped item (findBetterItem against the given slot), accepts armor by type and tier, and rejects consumables and materials it considers worthless; slot -1 means the stack is not in the player's inventory, which is the case for every chest slot. The module fetches the singleton through LiquidBounce.moduleManager and calls isUseful(stack, -1) both in the steal scan and in isEmpty.

This coupling means ChestStealer's stealable set is defined by another module's value system: enabling Useful keeps the chest's garbage in place and drains only what InventoryCleaner would keep, while disabling Useful steals every non-null stack the other filters allow. The same isUseful routine drives the InventoryCleaner module's own moving, so the two modules share one classification policy.

anticheat Countering Checks

The anticheat code that detects or counters the techniques this module uses. Full source, with the detection mechanism explained below each box.

anticheat FastClick (window click rate)

FastClick.java243 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.inventory;
16
17
import java.util.ArrayList;
18
import java.util.List;
19
20
import org.bukkit.Material;
21
import org.bukkit.entity.Player;
22
import org.bukkit.event.inventory.InventoryClickEvent;
23
import org.bukkit.event.inventory.InventoryType;
24
import org.bukkit.inventory.InventoryView;
25
import org.bukkit.inventory.ItemStack;
26
27
import fr.neatmonster.nocheatplus.actions.ParameterName;
28
import fr.neatmonster.nocheatplus.checks.Check;
29
import fr.neatmonster.nocheatplus.checks.CheckType;
30
import fr.neatmonster.nocheatplus.checks.ViolationData;
31
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
32
import fr.neatmonster.nocheatplus.permissions.Permissions;
33
import fr.neatmonster.nocheatplus.players.IPlayerData;
34
import fr.neatmonster.nocheatplus.utilities.entity.InventoryUtil;
35
import fr.neatmonster.nocheatplus.utilities.StringUtil;
36
import fr.neatmonster.nocheatplus.utilities.TickTask;
37
38
39
/**
40
 * FastClick checks for players clicking in inventories too quickly (nerfs autosteal cheats and the like).
41
 */
42
public class FastClick extends Check {
43
44
45
    final List<String> tags = new ArrayList<String>();
46
47
48
    /**
49
     * Instantiates a new fast click check.
50
     */
51
    public FastClick() {
52
        super(CheckType.INVENTORY_FASTCLICK);
53
    }
54
55
56
   /**
57
    * Checks a player.
58
    * 
59
    * @param player
60
    * @param now Millisec
61
    * @param view
62
    * @param slot
63
    * @param cursor
64
    * @param clicked
65
    * @param isShiftClick
66
    * @param inventoryAction
67
    * @param data
68
    * @param cc 
69
    * @param pData
70
    * @return true, if successful
71
    */
72
    public boolean check(final Player player, final long now, 
73
                         final InventoryClickEvent event, final int slot, final ItemStack cursor, 
74
                         final ItemStack clicked, final boolean isShiftClick, 
75
                         final String inventoryAction, final InventoryData data, final InventoryConfig cc, 
76
                         final IPlayerData pData) {
77
78
        final float amount;
79
        final Material clickedMat = clicked == null ? Material.AIR : clicked.getType();
80
        final Material cursorMat;
81
        final int cursorAmount;
82
        boolean cancel = false;
83
        tags.clear();
84
85
        if (cursor != null) {
86
            cursorMat = cursor.getType();
87
            cursorAmount = Math.max(1, cursor.getAmount());
88
        }
89
        else {
90
            cursorMat = null;
91
            cursorAmount = 0;
92
        }
93
94
        if (inventoryAction != null) {
95
            amount = getAmountWithAction(event, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, inventoryAction, data, cc);
96
        }
97
        else if (cursor != null) {
98
            // Detect shift-click features indirectly.
99
            amount = detectTweaks1_5(event, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, data, cc);
100
        }
101
        else amount = 1f;
102
103
        if (isShiftClick && inventoryAction.equals("MOVE_TO_OTHER_INVENTORY") 
104
            && (cursorMat != null && cursorMat != Material.AIR) 
105
            && clickedMat != Material.AIR) {
106
            return false;
107
        }
108
        
109
        // Count clicks
110
        data.fastClickFreq.add(now, amount);
111
        
112
        // Shor-term VL
113
        float shortTerm = data.fastClickFreq.bucketScore(0);
114
        if (shortTerm > cc.fastClickShortTermLimit) {
115
            // Check for lag.
116
            shortTerm /= (float) TickTask.getLag(data.fastClickFreq.bucketDuration(), true);
117
        }
118
        shortTerm -= cc.fastClickShortTermLimit;
119
        
120
        // Normal VL
121
        float normal = data.fastClickFreq.score(1f);
122
        if (normal > cc.fastClickNormalLimit) {
123
            // Check for lag.
124
            normal /= (float) TickTask.getLag(data.fastClickFreq.bucketDuration() * data.fastClickFreq.numberOfBuckets(), true);
125
        }
126
        normal -= cc.fastClickNormalLimit;
127
        
128
        // Process Violations.
129
        final double violation = Math.max(shortTerm, normal);
130
        if (violation > 0.0) {
131
            tags.add("clickspeed");
132
            data.fastClickVL += violation;
133
            final ViolationData vd = new ViolationData(this, player, data.fastClickVL, violation, cc.fastClickActions);
134
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
135
            cancel = executeActions(vd).willCancel();
136
        }
137
        else data.fastClickVL *= 0.99;
138
139
        if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)) {
140
            player.sendMessage("FastClick: " + data.fastClickFreq.bucketScore(0) + " | " + data.fastClickFreq.score(1f) + " | cursor=" + cursor 
141
                                + " | clicked=" + clicked + " | action=" + inventoryAction);
142
        }
143
        
144
        // Adjust data
145
        data.fastClickLastClicked = clickedMat;
146
        data.fastClickLastSlot = slot;
147
        data.fastClickLastCursor = cursorMat;
148
        data.fastClickLastCursorAmount = cursorAmount;
149
150
        // Lastly, always feed the improbable.
151
        if (cc.fastClickImprobableWeight > 0.0f) {
152
            Improbable.feed(player, cc.fastClickImprobableWeight * amount, now);
153
        }
154
        return cancel;
155
    }
156
    
157
158
   /**
159
    * Enforce sane timings for interacting with the container and clicking in it.
160
    * 
161
    * @param player
162
    * @param data
163
    * @param cc
164
    */
165
    public boolean checkContainerInteraction(final Player player, final InventoryData data, final InventoryConfig cc) {
166
        boolean cancel = false;
167
        tags.clear();
168
        if (InventoryUtil.isContainerInteractionRecent(player, cc.chestOpenLimit)) {
169
            // Interaction was too quick, violation.
170
            tags.add("interact_time");
171
            long duration = Math.max(data.lastClickTime - data.containerInteractTime, 20);
172
            double violation = (cc.chestOpenLimit / duration) * 100D; // Normalize.
173
            data.fastClickVL += violation;
174
            final ViolationData vd = new ViolationData(this, player, data.fastClickVL, violation, cc.fastClickActions);
175
            if (vd.needsParameters()) vd.setParameter(ParameterName.TAGS, StringUtil.join(tags, "+"));
176
            cancel = executeActions(vd).willCancel();  
177
        }
178
       return cancel;
179
    }
180
    
181
182
   /**
183
    * Detect the inventory tweaks that were introduced in MC 1.5
184
    * 
185
    * @param view
186
    * @param slot
187
    * @param clicked
188
    * @param clickedMat
189
    * @param cursorAmount
190
    * @param isShiftClick
191
    * @param data
192
    * @param cc
193
    */
194
    private float detectTweaks1_5(final InventoryClickEvent event, final int slot, final ItemStack clicked, 
195
                                  final Material clickedMat, final Material cursorMat, 
196
                                  final int cursorAmount, final boolean isShiftClick, 
197
                                  final InventoryData data, final InventoryConfig cc) {
198
199
        if (cursorMat != data.fastClickLastCursor 
200
            && (!isShiftClick || clickedMat == Material.AIR || clickedMat != data.fastClickLastClicked) 
201
            || cursorMat == Material.AIR || cursorAmount != data.fastClickLastCursorAmount) {
202
            return 1f;
203
        }
204
        else if (clickedMat == Material.AIR || clickedMat == cursorMat 
205
                || isShiftClick && clickedMat == data.fastClickLastClicked ) {
206
            return Math.min(cc.fastClickNormalLimit , cc.fastClickShortTermLimit) 
207
                    / (float) (isShiftClick && clickedMat != Material.AIR ? (1.0 + Math.max(cursorAmount, InventoryUtil.getStackCount(event, clicked))) : cursorAmount)  * 0.75f;
208
        }
209
        return 1f;
210
    }
211
212
213
    private float getAmountWithAction(final InventoryClickEvent event, final int slot, final ItemStack clicked, 
214
                                      final Material clickedMat, final Material cursorMat, 
215
                                      final int cursorAmount, final boolean isShiftClick, 
216
                                      final String inventoryAction, 
217
                                      final InventoryData data, final InventoryConfig cc) {
218
219
        // Continuous drop feature with open inventories.
220
        if (inventoryAction.equals("DROP_ONE_SLOT")
221
            && slot == data.fastClickLastSlot 
222
            && clickedMat == data.fastClickLastClicked
223
            && event.getInventory().getType() == InventoryType.CRAFTING
224
            // && InventoryUtil.couldHaveInventoryOpen(player)
225
            // TODO: Distinguish if the inventory is really open.
226
            ) {
227
            return 0.6f;
228
        }
229
230
        // Collect to cursor.
231
        if (inventoryAction.equals("COLLECT_TO_CURSOR")) {
232
            final int stackCount = InventoryUtil.getStackCount(event, clicked);
233
            return stackCount <= 0 ? 1f : Math.min(cc.fastClickNormalLimit , cc.fastClickShortTermLimit) / stackCount * 0.75f;
234
        }
235
236
        // Shift click features.
237
        if ((inventoryAction.equals("MOVE_TO_OTHER_INVENTORY")) && cursorMat != Material.AIR) {
238
            // Let the legacy method do the side condition checks and counting for now.
239
            return detectTweaks1_5(event, slot, clicked, clickedMat, cursorMat, cursorAmount, isShiftClick, data, cc);
240
        }
241
        return 1f;
242
    }
243
}

How it counteracts this module

NoCheatPlus FastClick counts inventory clicks into an ActionFrequency with five 200ms buckets against a short-term limit of 4 and a one-second window limit of 15, with lag division via TickTask. Each shift-click with an empty cursor counts 1.0; the stack-size weighting in detectTweaks1_5 only applies when the cursor already holds an item. The container-interaction path adds a violation of (155 / duration) * 100 for every click landing within 155ms of the container open time, where duration is the click timestamp minus the open timestamp.

At the stock 150-200ms delays the module lands one click per 200ms bucket (score 1-2 against the short-term limit of 4) and about 5-7 clicks per second against the window limit of 15, so the rate paths stay quiet; the first click usually lands at 150-200ms after opening, so the interact_time violation only fires when the delay draw comes up shorter than 155ms. The check turns aggressive the moment the user drops the delays: at a 50ms average the buckets carry 4-5 clicks and the window score clears 15, pushing fastClickVL toward the cancel action at vl>150 within a chest or two. The randomized mode makes things worse by concentrating pairs of clicks in single buckets, since the do-while can move several slots per frame at the delay floor.

anticheat Open (inventory close on movement)

Open.java171 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.inventory;
16
17
import java.util.UUID;
18
19
import org.bukkit.GameMode;
20
import org.bukkit.Input;
21
import org.bukkit.entity.Player;
22
import org.bukkit.event.inventory.InventoryType;
23
import org.bukkit.event.inventory.InventoryType.SlotType;
24
25
import fr.neatmonster.nocheatplus.NCPAPIProvider;
26
import fr.neatmonster.nocheatplus.checks.Check;
27
import fr.neatmonster.nocheatplus.checks.CheckType;
28
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
29
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
30
import fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData;
31
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
32
import fr.neatmonster.nocheatplus.compat.registry.BukkitAPIAccessFactory;
33
import fr.neatmonster.nocheatplus.compat.versions.ClientVersion;
34
import fr.neatmonster.nocheatplus.components.registry.event.IHandle;
35
import fr.neatmonster.nocheatplus.components.registry.feature.IDisableListener;
36
import fr.neatmonster.nocheatplus.hooks.ExemptionSettings;
37
import fr.neatmonster.nocheatplus.players.DataManager;
38
import fr.neatmonster.nocheatplus.players.IPlayerData;
39
import fr.neatmonster.nocheatplus.utilities.collision.CollisionUtil;
40
import fr.neatmonster.nocheatplus.utilities.entity.InventoryUtil;
41
42
/**
43
 * Watch over open inventories - check with "combined" static access, put here because it has too much to do with inventories.
44
 * @author asofold
45
 */
46
public class Open extends Check implements IDisableListener {
47
48
    private static Open instance = null;
49
50
    private UUID nestedPlayer = null;
51
52
    private final IHandle<ExemptionSettings> exeSet = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstanceHandle(ExemptionSettings.class);
53
    
54
    // TODO: Add specific contexts (allow different settings for fight / blockbreak etc.).
55
56
    /**
57
     * Static access check, if there is a cancel-action flag the caller should have stored that locally already and use the result to know if to cancel or not.
58
     * 
59
     * @param player
60
     * @return If cancelling some event is opportune (open inventory and cancel flag set).
61
     */
62
    public static boolean checkClose(Player player) {
63
        return instance.check(player);
64
    }
65
66
    public Open() {
67
        super(CheckType.INVENTORY_OPEN);
68
        instance = this;
69
    }
70
71
    @Override
72
    public void onDisable() {
73
        instance = null;
74
        nestedPlayer = null;
75
    }
76
77
    /**
78
     * Enforce a closed inventory on this generic event/action (without checking for any specific side condition) <br>
79
     * This check contains the isEnabled checking (!). Inventory is closed if set in the config. <br>
80
     * Also resets inventory opening time and interaction time.
81
     * 
82
     * @param player
83
     * @return True, if the inventory has been successfully closed. This will also reset the inventory open time and interaction time.
84
     */
85
    public boolean check(final Player player) {
86
        final boolean isShulkerBox = BukkitAPIAccessFactory.getBukkitAccess().getTopInventory(player).getType().toString().equals("SHULKER_BOX");
87
        if (
88
            // TODO: POC: Item duplication with teleporting NPCS, having their inventory open.
89
            exeSet.getHandle().isRegardedAsNpc(player)
90
            || !isEnabled(player) 
91
            || !InventoryUtil.hasInventoryOpen(player)
92
            // Workaround, Open would disallow players from opening the container if standing on top
93
            // of the shulker. Reason for this is unknown
94
            || isShulkerBox) {
95
            return false;
96
        }
97
        final IPlayerData pData = DataManager.getPlayerData(player);
98
        final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
99
        if (cc.openClose) {
100
            // NOTE about UUID stuff: https://github.com/NoCheatPlus/NoCheatPlus/commit/a41ff38c997bcca780da32681e92216880e9e1b0
101
            final UUID id = player.getUniqueId();
102
            if ((this.nestedPlayer == null || !id.equals(this.nestedPlayer))) {
103
                // (The second condition represents an error, but we don't handle alternating things just yet.)
104
                this.nestedPlayer = id;
105
                player.closeInventory();
106
                pData.getGenericInstance(InventoryData.class).inventoryOpenTime = 0;
107
                pData.getGenericInstance(InventoryData.class).containerInteractTime = 0;
108
                this.nestedPlayer = null;
109
                return true;
110
            }
111
        }
112
        return false;
113
    }
114
115
    /**
116
     * To be called on {@link org.bukkit.event.player.PlayerMoveEvent}; pre-requisite is {@link InventoryUtil#hasInventoryOpen(Player)} having returned true. <br>
117
     * (Against InventoryMove cheats and similar)<br>
118
     * 
119
     * @param player
120
     * @param pData
121
     * @return True, if the open inventory needs to be closed during this movement.
122
     */
123
    public boolean checkOnMove(final Player player, final IPlayerData pData) {
124
        if (BridgeMisc.isWASDImpulseKnown(player)) {
125
            // Use WASD input directly if available (1.21.1+).
126
            Input input = player.getCurrentInput();
127
            boolean moving = input.isLeft() || input.isRight() || input.isForward() || input.isBackward() || input.isJump();
128
            if (moving) {
129
                final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
130
                if (cc.openImprobableWeight > 0.0) {
131
                    Improbable.feed(player, cc.openImprobableWeight, System.currentTimeMillis());
132
                }
133
                return true;
134
            }
135
            return false;
136
        }
137
        
138
        final MovingData mData = pData.getGenericInstance(MovingData.class);
139
        final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
140
        final InventoryData data = pData.getGenericInstance(InventoryData.class);
141
        final boolean creative = player.getGameMode() == GameMode.CREATIVE && ((data.clickedSlotType == SlotType.QUICKBAR) || cc.openDisableCreative);
142
        final boolean isMerchant = BukkitAPIAccessFactory.getBukkitAccess().getTopInventory(player).getType() == InventoryType.MERCHANT;
143
        final PlayerMoveData thisMove = mData.playerMoves.getCurrentMove();
144
        // Skipping conditions first.
145
        if (
146
            // Ignore duplicate packets
147
            mData.lastMoveNoMove
148
            // Can't check vehicles
149
            || player.isInsideVehicle()
150
            // In creative or middle click
151
            || creative 
152
            // Ignore merchant inventories.
153
            || isMerchant 
154
            // Velocity is ignored altogether. TODO: Should be horizontal too. Maybe this still work fine, most the time appear together
155
            || !mData.getOrUseVerticalVelocity(thisMove.yDistance).isEmpty()
156
            //|| mData.useHorizontalVelocity(thisMove.hDistance - mData.getHorizontalFreedom()) >= thisMove.hDistance - mData.getHorizontalFreedom()
157
            // Ignore entity pushing.
158
            || pData.getClientVersion().isAtLeast(ClientVersion.V_1_9) && CollisionUtil.isCollidingWithEntities(player, 0.5, 0.1, 0.5, true)) {
159
            return false;
160
        }
161
            
162
        // Actual detection: do assume player to be actively moving even if we don't actually know the direction (MAYBE, needs testing)
163
        if (thisMove.hasImpulse.decide()) {
164
            if (cc.openImprobableWeight > 0.0) {
165
                Improbable.feed(player, cc.openImprobableWeight, System.currentTimeMillis());
166
            }
167
            return true;
168
        }
169
        return false;
170
    }
171
}

How it counteracts this module

NCP's Open check closes the inventory when the player moves while a window is open. checkOnMove skips duplicate packets, vehicles, creative quickbar cases, merchants and vertical-velocity moves, then decides on impulse via direct WASD input where available or the movement model's hasImpulse decision; an impulse while open feeds Improbable and the caller force-closes the GUI, resetting inventoryOpenTime and containerInteractTime.

ChestStealer never touches the player's motion: the steal loop only clicks the container, so any WASD input or step while the chest is open is visible to the check, and a single impulse move aborts the drain by closing the window. The module's own filters do not guard against it, since NoCompass only reads the held item and the steal logic ignores movement state entirely. The check also resets the open-time baseline that FastClick's interact_time path compares against, so a player caught moving mid-steal loses the click-timing advantage on the next attempt.

anticheat InventoryActions (window state mismatch)

InventoryActions.java60 lines · Java
1
/*
2
 * This file is part of Hawk Anticheat.
3
 * Copyright (C) 2018 Hawk Development Team
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
package me.islandscout.hawk.check.interaction.inventory;
20
21
/*
22
 * InventoryActions check originally written by Havesta; modified, split apart, and implemented into Hawk by Islandscout
23
 *
24
 * InventoryActions checks if a player is
25
 * - interacting with entities/blocks while inventory is opened
26
 */
27
28
import me.islandscout.hawk.HawkPlayer;
29
import me.islandscout.hawk.check.CustomCheck;
30
import me.islandscout.hawk.event.*;
31
32
public class InventoryActions extends CustomCheck {
33
34
    public InventoryActions() {
35
        super("inventoryactions", true, 3, 5, 0.999, 5000, "%player% failed inventory-actions, VL: %vl%", null);
36
    }
37
38
    @Override
39
    protected void check(Event e) {
40
        HawkPlayer pp = e.getHawkPlayer();
41
42
        //player tried to interact with entities/world while an inventory window is open
43
        if(pp.hasInventoryOpen() != 0 && (e instanceof InteractEntityEvent || e instanceof BlockDigEvent ||
44
                e instanceof ArmSwingEvent || e instanceof InteractWorldEvent)) {
45
            punish(pp, true, e);
46
            e.resync();
47
            //TODO After failing several times, there's a chance that they could be legit, but the inventory state is glitched. Close the player's inventory.
48
        }
49
50
        //player tried to interact with inventory while it is closed
51
        else if(pp.hasInventoryOpen() == 0 && e instanceof ClickInventoryEvent) {
52
            //TODO also check that window ID makes sense with the window type (eg. ID 0 must mean hasInventoryOpen() == 0)
53
            punish(pp, true, e);
54
            e.resync();
55
        }
56
        else {
57
            reward(pp);
58
        }
59
    }
60
}

How it counteracts this module

Hawk's InventoryActions punishes ClickInventoryEvent packets when HawkPlayer.hasInventoryOpen() is zero and world interaction (InteractEntity, BlockDig, ArmSwing, InteractWorld) when it is non-zero, with a resync on every punish. Hawk tracks the window lifecycle from S2D open, C16 inventory-command and close packets, so its open state mirrors the server's window bookkeeping rather than the client's screen.

ChestStealer's silent mode is the exposure here: it calls closeScreen() as soon as the S30 window-id matches, which drops the client GUI while the server-side window is still open or just closing. Any C0E that races the close, or any click Hawk attributes to a window it already considers closed, is punished and resynced, forcing a container state refresh that interrupts the drain. The module's pure-GUI design keeps the world-interaction branch quiet, since it never swings, digs or interacts while the chest is up, but the click-after-close race is inherent to the silent close path.

anticheat InventoryMove (rotation and state while open)

InventoryMove.java52 lines · Java
1
/*
2
 * This file is part of Hawk Anticheat.
3
 * Copyright (C) 2018 Hawk Development Team
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
package me.islandscout.hawk.check.movement;
20
21
import me.islandscout.hawk.HawkPlayer;
22
import me.islandscout.hawk.check.MovementCheck;
23
import me.islandscout.hawk.event.MoveEvent;
24
25
/*
26
 * InventoryActions check originally written by Havesta; modified, split apart, and implemented into Hawk by Islandscout
27
 *
28
 * InventoryMove checks if a player is
29
 * - rotating, sprinting, or sneaking while inventory is opened
30
 */
31
32
public class InventoryMove extends MovementCheck {
33
34
    public InventoryMove() {
35
        super("inventorymove", true, 3, 5, 0.999, 5000, "%player% failed inventory-move, VL: %vl%", null);
36
    }
37
38
    @Override
39
    protected void check(MoveEvent e) {
40
        HawkPlayer pp = e.getHawkPlayer();
41
42
        //TODO: false flag: rotation is still possible at least 1 tick after opening inventory
43
        //TODO: false flag: you gotta do that TP grace period thing for this too
44
        //TODO: false flag: ESCing out of F6 twitch options while inv is open will cause a desync. Forcibly close inventory on flag to fix desyncs like this?
45
        if((e.isUpdateRot() || pp.isSprinting() || pp.isSneaking()) && pp.hasInventoryOpen() != 0 && !e.isTeleportAccept()) {
46
            punishAndTryRubberband(pp, e);
47
        }
48
        else {
49
            reward(pp);
50
        }
51
    }
52
}

How it counteracts this module

Hawk's InventoryMove check punishes rotation updates, sprinting and sneaking while an inventory window is open, excluding only teleport-accept moves, and rubberbands the player on violation. The check keys on the client's movement state as reported in the move stream, so it catches players who open a chest mid-motion or look around while the window flag is set.

ChestStealer does nothing to hide these states: it never cancels movement packets and never suppresses rotation, so a player who opens the chest while holding W or sneaking, or who turns to check surroundings mid-steal, trips the check immediately. The vanilla chest GUI normally grabs the mouse and blocks look, which is the main reason rotation-while-open is rare in legit play, but the module offers no protection for the sprint and sneak flags, which persist from the moment of opening. The randomized steal delays are irrelevant to this check, which scores movement state, not click cadence.

← Back to Analysis Hub