LiquidSense Dev InventoryCleaner module 2 files, 581 lines

LiquidSense Dev InventoryCleaner: Full Source Analysis

LiquidSense's InventoryCleaner (a LiquidBounce-lineage module) runs one inventory pass per UpdateEvent: it sorts the hotbar, then drops every stack its usefulness predicate rejects, one click per randomized delay.

net/ccbluex/liquidbounce/features/module/modules/player/InventoryCleaner.kt · GitHub source ↗

Published 2026-08-13 · Updated 2026-10-14

Analysis

Overview

LiquidSense's InventoryCleaner (a LiquidBounce-lineage module) runs one inventory pass per UpdateEvent: it sorts the hotbar, then drops every stack its usefulness predicate rejects, one click per randomized delay. All clicks go through PlayerControllerMP.windowClick, which serializes them as C0EPacketClickWindow; because the sort and drop clicks can move a different item into the held slot, the controller's syncCurrentPlayItem emits C09PacketHeldItemChange alongside the stream. When the real inventory screen is not open, SimulateInventory wraps each click in C16PacketClientStatus(OPEN_INVENTORY_ACHIEVEMENT) plus C0DPacketCloseWindow so the server accepts clicks against a window it believes is open.

Architecture

Everything funnels through onUpdate. The early-return guard bails while flying, while the shared InventoryUtils.CLICK_TIMER has not passed the current delay, when InvOpen requires a real GuiInventory screen that is not open, when NoMove is set and the player is moving, or when the player's openContainer windowId is not 0. sortHotbar runs first and swaps the best item into each of the nine configured sort slots (SortSlot-1..9, one swap per tick). Then a while loop drops garbage: items(9, hotbar?45:36) collects slots 9..44 (or 9..35) whose stack fails isUseful, RandomSlot shuffles the candidate list, and each iteration picks one candidate and drops it via windowClick(windowId, slot, 4, 4): button 4, mode 4, the drop-whole-stack click. Every iteration rolls a fresh random delay between MinDelay and MaxDelay (defaults 400-600ms).

The usefulness predicate

isUseful is the module's brain. Swords and tools are compared by attack damage plus 1.25 per Sharpness level against every other stack of the same class; bows by their Power enchantment; armor through AutoArmor's ARMOR_COMPARATOR per armor piece; compasses, food, arrows, beds, diamonds, iron ingots, pearls, potions, and buckets are kept outright, while blocks, enchanted books, and water/lava buckets are kept only up to per-type stack caps. Each dropped stack is chosen independently, so the drop pattern is a stream of identical-slot DROP_ONE_SLOT clicks whenever several junk stacks sit in the same slot region.

The simulated inventory

windowClick only means something to the server while a window is open. When the GUI is closed and SimulateInventory is on, the module first sends C16PacketClientStatus(EnumState.OPEN_INVENTORY_ACHIEVEMENT), the packet the vanilla client sends when the player opens their own inventory screen, so the server opens the player's 2x2 crafting container, then clicks, then closes with C0DPacketCloseWindow. The click stream the server sees is therefore indistinguishable from a human opening the vanilla inventory and dropping items, which is exactly why inventory anticheats count clicks and window-open state rather than the packets themselves. The C09 half of the stream comes from syncCurrentPlayItem: every controller action compares inventory.currentItem against the last synced slot and emits C09PacketHeldItemChange when a sort swap changes the held item.

source InventoryCleaner.kt

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

The module body. onUpdate gates the whole pass, sortHotbar performs the mode-2 swap clicks (windowClick(0, bestItem, index, 2)), and the clean loop performs the mode-4 drop clicks. Each windowClick call goes through mc.playerController, which is what turns the Kotlin-level slot arithmetic into C0EPacketClickWindow traffic; the C16 open / C0D close pair brackets every click when the GUI is closed and SimulateInventory is on. The delay bookkeeping is local (a single delay field) but the actual throttle is the static InventoryUtils.CLICK_TIMER that every LiquidSense inventory module shares, so InventoryCleaner and AutoArmor serialize their clicks through one timer. The usefulness predicate in isUseful is the module's only real logic beyond the clicking; its failure path logs and returns true, which means an exception mid-check silently keeps the item.

source InventoryUtils.java (shared click timer)

InventoryUtils.java96 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.utils;
7
8
import net.ccbluex.liquidbounce.event.ClickWindowEvent;
9
import net.ccbluex.liquidbounce.event.EventTarget;
10
import net.ccbluex.liquidbounce.event.Listenable;
11
import net.ccbluex.liquidbounce.event.PacketEvent;
12
import net.ccbluex.liquidbounce.utils.timer.MSTimer;
13
import net.minecraft.block.Block;
14
import net.minecraft.init.Blocks;
15
import net.minecraft.item.Item;
16
import net.minecraft.item.ItemBlock;
17
import net.minecraft.item.ItemStack;
18
import net.minecraft.network.Packet;
19
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
20
21
import java.util.Arrays;
22
import java.util.List;
23
24
public final class InventoryUtils extends MinecraftInstance implements Listenable {
25
26
    public static final MSTimer CLICK_TIMER = new MSTimer();
27
    public static final List<Block> BLOCK_BLACKLIST = Arrays.asList(Blocks.enchanting_table, Blocks.chest, Blocks.ender_chest, Blocks.trapped_chest,
28
            Blocks.anvil, Blocks.sand, Blocks.web, Blocks.torch, Blocks.crafting_table, Blocks.furnace, Blocks.waterlily, Blocks.dispenser,
29
            Blocks.stone_pressure_plate, Blocks.wooden_pressure_plate, Blocks.noteblock, Blocks.dropper);
30
31
    public static int findItem(final int startSlot, final int endSlot, final Item item) {
32
        for(int i = startSlot; i < endSlot; i++) {
33
            final ItemStack stack = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
34
35
            if(stack != null && stack.getItem() == item)
36
                return i;
37
        }
38
        return -1;
39
    }
40
41
    public static boolean hasSpaceHotbar() {
42
        for(int i = 36; i < 45; i++) {
43
            final ItemStack itemStack = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
44
45
            if(itemStack == null)
46
                return true;
47
        }
48
        return false;
49
    }
50
51
    public static int findAutoBlockBlock() {
52
        for(int i = 36; i < 45; i++) {
53
            final ItemStack itemStack = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
54
55
            if(itemStack != null && itemStack.getItem() instanceof ItemBlock) {
56
                final ItemBlock itemBlock = (ItemBlock) itemStack.getItem();
57
                final Block block = itemBlock.getBlock();
58
59
                if (block.isFullCube() && !BLOCK_BLACKLIST.contains(block))
60
                    return i;
61
            }
62
        }
63
64
        for(int i = 36; i < 45; i++) {
65
            final ItemStack itemStack = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
66
67
            if(itemStack != null && itemStack.getItem() instanceof ItemBlock) {
68
                final ItemBlock itemBlock = (ItemBlock) itemStack.getItem();
69
                final Block block = itemBlock.getBlock();
70
71
                if (!BLOCK_BLACKLIST.contains(block))
72
                    return i;
73
            }
74
        }
75
76
        return -1;
77
    }
78
79
    @EventTarget
80
    public void onClick(final ClickWindowEvent event) {
81
        CLICK_TIMER.reset();
82
    }
83
84
    @EventTarget
85
    public void onPacket(final PacketEvent event) {
86
        final Packet packet = event.getPacket();
87
88
        if (packet instanceof C08PacketPlayerBlockPlacement)
89
            CLICK_TIMER.reset();
90
    }
91
92
    @Override
93
    public boolean handleEvents() {
94
        return true;
95
    }
96
}

What this file does

A tiny utility class whose entire relevance is the public static MSTimer CLICK_TIMER. Every LiquidSense inventory operation (window clicks, slot swaps, armor swaps) resets this timer, and every module waits on hasTimePassed(delay) before the next click. InventoryCleaner's per-iteration random delay is only applied through this shared gate, so two inventory modules running at once still emit a single serialized click stream rather than two interleaved ones. From a detection standpoint this is the module's throttle: the minimum inter-click gap the client will ever produce is whatever MinDelay is set to.

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 and continuous-drop ledger)

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

NCP's inventory click-rate check, invoked from InventoryListener on every server-side InventoryClickEvent (the Bukkit view of a C0EPacketClickWindow). Each click is scored into data.fastClickFreq, an ActionFrequency with a configurable bucket width, with an amount derived from the click. getAmountWithAction contains a branch written for exactly this module's pattern: a DROP_ONE_SLOT click on the same slot whose clicked material matches the previous click while the inventory type is CRAFTING scores 0.6f instead of 1f: the 'continuous drop feature with open inventories' discount that still accumulates a short-term bucket score against cc.fastClickShortTermLimit and a window score against cc.fastClickNormalLimit; the max of the two becomes the violation fed into fastClickVL and the configured actions. checkContainerInteraction adds a second, independent gate: any click landing within cc.chestOpenLimit of the container's open time is flagged interact_time.

The module's defaults (400-600ms between drops plus the shared CLICK_TIMER) sit well under the limits, and because the simulated open is a genuine server-side window open (C16), NCP's crafting-inventory state matches the branch condition exactly. The failure mode is MinDelay: with MinDelay at 0 and ItemDelay at 0, the while loop drains the whole inventory in a burst of DROP_ONE_SLOT clicks inside one tick, and the short-term bucket trips. FastClick also feeds Improbable with the weighted click amount, so sustained cleaning drags the player's combined-check improbability even when the raw rate is under the limit.

anticheat Open (inventory-open enforcement 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

Open watches the server-side open-inventory state. checkOnMove is called from the moving listener whenever InventoryUtil.hasInventoryOpen(player) is true, and it closes the inventory if the player is actively moving while it is open, with a WASD-impulse path on 1.21.1+ and a move-data impulse path on 1.8-1.20. Closing also resets inventoryOpenTime and containerInteractTime, which directly shrinks the FastClick chest-open window for the next click.

This is the server-side answer to the SimulateInventory dance: the module opens the crafting window with C16 while the player keeps walking, and Open's contract is that a walking player cannot have an inventory open. With NoMove off, one move event closes the fake window and the click stream hits a closed-container state; the module's NoMove and InvOpen options exist precisely to keep the fake-open window from being torn down mid-clean. The static checkClose path is the companion that enforces a closed inventory on generic events.

anticheat MoreInventory (crafting-slot abuse)

MoreInventory.java60 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 org.bukkit.entity.Player;
18
import org.bukkit.event.inventory.InventoryType;
19
import org.bukkit.inventory.Inventory;
20
21
import fr.neatmonster.nocheatplus.checks.Check;
22
import fr.neatmonster.nocheatplus.checks.CheckType;
23
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
24
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
25
import fr.neatmonster.nocheatplus.players.IPlayerData;
26
27
/**
28
* A check meant to prevent players from exploiting the 4 default crafting slot to get more storage space.
29
*
30
*/
31
public class MoreInventory extends Check {
32
33
  /**
34
    * Instanties a new MoreInventory check
35
    *
36
    */
37
    public MoreInventory() {
38
        super(CheckType.INVENTORY_MOREINVENTORY);
39
    }
40
    
41
42
  /**
43
    * Checks a player
44
    * @param player 
45
    * @param PoYdiff the discrepancy between current and last pitch/yaw
46
    *
47
    * @author xaw3ep
48
    * @return true if succesful
49
    */
50
    public boolean check(final Player player, final CombinedData cData, final IPlayerData pData, final InventoryType type, 
51
    	                 final Inventory inv, final boolean PoYdiff) {
52
        
53
        // TODO: bring in the moving subcheck in invMove.
54
        if (type == InventoryType.CRAFTING 
55
            && (player.isSprinting() || PoYdiff || pData.isShiftKeyPressed() || BridgeMisc.isUsingItem(player))) {
56
            return true;
57
        }
58
        return false;
59
    }
60
}

How it counteracts this module

The smallest NCP inventory check: when the player's open inventory type is CRAFTING (the 2x2 player inventory) and the player is sprinting, changing pitch/yaw, holding shift, or using an item, the check fires and InventoryListener closes the inventory. It exists to stop the 4-slot-crafting-storage exploit, but its trigger set is exactly the state SimulateInventory creates: a server-side crafting window that stays open while the player behaves as if it were not there. A cleaner run that moves (NoMove off) while the fake window is open reproduces the 'acting while the crafting inventory is open' contradiction and gets the window closed mid-stream, after which further C0E clicks are clicks into a window the server already closed.

anticheat FastConsume (Arc v2 inventory-action rate)

FastConsume.java28 lines · Java
1
package me.vrekt.arc.check.inventory;
2
3
import me.vrekt.arc.Arc;
4
import me.vrekt.arc.check.Check;
5
import me.vrekt.arc.check.CheckType;
6
import me.vrekt.arc.data.inventory.InventoryData;
7
import org.bukkit.entity.Player;
8
9
public class FastConsume extends Check {
10
11
    private int consumeTime = 0;
12
13
    public FastConsume() {
14
        super(CheckType.FASTCONSUME);
15
16
        consumeTime = Arc.getCheckManager().getValueInt(CheckType.FASTCONSUME, "consume-time");
17
    }
18
19
    public boolean check(Player player, InventoryData data) {
20
21
        long now = System.currentTimeMillis();
22
        long last = data.getConsumeTime();
23
        long total = now - last;
24
25
        // check if the time it took to consume the item is less than allowed.
26
        return total < consumeTime && checkViolation(player, "consume time less than allowed.");
27
    }
28
}

How it counteracts this module

Arc v2's only inventory check. It measures the wall-clock gap between consecutive item-consumption events via InventoryData.getConsumeTime and flags any gap shorter than the configured consume-time ('consume time less than allowed.'). Honest note: the check watches eating and drinking consumption, not window clicks, so InventoryCleaner's drop stream never reaches it. It is the closest Arc v2 check to the action-rate class the module exercises, and its presence in the Arc v2 inventory family is the entire inventory surface Arc offers against this module. Arc v2 has no C0E handling of its own; its packet wrapper for window clicks exists but no check consumes it.

← Back to Analysis Hub