Sigma 4.11 InventoryManager module 2 files, 618 lines

Sigma 4.11 InventoryManager: Full Source Analysis

Sigma 4.11's InventoryManager is a full inventory organizer driven from the EventUpdate pre phase: it keeps the best weapon, pickaxe, shovel and axe in hotbar slots 36-39, delegates armor…

info/sigmaclient/module/impl/player/InventoryManager.java · GitHub source ↗

Published 2026-08-13 · Updated 2026-08-13

Analysis

Overview

Sigma 4.11's InventoryManager is a full inventory organizer driven from the EventUpdate pre phase: it keeps the best weapon, pickaxe, shovel and axe in hotbar slots 36-39, delegates armor to the AutoArmor module (shift-clicking upgrades and dropping worn pieces), and runs an inventory cleaner that drops junk under a whitelist/blacklist rule set with a BLOCKCAP (default 128) for blocks. Every action is a mc.playerController.windowClick - SHIFT_CLICK (mode 1) for armor, SWAP (mode 2) for tools, DROP (mode 4, button 1) for junk - so all of it travels as C0EPacketClickWindow bursts against the player's own window 0, gated by a shared DELAY timer (default 1, i.e. 50ms, up to 10) that caps the click rate at 20 clicks per second. The Basic mode operates with mc.currentScreen == null - clicking a window the client considers closed - while OpenInv mode requires the GuiInventory screen.

Click pipeline

The EventUpdate pre handler is a sequence of timer-gated passes: first the AutoArmor pass (getBestArmor, gated by AutoArmor's own DELAY/MODE settings and only when AutoArmor is enabled), then a consistency guard that bails while any armor slot holds a non-best piece or a matching piece exists in the inventory, then the four best-tool swaps into slots 36-39 (weapon 36, pickaxe 37, shovel 38, axe 39), and finally the INVCLEANER sweep over slots 9-44 calling shouldDrop on each stack and dropping one item at a time. Every pass shares the single timer: a click resets it, and when DELAY > 0 the pass breaks after one click per tick, so the sustained rate is 1000/(DELAY*50) clicks per second - 20/s at the default, 10/s at DELAY 2. The drop path uses windowClick(slot, 1, 4) - button 1, mode 4, the vanilla drop-one-slot action - which is what NCP weights at 0.6 when repeated on the same slot.

Item policy

shouldDrop encodes the cleanup rules: display-name guards exempt '(right click)' and '§k||' items; the four hotbar tool slots are exempt while they hold their best item; armor is exempt while it is the best piece for its slot; blocks drop when the total block count exceeds BLOCKCAP or the block is on Scaffold's blacklist; bad potions (poison, harm, slowness, weakness - or any potion with no effects) drop; food drops when FOOD is on (golden apples exempt); hoes, tools, swords and armor always drop unless the SWORD setting keeps swords; bows and arrows drop when ARCHERY is on; and a long unlocalizedName blacklist (tnt, sticks, eggs, string, cake, mushroom, flint, compass, dyes, feathers, buckets, chests without 'collect', snow, fish, enchants, exp, shears, anvils, torches, seeds, leather, reeds, skulls, records, snowballs, glass bottles, pistons) covers the rest. Weapon and tool 'best' scoring is getDamage (tool damage + sword attack damage + sharpness*1.25 + fire aspect*0.01) and getToolEffect (str-vs-block with gold penalties and efficiency/unbreaking bonuses).

Window-state assumption

The module assumes it may click window 0 at any time: Basic mode runs when mc.currentScreen == null, GuiInventory or GuiChat is open, and OpenInv mode narrows that to GuiInventory only. With no screen open, the vanilla client still accepts window-0 clicks because the player inventory container is always conceptually open in 1.8 - the C0E packets carry windowId 0 and the server processes them against the crafting/player inventory. That is also the exact condition anticheats key on: Hawk's InventoryActions flags any ClickInventoryEvent while its per-player window state says nothing is open, which makes the default Basic mode visible to it on every click.

source InventoryManager.java (module)

InventoryManager.java498 lines · JavaOriginal ↗
1
package info.sigmaclient.module.impl.player;
2
3
import java.util.ArrayList;
4
5
import net.minecraft.client.gui.GuiChat;
6
import net.minecraft.client.gui.inventory.GuiInventory;
7
import net.minecraft.enchantment.Enchantment;
8
import net.minecraft.enchantment.EnchantmentHelper;
9
import net.minecraft.init.Blocks;
10
import net.minecraft.init.Items;
11
import net.minecraft.item.Item;
12
import net.minecraft.item.ItemAppleGold;
13
import net.minecraft.item.ItemArmor;
14
import net.minecraft.item.ItemAxe;
15
import net.minecraft.item.ItemBlock;
16
import net.minecraft.item.ItemBow;
17
import net.minecraft.item.ItemFood;
18
import net.minecraft.item.ItemGlassBottle;
19
import net.minecraft.item.ItemHoe;
20
import net.minecraft.item.ItemPickaxe;
21
import net.minecraft.item.ItemPotion;
22
import net.minecraft.item.ItemSpade;
23
import net.minecraft.item.ItemStack;
24
import net.minecraft.item.ItemSword;
25
import net.minecraft.item.ItemTool;
26
import net.minecraft.network.Packet;
27
import net.minecraft.network.play.client.C03PacketPlayer;
28
import net.minecraft.network.play.client.C09PacketHeldItemChange;
29
import net.minecraft.network.play.client.C0EPacketClickWindow;
30
import net.minecraft.network.play.server.S04PacketEntityEquipment;
31
import net.minecraft.network.play.server.S09PacketHeldItemChange;
32
import net.minecraft.network.play.server.S1CPacketEntityMetadata;
33
import net.minecraft.potion.Potion;
34
import net.minecraft.potion.PotionEffect;
35
import info.sigmaclient.Client;
36
import info.sigmaclient.event.Event;
37
import info.sigmaclient.event.RegisterEvent;
38
import info.sigmaclient.event.impl.EventPacket;
39
import info.sigmaclient.event.impl.EventUpdate;
40
import info.sigmaclient.module.Module;
41
import info.sigmaclient.module.data.ModuleData;
42
import info.sigmaclient.module.data.Options;
43
import info.sigmaclient.module.data.Setting;
44
import info.sigmaclient.module.impl.player.Scaffold;
45
import info.sigmaclient.util.misc.ChatUtil;
46
import info.sigmaclient.util.misc.Timer;
47
48
/*
49
 * Made by LeakedPvP
50
 */
51
public class InventoryManager extends Module {
52
	public static final String BLOCKCAP = "BLOCKCAP";
53
	public static final String DELAY = "DELAY";
54
	public static final String ARCHERY = "ARCHERY";
55
	public static final String FOOD = "FOOD";
56
	public static final String INVCLEANER = "INVCLEANER";
57
	public static final String MODE = "MODE";
58
	public static final String SWORD = "SWORD";
59
    
60
    public InventoryManager(ModuleData data) {   	   
61
        super(data);
62
        settings.put(BLOCKCAP, new Setting<>(BLOCKCAP, 128, "Max blocks allowed in your inventory.", 8, -1, 256));
63
        settings.put(DELAY, new Setting<>(DELAY, 1, "Inventory clicks delay.", 1, 0, 10));
64
        settings.put(ARCHERY, new Setting<>(ARCHERY, false, "Clean bows and arrows."));
65
        settings.put(FOOD, new Setting<>(FOOD, false, "Clean food. Keeps Golden Apples."));
66
        settings.put(SWORD, new Setting<>(SWORD, false, "Keep only swords as weapon."));
67
        settings.put(INVCLEANER, new Setting<>(INVCLEANER, true, "Cleans your inventory for you."));
68
		settings.put(MODE, new Setting<>(MODE, new Options("Mode", "Basic",new String[] {"Basic", "OpenInv"}), "InvManager method."));
69
    }
70
    public static int weaponSlot = 36, pickaxeSlot = 37, axeSlot = 38, shovelSlot = 39;
71
    Timer timer = new Timer();
72
    ArrayList<Integer>whitelistedItems = new ArrayList<>();
73
    @Override
74
    public void onEnable() {
75
        super.onEnable();
76
    }
77
    @Override
78
    @RegisterEvent(events = {EventUpdate.class})
79
    public void onEvent(Event event) {
80
        setSuffix("dev");
81
        long delay = ((Number) settings.get(DELAY).getValue()).longValue()*50;
82
    	if(event instanceof EventUpdate){
83
            EventUpdate em =(EventUpdate)event;
84
            String mode = ((Options) settings.get(MODE).getValue()).getSelected();
85
            this.setSuffix(mode);
86
            Module armor = Client.getModuleManager().get(AutoArmor.class);
87
            long Adelay = ((Number) armor.getSetting(AutoArmor.DELAY).getValue()).longValue()*50;
88
            String Amode = ((Options) armor.getSetting(AutoArmor.MODE).getValue()).getSelected();
89
            this.setSuffix(mode);
90
            if(!em.isPre())
91
            	return;
92
            if(timer.check(Adelay) && armor.isEnabled()){
93
            	 if(!Amode.equalsIgnoreCase("OpenInv") || mc.currentScreen instanceof GuiInventory){
94
                     if(mc.currentScreen == null || mc.currentScreen instanceof GuiInventory || mc.currentScreen instanceof GuiChat){
95
                    	 getBestArmor();
96
                     }
97
                 }
98
            }
99
            if( armor.isEnabled())
100
            for(int type = 1; type < 5; type++){
101
        		if(mc.thePlayer.inventoryContainer.getSlot(4 + type).getHasStack()){
102
        			ItemStack is = mc.thePlayer.inventoryContainer.getSlot(4 + type).getStack();
103
        			if(!AutoArmor.isBestArmor(is, type)){
104
        				return;
105
        			}
106
        		}else if(invContainsType(type-1)){
107
        			return;
108
        		}
109
            }
110
            if(mode.equalsIgnoreCase("OpenInv") && !(mc.currentScreen instanceof GuiInventory)){
111
            	return;
112
            }
113
            
114
            if(mc.currentScreen == null || mc.currentScreen instanceof GuiInventory || mc.currentScreen instanceof GuiChat){
115
            	if(timer.check(delay) && weaponSlot >= 36){         
116
117
            		if (!mc.thePlayer.inventoryContainer.getSlot(weaponSlot).getHasStack()){
118
            			getBestWeapon(weaponSlot);
119
                	
120
            		}else{
121
            			if(!isBestWeapon(mc.thePlayer.inventoryContainer.getSlot(weaponSlot).getStack())){           			
122
                			getBestWeapon(weaponSlot);
123
                		}
124
            		}
125
            	}
126
            	if(timer.check(delay) && pickaxeSlot >= 36){
127
            		getBestPickaxe(pickaxeSlot);
128
            	}
129
            	if(timer.check(delay) && shovelSlot >= 36){
130
            		getBestShovel(shovelSlot);
131
            	}
132
            	if(timer.check(delay) && axeSlot >= 36){
133
            		getBestAxe(axeSlot);
134
            	}
135
            	if(timer.check(delay) && (Boolean) settings.get(INVCLEANER).getValue())
136
                for (int i = 9; i < 45; i++) {
137
                    if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
138
                        ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
139
                        if(shouldDrop(is, i)){
140
                        	drop(i);
141
                        	timer.reset();
142
                        	if(delay > 0)
143
                        	break;
144
                        }
145
                    }
146
                }              
147
            }
148
    	}
149
    }
150
    public void shiftClick(int slot){
151
    	mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, slot, 0, 1, mc.thePlayer);
152
    }
153
    public void swap(int slot1, int hotbarSlot){
154
    	mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, slot1, hotbarSlot, 2, mc.thePlayer);
155
    }
156
    public void drop(int slot){
157
    	mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, slot, 1, 4, mc.thePlayer);
158
    }
159
    public boolean isBestWeapon(ItemStack stack){
160
    	float damage = getDamage(stack);
161
    	for (int i = 9; i < 45; i++) {
162
            if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
163
                ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
164
                if(getDamage(is) > damage && (is.getItem() instanceof ItemSword || !(Boolean) settings.get(SWORD).getValue()))
165
                	return false;
166
            }
167
        }
168
    	if((stack.getItem() instanceof ItemSword || !(Boolean) settings.get(SWORD).getValue())){
169
    		return true;
170
    	}else{
171
    		return false;
172
    	}
173
    	
174
    }
175
176
    public void getBestWeapon(int slot){
177
    	for (int i = 9; i < 45; i++) {
178
            if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
179
                ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
180
                if(isBestWeapon(is) && getDamage(is) > 0 && (is.getItem() instanceof ItemSword || !(Boolean) settings.get(SWORD).getValue())){
181
                	swap(i, slot - 36);
182
            		timer.reset();
183
                	break;
184
                }
185
            }
186
        }
187
    }
188
 
189
    private float getDamage(ItemStack stack) {
190
    	float damage = 0;
191
    	Item item = stack.getItem();
192
    	if(item instanceof ItemTool){
193
    		ItemTool tool = (ItemTool)item;
194
    		damage += tool.getDamage();
195
    	}
196
    	if(item instanceof ItemSword){
197
    		ItemSword sword = (ItemSword)item;
198
    		damage += sword.getAttackDamage();
199
    	}
200
    	damage += EnchantmentHelper.getEnchantmentLevel(Enchantment.sharpness.effectId, stack) * 1.25f + 
201
    			EnchantmentHelper.getEnchantmentLevel(Enchantment.fireAspect.effectId, stack) * 0.01f;
202
        return damage;
203
    }
204
    public boolean shouldDrop(ItemStack stack, int slot){
205
    	if(stack.getDisplayName().toLowerCase().contains("(right click)")){
206
    		return false;
207
    	}
208
    	if(stack.getDisplayName().toLowerCase().contains("§k||")){
209
    		return false;
210
    	}
211
    	if((slot == weaponSlot && isBestWeapon(mc.thePlayer.inventoryContainer.getSlot(weaponSlot).getStack())) ||
212
    			(slot == pickaxeSlot && isBestPickaxe(mc.thePlayer.inventoryContainer.getSlot(pickaxeSlot).getStack()) && pickaxeSlot >= 0) ||
213
    			(slot == axeSlot && isBestAxe(mc.thePlayer.inventoryContainer.getSlot(axeSlot).getStack()) && axeSlot >= 0) ||
214
    			(slot == shovelSlot && isBestShovel(mc.thePlayer.inventoryContainer.getSlot(shovelSlot).getStack()) && shovelSlot >= 0) ){
215
    		return false;
216
    	}
217
    	if(stack.getItem() instanceof ItemArmor){
218
    		for(int type = 1; type < 5; type++){
219
    			if(mc.thePlayer.inventoryContainer.getSlot(4 + type).getHasStack()){
220
        			ItemStack is = mc.thePlayer.inventoryContainer.getSlot(4 + type).getStack();
221
        			if(AutoArmor.isBestArmor(is, type)){
222
        				continue;
223
        			}
224
        		}
225
    			if(AutoArmor.isBestArmor(stack, type)){
226
    				return false;
227
    			}
228
    		}
229
    	}
230
    	if (stack.getItem() instanceof ItemBlock &&
231
    			(getBlockCount() > ((Number) settings.get(BLOCKCAP).getValue()).intValue() || 
232
    					Scaffold.getBlacklistedBlocks().contains(((ItemBlock)stack.getItem()).getBlock()))){
233
    		return true;
234
    	}
235
    	if(stack.getItem() instanceof ItemPotion){
236
    		if(isBadPotion(stack)){
237
    			return true;
238
    		}
239
    	}
240
    	if(stack.getItem() instanceof ItemFood && (Boolean) settings.get(FOOD).getValue() && !(stack.getItem() instanceof ItemAppleGold)){
241
    		return true;
242
    	}
243
    	if(stack.getItem() instanceof ItemHoe || stack.getItem() instanceof ItemTool || stack.getItem() instanceof ItemSword || stack.getItem() instanceof ItemArmor){
244
    		return true;
245
    	}
246
    	if((stack.getItem() instanceof ItemBow || stack.getItem().getUnlocalizedName().contains("arrow")) && (Boolean) settings.get(ARCHERY).getValue()){
247
    		return true;
248
    	}
249
    	
250
    	if(((stack.getItem().getUnlocalizedName().contains("tnt")) ||
251
                        (stack.getItem().getUnlocalizedName().contains("stick")) ||
252
                        (stack.getItem().getUnlocalizedName().contains("egg")) ||
253
                        (stack.getItem().getUnlocalizedName().contains("string")) ||
254
                        (stack.getItem().getUnlocalizedName().contains("cake")) ||
255
                        (stack.getItem().getUnlocalizedName().contains("mushroom")) ||
256
                        (stack.getItem().getUnlocalizedName().contains("flint")) ||
257
                        (stack.getItem().getUnlocalizedName().contains("compass")) ||
258
                        (stack.getItem().getUnlocalizedName().contains("dyePowder")) ||
259
                        (stack.getItem().getUnlocalizedName().contains("feather")) ||
260
                        (stack.getItem().getUnlocalizedName().contains("bucket")) ||
261
                        (stack.getItem().getUnlocalizedName().contains("chest") && !stack.getDisplayName().toLowerCase().contains("collect")) ||
262
                        (stack.getItem().getUnlocalizedName().contains("snow")) ||
263
                        (stack.getItem().getUnlocalizedName().contains("fish")) ||
264
                        (stack.getItem().getUnlocalizedName().contains("enchant")) ||
265
                        (stack.getItem().getUnlocalizedName().contains("exp")) ||
266
                        (stack.getItem().getUnlocalizedName().contains("shears")) ||
267
                        (stack.getItem().getUnlocalizedName().contains("anvil")) ||
268
                        (stack.getItem().getUnlocalizedName().contains("torch")) ||
269
                        (stack.getItem().getUnlocalizedName().contains("seeds")) ||
270
                        (stack.getItem().getUnlocalizedName().contains("leather")) ||
271
                        (stack.getItem().getUnlocalizedName().contains("reeds")) ||
272
                        (stack.getItem().getUnlocalizedName().contains("skull")) ||
273
                        (stack.getItem().getUnlocalizedName().contains("record")) ||
274
                        (stack.getItem().getUnlocalizedName().contains("snowball")) ||
275
                        (stack.getItem() instanceof ItemGlassBottle) ||
276
                        (stack.getItem().getUnlocalizedName().contains("piston")))){
277
    		return true;
278
    	}            
279
    	
280
    	return false;
281
    }
282
    public ArrayList<Integer>getWhitelistedItem(){
283
    	return whitelistedItems;
284
    }
285
    private int getBlockCount() {
286
        int blockCount = 0;
287
        for (int i = 0; i < 45; i++) {
288
            if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
289
                ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
290
                Item item = is.getItem();
291
                if (is.getItem() instanceof ItemBlock && !Scaffold.getBlacklistedBlocks().contains(((ItemBlock) item).getBlock())) {
292
                    blockCount += is.stackSize;
293
                }
294
            }
295
        }
296
        return blockCount;
297
    }
298
    
299
    private void getBestPickaxe(int slot){
300
    	for (int i = 9; i < 45; i++) {
301
			if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
302
				ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
303
				
304
				if(isBestPickaxe(is) && pickaxeSlot != i){
305
					if(!isBestWeapon(is))
306
					if(!mc.thePlayer.inventoryContainer.getSlot(pickaxeSlot).getHasStack()){	
307
						swap(i, pickaxeSlot - 36);
308
						timer.reset();
309
    					if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
310
    						return;
311
					}else if(!isBestPickaxe(mc.thePlayer.inventoryContainer.getSlot(pickaxeSlot).getStack())){
312
						swap(i, pickaxeSlot - 36);
313
						timer.reset();
314
    					if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
315
    						return;
316
					}
317
				
318
				}
319
			}
320
    	}
321
    }
322
    private void getBestShovel(int slot){
323
    	for (int i = 9; i < 45; i++) {
324
			if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
325
				ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
326
				
327
				if(isBestShovel(is) && shovelSlot != i){
328
					if(!isBestWeapon(is))
329
					if(!mc.thePlayer.inventoryContainer.getSlot(shovelSlot).getHasStack()){
330
						swap(i, shovelSlot - 36);
331
						timer.reset();
332
    					if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
333
    						return;
334
					}else if(!isBestShovel(mc.thePlayer.inventoryContainer.getSlot(shovelSlot).getStack())){	
335
						swap(i, shovelSlot - 36);
336
						timer.reset();
337
    					if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
338
    						return;
339
					}
340
				
341
				}
342
			}
343
    	}
344
    }
345
    private void getBestAxe(int slot){
346
347
    	for (int i = 9; i < 45; i++) {
348
			if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
349
				ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
350
				
351
				if(isBestAxe(is) && axeSlot != i){
352
					if(!isBestWeapon(is))
353
					if(!mc.thePlayer.inventoryContainer.getSlot(axeSlot).getHasStack()){
354
						swap(i, axeSlot - 36);
355
						timer.reset();
356
    					if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
357
    						return;
358
					}else if(!isBestAxe(mc.thePlayer.inventoryContainer.getSlot(axeSlot).getStack())){
359
						swap(i, axeSlot - 36);
360
						timer.reset();
361
    					if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
362
    						return;
363
					}
364
				
365
				}
366
			}
367
    	}
368
    }
369
    private boolean isBestPickaxe(ItemStack stack){
370
     	Item item = stack.getItem();
371
    	if(!(item instanceof ItemPickaxe))
372
    		return false;
373
    	float value = getToolEffect(stack);
374
    	for (int i = 9; i < 45; i++) {
375
            if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
376
                ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
377
                if(getToolEffect(is) > value && is.getItem() instanceof ItemPickaxe){                	
378
                	return false;
379
                }
380
                	
381
            }
382
        }
383
    	return true;
384
    }
385
    private boolean isBestShovel(ItemStack stack){
386
    	Item item = stack.getItem();
387
    	if(!(item instanceof ItemSpade))
388
    		return false;
389
    	float value = getToolEffect(stack);
390
    	for (int i = 9; i < 45; i++) {
391
            if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
392
                ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
393
                if(getToolEffect(is) > value && is.getItem() instanceof ItemSpade){                	
394
                	return false;
395
                }
396
                	
397
            }
398
        }
399
    	return true;
400
    }
401
    private boolean isBestAxe(ItemStack stack){
402
    	Item item = stack.getItem();
403
    	if(!(item instanceof ItemAxe))
404
    		return false;
405
    	float value = getToolEffect(stack);
406
    	for (int i = 9; i < 45; i++) {
407
            if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
408
                ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
409
                if(getToolEffect(is) > value && is.getItem() instanceof ItemAxe && !isBestWeapon(stack)){                
410
                	return false;
411
                }
412
                	
413
            }
414
        }
415
    	return true;
416
    }
417
    private float getToolEffect(ItemStack stack){
418
    	Item item = stack.getItem();
419
    	if(!(item instanceof ItemTool))
420
    		return 0;
421
    	String name = item.getUnlocalizedName();
422
    	ItemTool tool = (ItemTool)item;
423
    	float value = 1;
424
    	if(item instanceof ItemPickaxe){
425
    		value = tool.getStrVsBlock(stack, Blocks.stone);
426
    		if(name.toLowerCase().contains("gold")){
427
    			value -= 5;
428
    		}
429
    	}else if(item instanceof ItemSpade){
430
    		value = tool.getStrVsBlock(stack, Blocks.dirt);
431
    		if(name.toLowerCase().contains("gold")){
432
    			value -= 5;
433
    		}
434
    	}else if(item instanceof ItemAxe){
435
    		value = tool.getStrVsBlock(stack, Blocks.log);
436
    		if(name.toLowerCase().contains("gold")){
437
    			value -= 5;
438
    		}
439
    	}else
440
    		return 1f;
441
		value += EnchantmentHelper.getEnchantmentLevel(Enchantment.efficiency.effectId, stack) * 0.0075D;
442
		value += EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, stack)/100d;
443
    	return value;
444
    }
445
    private boolean isBadPotion(ItemStack stack) {
446
        if (stack != null && stack.getItem() instanceof ItemPotion) {
447
            final ItemPotion potion = (ItemPotion) stack.getItem();
448
            if(potion.getEffects(stack) == null)
449
            	return true;
450
            for (final Object o : potion.getEffects(stack)) {
451
                final PotionEffect effect = (PotionEffect) o;
452
                if (effect.getPotionID() == Potion.poison.getId() || effect.getPotionID() == Potion.harm.getId() || effect.getPotionID() == Potion.moveSlowdown.getId() || effect.getPotionID() == Potion.weakness.getId()) {
453
                	return true;
454
                }
455
            }
456
        }
457
        return false;
458
    }
459
    boolean invContainsType(int type){
460
    	
461
    	for(int i = 9; i < 45; i++){
462
    		if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
463
				ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
464
				Item item = is.getItem();
465
				if(item instanceof ItemArmor){
466
					ItemArmor armor = (ItemArmor)item;
467
					if(type == armor.armorType){
468
						return true;
469
					}	
470
				}
471
    		}
472
    	}
473
    	return false;
474
    }
475
    public void getBestArmor(){
476
    	for(int type = 1; type < 5; type++){
477
    		if(mc.thePlayer.inventoryContainer.getSlot(4 + type).getHasStack()){
478
    			ItemStack is = mc.thePlayer.inventoryContainer.getSlot(4 + type).getStack();
479
    			if(AutoArmor.isBestArmor(is, type)){
480
    				continue;
481
    			}else{
482
    				drop(4 + type);
483
    			}
484
    		}
485
    		for (int i = 9; i < 45; i++) {
486
    			if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
487
    				ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
488
    				if(AutoArmor.isBestArmor(is, type) && AutoArmor.getProtection(is) > 0){
489
    					shiftClick(i);
490
    					timer.reset();
491
    					if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
492
    						return;
493
    				}
494
    			}
495
            }
496
        }
497
    }
498
}

What this file does

The module is a 120-line policy engine over windowClick. The three click helpers are thin wrappers: shiftClick(slot) sends windowClick(windowId, slot, 0, 1) - SHIFT_CLICK, used only by getBestArmor; swap(slot1, hotbarSlot) sends windowClick(windowId, slot1, hotbarSlot, 2) - the SWAP action that moves an item into a hotbar slot; drop(slot) sends windowClick(windowId, slot, 1, 4) - DROP_ONE_SLOT. The windowId is always mc.thePlayer.inventoryContainer.windowId (0 for the player inventory), so no window-open packet is ever sent - the module never touches C16 or S2D and never relies on a server window. The weapon/tool passes run getBestWeapon/getBestPickaxe/getBestShovel/getBestAxe with per-type 'best' comparisons over slots 9-44, and the AutoArmor pass reads the other module's settings directly (armor.getSetting(AutoArmor.DELAY)). The C09PacketHeldItemChange import on line 28 is vestigial - no C09 is ever constructed; slot changes are expressed entirely through C0E swaps, which is the detail that keeps the module off C09-rate checks.

source AutoArmor.java (armor pass dependency)

AutoArmor.java120 lines · JavaOriginal ↗
1
package info.sigmaclient.module.impl.player;
2
3
import net.minecraft.client.gui.GuiChat;
4
import net.minecraft.client.gui.inventory.GuiInventory;
5
import net.minecraft.enchantment.Enchantment;
6
import net.minecraft.enchantment.EnchantmentHelper;
7
import net.minecraft.item.ItemArmor;
8
import net.minecraft.item.ItemStack;
9
import net.minecraft.network.play.client.C16PacketClientStatus;
10
import net.minecraft.network.play.client.C16PacketClientStatus.EnumState;
11
import info.sigmaclient.Client;
12
import info.sigmaclient.event.Event;
13
import info.sigmaclient.event.impl.EventTick;
14
import info.sigmaclient.module.Module;
15
import info.sigmaclient.module.data.ModuleData;
16
import info.sigmaclient.module.data.Options;
17
import info.sigmaclient.module.data.Setting;
18
import info.sigmaclient.util.misc.Timer;
19
import info.sigmaclient.event.RegisterEvent;
20
public class AutoArmor extends Module {
21
22
	public static final String DELAY = "DELAY";
23
	public static final String MODE = "MODE";
24
	private Timer timer = new Timer();
25
    public AutoArmor(ModuleData data) {
26
        super(data);
27
        settings.put(DELAY, new Setting<>(DELAY, 1, "Inventory clicks delay.", 1, 0, 10));
28
		settings.put(MODE, new Setting<>(MODE, new Options("Mode", "Basic",new String[] {"Basic", "OpenInv", "FakeInv"}), "InvManager method."));
29
    }
30
31
    @Override
32
    @RegisterEvent(events = {EventTick.class})
33
    public void onEvent(Event event) {
34
        String mode = ((Options) settings.get(MODE).getValue()).getSelected();
35
        this.setSuffix(mode);
36
    	if(Client.getModuleManager().isEnabled(InventoryManager.class))
37
    		return;
38
    	long delay = ((Number) settings.get(DELAY).getValue()).longValue()*50;
39
        if(mode.equalsIgnoreCase("OpenInv") && !(mc.currentScreen instanceof GuiInventory)){
40
        	return;
41
        }
42
        if(mc.currentScreen == null || mc.currentScreen instanceof GuiInventory || mc.currentScreen instanceof GuiChat){
43
        	if(timer.check(delay)){
44
        		getBestArmor();
45
        	}
46
        }
47
    }
48
    
49
    public void getBestArmor(){
50
    	for(int type = 1; type < 5; type++){
51
    		if(mc.thePlayer.inventoryContainer.getSlot(4 + type).getHasStack()){
52
    			ItemStack is = mc.thePlayer.inventoryContainer.getSlot(4 + type).getStack();
53
    			if(isBestArmor(is, type)){
54
    				continue;
55
    			}else{
56
    				if( ((Options) settings.get(MODE).getValue()).getSelected().equalsIgnoreCase("FakeInv")){
57
        				C16PacketClientStatus p = new C16PacketClientStatus(EnumState.OPEN_INVENTORY_ACHIEVEMENT);
58
        				mc.thePlayer.sendQueue.addToSendQueue(p);
59
    				}
60
    				drop(4 + type);
61
    			}
62
    		}
63
    		for (int i = 9; i < 45; i++) {
64
    			if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
65
    				ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
66
    				if(isBestArmor(is, type) && getProtection(is) > 0){
67
    					shiftClick(i);
68
    					timer.reset();
69
    					if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
70
    						return;
71
    				}
72
    			}
73
            }
74
        }
75
    }
76
    public static boolean isBestArmor(ItemStack stack, int type){
77
    	float prot = getProtection(stack);
78
    	String strType = "";
79
    	if(type == 1){
80
    		strType = "helmet";
81
    	}else if(type == 2){
82
    		strType = "chestplate";
83
    	}else if(type == 3){
84
    		strType = "leggings";
85
    	}else if(type == 4){
86
    		strType = "boots";
87
    	}
88
    	if(!stack.getUnlocalizedName().contains(strType)){
89
    		return false;
90
    	}
91
    	for (int i = 5; i < 45; i++) {
92
            if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
93
                ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
94
                if(getProtection(is) > prot && is.getUnlocalizedName().contains(strType))
95
                	return false;
96
            }
97
        }
98
    	return true;
99
    }
100
    public void shiftClick(int slot){
101
    	mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, slot, 0, 1, mc.thePlayer);
102
    }
103
104
    public void drop(int slot){
105
    	mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, slot, 1, 4, mc.thePlayer);
106
    }
107
    public static float getProtection(ItemStack stack){
108
    	float prot = 0;
109
    	if ((stack.getItem() instanceof ItemArmor)) {
110
    		ItemArmor armor = (ItemArmor)stack.getItem();
111
    		prot += armor.damageReduceAmount + (100 - armor.damageReduceAmount) * EnchantmentHelper.getEnchantmentLevel(Enchantment.protection.effectId, stack) * 0.0075D;
112
    		prot += EnchantmentHelper.getEnchantmentLevel(Enchantment.blastProtection.effectId, stack)/100d;
113
    		prot += EnchantmentHelper.getEnchantmentLevel(Enchantment.fireProtection.effectId, stack)/100d;
114
    		prot += EnchantmentHelper.getEnchantmentLevel(Enchantment.thorns.effectId, stack)/100d;
115
    		prot += EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, stack)/50d;   	
116
    		prot += EnchantmentHelper.getEnchantmentLevel(Enchantment.field_180308_g.effectId, stack)/100d;   	
117
    	}
118
	    return prot;
119
    }
120
}

What this file does

AutoArmor is the armor half of the pipeline and the module's only hard dependency. Its settings (DELAY, MODE) gate InventoryManager's armor pass: the pass reads armor.getSetting(AutoArmor.DELAY) and AutoArmor.MODE, waits for AutoArmor's timer, and only calls getBestArmor when AutoArmor is enabled and the screen rule matches. AutoArmor itself defers to InventoryManager when both are on (isEnabled(InventoryManager.class) returns early), so the two modules never double-click. getBestArmor - shared by both modules - iterates armor slots 4-8, drops a worn piece that is no longer best (drop(4 + type), a DROP_ONE_SLOT click) and shift-clicks the best piece from the inventory (shiftClick(i)); its FakeInv mode (not used by InventoryManager's pass) sends a C16PacketClientStatus OPEN_INVENTORY_ACHIEVEMENT to make the server think the inventory opened. The interplay matters for countering because every armor click is a full-weight C0E against the same 50ms timer as the tool swaps and drops.

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 (click-rate 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 FastClick is the rate check for window clicks. Each click feeds data.fastClickFreq - an ActionFrequency(5, 200L), i.e. five 200ms buckets covering one second (InventoryData line 58) - with an amount weight: 1.0 for ordinary clicks, 0.6 for a repeated DROP_ONE_SLOT on the same slot in the CRAFTING inventory (the getAmountWithAction branch, which is exactly the module's drop-one-at-a-time pattern), and scaled weights for COLLECT_TO_CURSOR and shift-click stacks. The newest bucket is scored against cc.fastClickShortTermLimit (default 4, DefaultConfig line 389) and the full window against cc.fastClickNormalLimit (default 15, line 390), both lag-adapted, with violations accruing fastClickVL and cancelling from vl>150 under the default actions. At the module's default 50ms delay the sustained rate is 20 clicks per second: the full-window score of ~20 (or ~12 for a pure drop sequence at 0.6 weight) clears the 15/s normal limit whenever any full-weight shift-click or swap is in the mix, and the per-bucket score sits right at the 4-per-200ms boundary, so timer jitter that bunches five clicks into one bucket trips the short-term path. DELAY >= 2 (10/s) keeps the window score under 15 and passes the rate check entirely.

anticheat InventoryActions (closed-window click rejection)

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 is the window-state check. It tracks each player's open-window state (pp.hasInventoryOpen()) and punishes two inversions: interacting with entities/blocks while a window is open, and - the relevant branch - any ClickInventoryEvent while hasInventoryOpen() == 0, i.e. a window click with no window open. The punish path resyncs the client (e.resync()) to force the window state back in sync. Sigma's Basic mode clicks window 0 with mc.currentScreen == null, which on the server means no S2D window-open ever arrived, so Hawk's ledger records the inventory as closed and every one of the module's clicks is a punishable closed-window click, independent of rate. The OpenInv mode is the designed dodge: it only acts while the GuiInventory screen is open, which arrives with the window-open packet (C16 OPEN_INVENTORY_ACHIEVEMENT or the vanilla open), so Hawk's hasInventoryOpen() is nonzero and the clicks are legitimate. The module's own comment structure shows this was a deliberate mode split rather than an accident.

anticheat ItemSwitchSpeed (the C09 check the module avoids)

ItemSwitchSpeed.java80 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
package me.islandscout.hawk.check.interaction.item;
19
20
import me.islandscout.hawk.HawkPlayer;
21
import me.islandscout.hawk.check.Cancelless;
22
import me.islandscout.hawk.check.CustomCheck;
23
import me.islandscout.hawk.event.Event;
24
import me.islandscout.hawk.event.InteractItemEvent;
25
import me.islandscout.hawk.event.InteractWorldEvent;
26
import me.islandscout.hawk.event.ItemSwitchEvent;
27
import org.bukkit.entity.Player;
28
29
import java.util.*;
30
31
public class ItemSwitchSpeed extends CustomCheck implements Cancelless {
32
33
    private Map<UUID, Long> lastSwitchTicks;
34
    private Set<UUID> usedSomething;
35
    private int MIN_SWITCH_TICKS;
36
37
    //might rename this to "AutoUse"
38
    public ItemSwitchSpeed() {
39
        super("itemswitchspeed", true, -1, 1, 0.999, 5000, "%player% failed item switch speed, VL: %vl%", null);
40
        lastSwitchTicks = new HashMap<>();
41
        usedSomething = new HashSet<>();
42
        MIN_SWITCH_TICKS = (int)customSetting("minSwitchTicks", "", 1);
43
    }
44
45
    //For future reference, if you try to verify that the item-switch packet points to a different slot, beware of falses.
46
    //The client can send item-switch packets regardless if the slot switched or not.
47
48
    @Override
49
    protected void check(Event event) {
50
        if(event instanceof InteractItemEvent || event instanceof InteractWorldEvent) {
51
            usedSomething.add(event.getPlayer().getUniqueId());
52
        }
53
        else if(event instanceof ItemSwitchEvent) {
54
55
            HawkPlayer pp = event.getHawkPlayer();
56
            UUID uuid = pp.getUuid();
57
58
            if(usedSomething.contains(uuid)) {
59
                long lastSwitchTick = lastSwitchTicks.getOrDefault(uuid, 0L);
60
                if(pp.getCurrentTick() - lastSwitchTick < MIN_SWITCH_TICKS) {
61
                    punish(pp, 1, false, event);
62
                }
63
                else {
64
                    reward(pp);
65
                }
66
67
                usedSomething.remove(uuid);
68
            }
69
70
            lastSwitchTicks.put(pp.getUuid(), pp.getCurrentTick());
71
        }
72
    }
73
74
    @Override
75
    public void removeData(Player p) {
76
        UUID uuid = p.getUniqueId();
77
        lastSwitchTicks.remove(uuid);
78
        usedSomething.remove(uuid);
79
    }
80
}

How it counteracts this module

ItemSwitchSpeed is the held-item switch rate check and the counter that the module structurally avoids. It listens for ItemSwitchEvent (fired by C09PacketHeldItemChange) and, whenever the player used an item (InteractItemEvent or InteractWorldEvent) in the same tick window, punishes a switch fewer than MIN_SWITCH_TICKS (default 1) ticks after the previous switch - the signature of autotool-style instant switching. The check is cancelless and only feeds VL. InventoryManager never sends C09: its C09PacketHeldItemChange import is dead code, and every slot change is a C0E SWAP click against window 0, so the check never sees an ItemSwitchEvent from this module. That is the honest verdict for the C09 side of the packet surface: the module is invisible to C09 policing precisely because it routes its hotbar changes through the inventory window protocol instead of the held-item channel - which in turn is why the C0E rate and window-state checks above are the effective counters.

← Back to Analysis Hub