0x0E C0EPacketClickWindow
Player clicks in an inventory window. Handles item moves: pickup, shift-click, number key swap, middle click, drop, drag init, and double-click.
Published 2026-06-18 · Updated 2026-10-14
Fields
| Field | Type | Description |
|---|---|---|
| windowId | byte | Container window ID |
| slotId | short | Slot index (-999=outside, -1=drop) |
| usedButton | byte | Mouse button + shift modifier |
| actionNumber | short | Transaction ID, incremented server-side |
| mode | byte | 0=click, 1=shiftClick, 2=numKey, 3=midClick, 4=drop, 5=drag, 6=doubleClick |
| clickedItem | ItemStack | Item in slot before the click |
Wire Encoding
| Field | Type | Notes |
|---|---|---|
| Window ID | byte | 0=player inv |
| Slot | short | -999=outside window |
| Used Button | byte | 0=left, 1=right + shift |
| Action Number | short | Transaction counter |
| Mode | byte | 0=click, 1=shiftClick, 2=numKey, 3=midClick, 4=drop, 5/6=drag |
| Clicked Item | Slot | ItemStack before click |
MCP References
NetHandlerPlayServer.processClickWindow()Handler Interface
INetHandlerPlayServerNotes
Vanilla Source
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
Deobfuscated MCP 1.8.9 source of C0EPacketClickWindow, fetched directly from Marcelektro/MavenMCP-1.8.9 (net/minecraft/network/play/client/C0EPacketClickWindow.java) at build time and verified present.
Deep Dive
Role in the protocol
C0E is the inventory click packet: windowId, slotId, usedButton, mode, clickedItem (the server's copy of the stack being clicked), and an action number. The server runs openContainer.slotClick and confirms with S32PacketConfirmTransaction only when the clicked-item copy matches; otherwise it re-sends the whole container. It is the only way to move items programmatically, so every inventory automation module funnels through it, either by constructing it directly or through PlayerControllerMP.windowClick.
Vanilla handling
processClickWindow verifies the window id matches the open container and that crafting is allowed, then runs slotClick(slotId, button, mode, player). If the returned stack equals packetIn.getClickedItem() it confirms with S32 (accepted = true) and resyncs; otherwise it stores the action number in a pending map, sends S32 accepted = false, and force-syncs the container. The windowId 0 check matters: clients must match the current window or the click is silently dropped.
Why clients touch it
In the 10-client corpus C0E is used by inventory managers (Sigma InventoryManager via PlayerControllerMP.windowClick), inventory-move modules (Rise 5.99 InvMove cancels and re-wraps C0E with C16+C0D), the Rise 6.2.4 BufferAbuseInventoryMove exploit (sends empty C0E packets to abuse the transaction buffer), captcha bots (Rise 5.99 Auto clicks the Redesky captcha item), and Tenacity NoSlowModule (clicks the armor slot to swap the held item). Note that ChestStealer and AutoArmor in this corpus route through C16 open-inventory status, not C0E clicks. LiquidSense Dev overwrites PlayerControllerMP.windowClick to fire a cancelable ClickWindowEvent before every C0E send, and November Recode 2.0 registers C0E in its Lua scripting packet-id map (0x0E) so scripts can observe and cancel it, but ships no click module of its own.
Exploit surface
The action number and clicked-item echo are the attack surface. Sending clicks with a stale or forged clickedItem makes the server resync the container, which some disablers use to flood the transaction pipeline. BufferAbuseInventoryMove exploits the server's transaction accounting by sending clicks the server must answer, delaying watchdog's transaction-based checks. The windowId mismatch is a silent drop, which InvMove uses to cancel clicks and re-send them under a fake open-inventory state. LiquidSense's windowClick overwrite computes the container transaction id and then discards it, sending (short) -1; the server never validates the action number against a counter, it only echoes it in the S32 reply, so the click confirms the same way a real id would and the client container counter is left stale.
Server-Side Handling
processClickWindow: windowId must equal openContainer.windowId and crafting must be allowed. slotClick mutates the container; on clickedItem match the server confirms (S32 true) and resyncs, on mismatch it stores the action number, sends S32 false, and force-syncs all slots. Crafting players get a full container resend instead of a click.
Protocol Analysis
Fields: windowId byte, slotId short, usedButton byte, mode byte, clickedItem (ItemStack or null), actionNumber short. Window 0 is the player inventory; chests start at 1. The clickedItem must be the exact stack the server last sent for that slot, which is why clients cache S2FPacketSetSlot/S30PacketWindowItems state.
Anti-Cheat Landscape
Anti-cheats track click rate and window state. Inventory move (clicking while moving) is detected by comparing C0E timing against movement packets; CancelInventoryMove in Rise 6.2.4 exists to cancel the C16 open-inventory status so the server never learns the inventory is open. Transaction flooding via C0E is a disabler vector against Watchdog, which uses transaction gaps to time its checks.
implementation Implementation Cases
The programmatic inventory click. Inventory managers click through it, InvMove re-wraps it, BufferAbuseInventoryMove floods it, and a captcha bot clicks with it. Its confirm/resync loop is what makes it both reliable for automation and exploitable for transaction flooding. LiquidSense Dev adds the ClickWindowEvent mixin that lets any module veto clicks, and November Recode 2.0 exposes the packet to Lua scripts.
Automatically equip the best armor and tools by clicking the inventory container.
Sigma InventoryManager scans the container slots, computes protection/weapon scores, and performs shift-clicks and hotbar swaps through mc.playerController.windowClick, which internally constructs C0EPacketClickWindow with the current windowId and the next transaction id. The module guards against concurrent modules (e.g. AutoArmor yields when InventoryManager is on).
// ===== FILE: Sigma 4.11, info/sigmaclient/module/impl/player/InventoryManager.java =====
package info.sigmaclient.module.impl.player;
import java.util.ArrayList;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAppleGold;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemGlassBottle;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemPotion;
import net.minecraft.item.ItemSpade;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C03PacketPlayer;
import net.minecraft.network.play.client.C09PacketHeldItemChange;
import net.minecraft.network.play.client.C0EPacketClickWindow;
import net.minecraft.network.play.server.S04PacketEntityEquipment;
import net.minecraft.network.play.server.S09PacketHeldItemChange;
import net.minecraft.network.play.server.S1CPacketEntityMetadata;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import info.sigmaclient.Client;
import info.sigmaclient.event.Event;
import info.sigmaclient.event.RegisterEvent;
import info.sigmaclient.event.impl.EventPacket;
import info.sigmaclient.event.impl.EventUpdate;
import info.sigmaclient.module.Module;
import info.sigmaclient.module.data.ModuleData;
import info.sigmaclient.module.data.Options;
import info.sigmaclient.module.data.Setting;
import info.sigmaclient.module.impl.player.Scaffold;
import info.sigmaclient.util.misc.ChatUtil;
import info.sigmaclient.util.misc.Timer;
/*
* Made by LeakedPvP
*/
public class InventoryManager extends Module {
public static final String BLOCKCAP = "BLOCKCAP";
public static final String DELAY = "DELAY";
public static final String ARCHERY = "ARCHERY";
public static final String FOOD = "FOOD";
public static final String INVCLEANER = "INVCLEANER";
public static final String MODE = "MODE";
public static final String SWORD = "SWORD";
public InventoryManager(ModuleData data) {
super(data);
settings.put(BLOCKCAP, new Setting<>(BLOCKCAP, 128, "Max blocks allowed in your inventory.", 8, -1, 256));
settings.put(DELAY, new Setting<>(DELAY, 1, "Inventory clicks delay.", 1, 0, 10));
settings.put(ARCHERY, new Setting<>(ARCHERY, false, "Clean bows and arrows."));
settings.put(FOOD, new Setting<>(FOOD, false, "Clean food. Keeps Golden Apples."));
settings.put(SWORD, new Setting<>(SWORD, false, "Keep only swords as weapon."));
settings.put(INVCLEANER, new Setting<>(INVCLEANER, true, "Cleans your inventory for you."));
settings.put(MODE, new Setting<>(MODE, new Options("Mode", "Basic",new String[] {"Basic", "OpenInv"}), "InvManager method."));
}
public static int weaponSlot = 36, pickaxeSlot = 37, axeSlot = 38, shovelSlot = 39;
Timer timer = new Timer();
ArrayList<Integer>whitelistedItems = new ArrayList<>();
@Override
public void onEnable() {
super.onEnable();
}
@Override
@RegisterEvent(events = {EventUpdate.class})
public void onEvent(Event event) {
setSuffix("dev");
long delay = ((Number) settings.get(DELAY).getValue()).longValue()*50;
if(event instanceof EventUpdate){
EventUpdate em =(EventUpdate)event;
String mode = ((Options) settings.get(MODE).getValue()).getSelected();
this.setSuffix(mode);
Module armor = Client.getModuleManager().get(AutoArmor.class);
long Adelay = ((Number) armor.getSetting(AutoArmor.DELAY).getValue()).longValue()*50;
String Amode = ((Options) armor.getSetting(AutoArmor.MODE).getValue()).getSelected();
this.setSuffix(mode);
if(!em.isPre())
return;
if(timer.check(Adelay) && armor.isEnabled()){
if(!Amode.equalsIgnoreCase("OpenInv") || mc.currentScreen instanceof GuiInventory){
if(mc.currentScreen == null || mc.currentScreen instanceof GuiInventory || mc.currentScreen instanceof GuiChat){
getBestArmor();
}
}
}
if( armor.isEnabled())
for(int type = 1; type < 5; type++){
if(mc.thePlayer.inventoryContainer.getSlot(4 + type).getHasStack()){
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(4 + type).getStack();
if(!AutoArmor.isBestArmor(is, type)){
return;
}
}else if(invContainsType(type-1)){
return;
}
}
if(mode.equalsIgnoreCase("OpenInv") && !(mc.currentScreen instanceof GuiInventory)){
return;
}
if(mc.currentScreen == null || mc.currentScreen instanceof GuiInventory || mc.currentScreen instanceof GuiChat){
if(timer.check(delay) && weaponSlot >= 36){
if (!mc.thePlayer.inventoryContainer.getSlot(weaponSlot).getHasStack()){
getBestWeapon(weaponSlot);
}else{
if(!isBestWeapon(mc.thePlayer.inventoryContainer.getSlot(weaponSlot).getStack())){
getBestWeapon(weaponSlot);
}
}
}
if(timer.check(delay) && pickaxeSlot >= 36){
getBestPickaxe(pickaxeSlot);
}
if(timer.check(delay) && shovelSlot >= 36){
getBestShovel(shovelSlot);
}
if(timer.check(delay) && axeSlot >= 36){
getBestAxe(axeSlot);
}
if(timer.check(delay) && (Boolean) settings.get(INVCLEANER).getValue())
for (int i = 9; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
if(shouldDrop(is, i)){
drop(i);
timer.reset();
if(delay > 0)
break;
}
}
}
}
}
}
public void shiftClick(int slot){
mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, slot, 0, 1, mc.thePlayer);
}
public void swap(int slot1, int hotbarSlot){
mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, slot1, hotbarSlot, 2, mc.thePlayer);
}
public void drop(int slot){
mc.playerController.windowClick(mc.thePlayer.inventoryContainer.windowId, slot, 1, 4, mc.thePlayer);
}
public boolean isBestWeapon(ItemStack stack){
float damage = getDamage(stack);
for (int i = 9; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
if(getDamage(is) > damage && (is.getItem() instanceof ItemSword || !(Boolean) settings.get(SWORD).getValue()))
return false;
}
}
if((stack.getItem() instanceof ItemSword || !(Boolean) settings.get(SWORD).getValue())){
return true;
}else{
return false;
}
}
public void getBestWeapon(int slot){
for (int i = 9; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
if(isBestWeapon(is) && getDamage(is) > 0 && (is.getItem() instanceof ItemSword || !(Boolean) settings.get(SWORD).getValue())){
swap(i, slot - 36);
timer.reset();
break;
}
}
}
}
private float getDamage(ItemStack stack) {
float damage = 0;
Item item = stack.getItem();
if(item instanceof ItemTool){
ItemTool tool = (ItemTool)item;
damage += tool.getDamage();
}
if(item instanceof ItemSword){
ItemSword sword = (ItemSword)item;
damage += sword.getAttackDamage();
}
damage += EnchantmentHelper.getEnchantmentLevel(Enchantment.sharpness.effectId, stack) * 1.25f +
EnchantmentHelper.getEnchantmentLevel(Enchantment.fireAspect.effectId, stack) * 0.01f;
return damage;
}
public boolean shouldDrop(ItemStack stack, int slot){
if(stack.getDisplayName().toLowerCase().contains("(right click)")){
return false;
}
if(stack.getDisplayName().toLowerCase().contains("§k||")){
return false;
}
if((slot == weaponSlot && isBestWeapon(mc.thePlayer.inventoryContainer.getSlot(weaponSlot).getStack())) ||
(slot == pickaxeSlot && isBestPickaxe(mc.thePlayer.inventoryContainer.getSlot(pickaxeSlot).getStack()) && pickaxeSlot >= 0) ||
(slot == axeSlot && isBestAxe(mc.thePlayer.inventoryContainer.getSlot(axeSlot).getStack()) && axeSlot >= 0) ||
(slot == shovelSlot && isBestShovel(mc.thePlayer.inventoryContainer.getSlot(shovelSlot).getStack()) && shovelSlot >= 0) ){
return false;
}
if(stack.getItem() instanceof ItemArmor){
for(int type = 1; type < 5; type++){
if(mc.thePlayer.inventoryContainer.getSlot(4 + type).getHasStack()){
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(4 + type).getStack();
if(AutoArmor.isBestArmor(is, type)){
continue;
}
}
if(AutoArmor.isBestArmor(stack, type)){
return false;
}
}
}
if (stack.getItem() instanceof ItemBlock &&
(getBlockCount() > ((Number) settings.get(BLOCKCAP).getValue()).intValue() ||
Scaffold.getBlacklistedBlocks().contains(((ItemBlock)stack.getItem()).getBlock()))){
return true;
}
if(stack.getItem() instanceof ItemPotion){
if(isBadPotion(stack)){
return true;
}
}
if(stack.getItem() instanceof ItemFood && (Boolean) settings.get(FOOD).getValue() && !(stack.getItem() instanceof ItemAppleGold)){
return true;
}
if(stack.getItem() instanceof ItemHoe || stack.getItem() instanceof ItemTool || stack.getItem() instanceof ItemSword || stack.getItem() instanceof ItemArmor){
return true;
}
if((stack.getItem() instanceof ItemBow || stack.getItem().getUnlocalizedName().contains("arrow")) && (Boolean) settings.get(ARCHERY).getValue()){
return true;
}
if(((stack.getItem().getUnlocalizedName().contains("tnt")) ||
(stack.getItem().getUnlocalizedName().contains("stick")) ||
(stack.getItem().getUnlocalizedName().contains("egg")) ||
(stack.getItem().getUnlocalizedName().contains("string")) ||
(stack.getItem().getUnlocalizedName().contains("cake")) ||
(stack.getItem().getUnlocalizedName().contains("mushroom")) ||
(stack.getItem().getUnlocalizedName().contains("flint")) ||
(stack.getItem().getUnlocalizedName().contains("compass")) ||
(stack.getItem().getUnlocalizedName().contains("dyePowder")) ||
(stack.getItem().getUnlocalizedName().contains("feather")) ||
(stack.getItem().getUnlocalizedName().contains("bucket")) ||
(stack.getItem().getUnlocalizedName().contains("chest") && !stack.getDisplayName().toLowerCase().contains("collect")) ||
(stack.getItem().getUnlocalizedName().contains("snow")) ||
(stack.getItem().getUnlocalizedName().contains("fish")) ||
(stack.getItem().getUnlocalizedName().contains("enchant")) ||
(stack.getItem().getUnlocalizedName().contains("exp")) ||
(stack.getItem().getUnlocalizedName().contains("shears")) ||
(stack.getItem().getUnlocalizedName().contains("anvil")) ||
(stack.getItem().getUnlocalizedName().contains("torch")) ||
(stack.getItem().getUnlocalizedName().contains("seeds")) ||
(stack.getItem().getUnlocalizedName().contains("leather")) ||
(stack.getItem().getUnlocalizedName().contains("reeds")) ||
(stack.getItem().getUnlocalizedName().contains("skull")) ||
(stack.getItem().getUnlocalizedName().contains("record")) ||
(stack.getItem().getUnlocalizedName().contains("snowball")) ||
(stack.getItem() instanceof ItemGlassBottle) ||
(stack.getItem().getUnlocalizedName().contains("piston")))){
return true;
}
return false;
}
public ArrayList<Integer>getWhitelistedItem(){
return whitelistedItems;
}
private int getBlockCount() {
int blockCount = 0;
for (int i = 0; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
Item item = is.getItem();
if (is.getItem() instanceof ItemBlock && !Scaffold.getBlacklistedBlocks().contains(((ItemBlock) item).getBlock())) {
blockCount += is.stackSize;
}
}
}
return blockCount;
}
private void getBestPickaxe(int slot){
for (int i = 9; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
if(isBestPickaxe(is) && pickaxeSlot != i){
if(!isBestWeapon(is))
if(!mc.thePlayer.inventoryContainer.getSlot(pickaxeSlot).getHasStack()){
swap(i, pickaxeSlot - 36);
timer.reset();
if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
return;
}else if(!isBestPickaxe(mc.thePlayer.inventoryContainer.getSlot(pickaxeSlot).getStack())){
swap(i, pickaxeSlot - 36);
timer.reset();
if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
return;
}
}
}
}
}
private void getBestShovel(int slot){
for (int i = 9; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
if(isBestShovel(is) && shovelSlot != i){
if(!isBestWeapon(is))
if(!mc.thePlayer.inventoryContainer.getSlot(shovelSlot).getHasStack()){
swap(i, shovelSlot - 36);
timer.reset();
if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
return;
}else if(!isBestShovel(mc.thePlayer.inventoryContainer.getSlot(shovelSlot).getStack())){
swap(i, shovelSlot - 36);
timer.reset();
if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
return;
}
}
}
}
}
private void getBestAxe(int slot){
for (int i = 9; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
if(isBestAxe(is) && axeSlot != i){
if(!isBestWeapon(is))
if(!mc.thePlayer.inventoryContainer.getSlot(axeSlot).getHasStack()){
swap(i, axeSlot - 36);
timer.reset();
if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
return;
}else if(!isBestAxe(mc.thePlayer.inventoryContainer.getSlot(axeSlot).getStack())){
swap(i, axeSlot - 36);
timer.reset();
if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
return;
}
}
}
}
}
private boolean isBestPickaxe(ItemStack stack){
Item item = stack.getItem();
if(!(item instanceof ItemPickaxe))
return false;
float value = getToolEffect(stack);
for (int i = 9; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
if(getToolEffect(is) > value && is.getItem() instanceof ItemPickaxe){
return false;
}
}
}
return true;
}
private boolean isBestShovel(ItemStack stack){
Item item = stack.getItem();
if(!(item instanceof ItemSpade))
return false;
float value = getToolEffect(stack);
for (int i = 9; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
if(getToolEffect(is) > value && is.getItem() instanceof ItemSpade){
return false;
}
}
}
return true;
}
private boolean isBestAxe(ItemStack stack){
Item item = stack.getItem();
if(!(item instanceof ItemAxe))
return false;
float value = getToolEffect(stack);
for (int i = 9; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
if(getToolEffect(is) > value && is.getItem() instanceof ItemAxe && !isBestWeapon(stack)){
return false;
}
}
}
return true;
}
private float getToolEffect(ItemStack stack){
Item item = stack.getItem();
if(!(item instanceof ItemTool))
return 0;
String name = item.getUnlocalizedName();
ItemTool tool = (ItemTool)item;
float value = 1;
if(item instanceof ItemPickaxe){
value = tool.getStrVsBlock(stack, Blocks.stone);
if(name.toLowerCase().contains("gold")){
value -= 5;
}
}else if(item instanceof ItemSpade){
value = tool.getStrVsBlock(stack, Blocks.dirt);
if(name.toLowerCase().contains("gold")){
value -= 5;
}
}else if(item instanceof ItemAxe){
value = tool.getStrVsBlock(stack, Blocks.log);
if(name.toLowerCase().contains("gold")){
value -= 5;
}
}else
return 1f;
value += EnchantmentHelper.getEnchantmentLevel(Enchantment.efficiency.effectId, stack) * 0.0075D;
value += EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, stack)/100d;
return value;
}
private boolean isBadPotion(ItemStack stack) {
if (stack != null && stack.getItem() instanceof ItemPotion) {
final ItemPotion potion = (ItemPotion) stack.getItem();
if(potion.getEffects(stack) == null)
return true;
for (final Object o : potion.getEffects(stack)) {
final PotionEffect effect = (PotionEffect) o;
if (effect.getPotionID() == Potion.poison.getId() || effect.getPotionID() == Potion.harm.getId() || effect.getPotionID() == Potion.moveSlowdown.getId() || effect.getPotionID() == Potion.weakness.getId()) {
return true;
}
}
}
return false;
}
boolean invContainsType(int type){
for(int i = 9; i < 45; i++){
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
Item item = is.getItem();
if(item instanceof ItemArmor){
ItemArmor armor = (ItemArmor)item;
if(type == armor.armorType){
return true;
}
}
}
}
return false;
}
public void getBestArmor(){
for(int type = 1; type < 5; type++){
if(mc.thePlayer.inventoryContainer.getSlot(4 + type).getHasStack()){
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(4 + type).getStack();
if(AutoArmor.isBestArmor(is, type)){
continue;
}else{
drop(4 + type);
}
}
for (int i = 9; i < 45; i++) {
if (mc.thePlayer.inventoryContainer.getSlot(i).getHasStack()) {
ItemStack is = mc.thePlayer.inventoryContainer.getSlot(i).getStack();
if(AutoArmor.isBestArmor(is, type) && AutoArmor.getProtection(is) > 0){
shiftClick(i);
timer.reset();
if(((Number) settings.get(DELAY).getValue()).longValue() > 0)
return;
}
}
}
}
}
}
// NOTE (AI): Sigma 4.11 InventoryManager: complete 498-line file. Uses playerController.windowClick (lines ~151-157) which builds C0E; the packet class is imported at line ~29. Full scoring and click logic for armor/tool management.
Allow movement while an inventory GUI is open by re-sending clicks under a fake inventory-open state.
In packet mode, InvMove cancels C0DPacketCloseWindow and C0EPacketClickWindow, then replays the click preceded by a C16 OPEN_INVENTORY_ACHIEVEMENT status and followed by a C0DPacketCloseWindow, all via sendPacketWithoutEvent so the server sees a coherent open-click-close sequence while the player keeps moving.
// ===== FILE: Rise 5.99, dev/rise/module/impl/movement/InvMove.java =====
/*
Copyright Alan Wood 2021
None of this code to be reused without my written permission
Intellectual Rights owned by Alan Wood
*/
package dev.rise.module.impl.movement;
import dev.rise.event.impl.motion.PreMotionEvent;
import dev.rise.event.impl.packet.PacketSendEvent;
import dev.rise.module.Module;
import dev.rise.module.api.ModuleInfo;
import dev.rise.module.enums.Category;
import dev.rise.setting.impl.BooleanSetting;
import dev.rise.setting.impl.NumberSetting;
import dev.rise.ui.clickgui.impl.ClickGUI;
import dev.rise.ui.clickgui.impl.strikeless.StrikeGUI;
import dev.rise.util.player.PacketUtil;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C0DPacketCloseWindow;
import net.minecraft.network.play.client.C0EPacketClickWindow;
import net.minecraft.network.play.client.C16PacketClientStatus;
@ModuleInfo(name = "InvMove", description = "Lets you move while in Guis", category = Category.MOVEMENT)
public final class InvMove extends Module {
private final NumberSetting slowdown = new NumberSetting("Slow Down", this, 1, 0.1, 1, 0.1);
private final BooleanSetting packet = new BooleanSetting("Packet", this, false);
private final KeyBinding[] affectedBindings = new KeyBinding[]{
mc.gameSettings.keyBindForward,
mc.gameSettings.keyBindBack,
mc.gameSettings.keyBindRight,
mc.gameSettings.keyBindLeft,
mc.gameSettings.keyBindJump
};
@Override
public void onPreMotion(final PreMotionEvent event) {
if (mc.currentScreen != null && !(mc.currentScreen instanceof GuiChat)) {
for (final KeyBinding a : affectedBindings) {
a.setKeyPressed(GameSettings.isKeyDown(a));
}
if (mc.currentScreen != null) {
final double s = slowdown.getValue();
if (!(mc.currentScreen instanceof ClickGUI || mc.currentScreen instanceof StrikeGUI)) {
mc.thePlayer.motionX *= s;
mc.thePlayer.motionZ *= s;
}
}
}
}
@Override
public void onPacketSend(final PacketSendEvent event) {
final Packet<?> p = event.getPacket();
if (packet.isEnabled()) {
if (p instanceof C0DPacketCloseWindow)
event.setCancelled(true);
if (p instanceof C0EPacketClickWindow) {
event.setCancelled(true);
PacketUtil.sendPacketWithoutEvent(new C16PacketClientStatus(C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT));
PacketUtil.sendPacketWithoutEvent(event.getPacket());
PacketUtil.sendPacketWithoutEvent(new C0DPacketCloseWindow(mc.thePlayer.inventoryContainer.windowId));
}
if (p instanceof C16PacketClientStatus) {
final C16PacketClientStatus packetClientStatus = (C16PacketClientStatus) event.getPacket();
if (packetClientStatus.getStatus() == C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT)
event.setCancelled(true);
}
}
}
}
// NOTE (AI): Rise 5.99 InvMove: complete file. Packet mode (lines ~63-79) cancels C0E, sends C16 open + the click + C0D close without events, and suppresses C16 open status so the GUI state stays hidden.
Abuse the server's transaction buffer by sending C0E clicks while the inventory is open, delaying watchdog's transaction-based movement checks.
Sends empty C0EPacketClickWindow packets (no-arg constructor) on a tick cycle while an inventory screen is open, and cancels legit C0E so the client's own clicks do not leak. The flood keeps the server's pending-transaction map busy so its confirm-based timing checks lag.
// ===== FILE: Rise 6.2.4, Client-release2/Client/src/main/java/com/alan/clients/module/impl/movement/inventorymove/BufferAbuseInventoryMove.java =====
package com.alan.clients.module.impl.movement.inventorymove;
import com.alan.clients.event.Listener;
import com.alan.clients.event.annotations.EventLink;
import com.alan.clients.event.impl.motion.JumpEvent;
import com.alan.clients.event.impl.motion.PreMotionEvent;
import com.alan.clients.event.impl.motion.PreUpdateEvent;
import com.alan.clients.event.impl.motion.StrafeEvent;
import com.alan.clients.event.impl.other.WorldChangeEvent;
import com.alan.clients.event.impl.packet.PacketSendEvent;
import com.alan.clients.module.impl.movement.InventoryMove;
import com.alan.clients.util.packet.PacketUtil;
import com.alan.clients.value.Mode;
import com.alan.clients.value.impl.NumberValue;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C0EPacketClickWindow;
import java.util.concurrent.ConcurrentLinkedQueue;
public class BufferAbuseInventoryMove extends Mode<InventoryMove> {
private final NumberValue clicksSetting = new NumberValue("Clicks", this, 3, 2, 10, 1);
private final NumberValue amount = new NumberValue("Amount", this, 5, 1, 10, 1);
private final ConcurrentLinkedQueue<Packet<?>> packets = new ConcurrentLinkedQueue<>();
private boolean done, sent;
private int clicks;
public BufferAbuseInventoryMove(String name, InventoryMove parent) {
super(name, parent);
}
@EventLink
public final Listener<PreMotionEvent> onPreMotionEvent = event -> {
if (this.canAbuse()) {
if (!this.sent) {
if (!this.done) {
this.done = true;
} else {
for (int i = 0; i < this.amount.getValue().intValue(); i++) {
PacketUtil.sendNoEvent(new C0EPacketClickWindow());
}
packets.forEach(PacketUtil::sendNoEvent);
packets.clear();
this.sent = true;
}
}
} else {
this.done = false;
this.sent = false;
}
};
@EventLink
public final Listener<StrafeEvent> onStrafe = event -> {
if (this.canAbuse() && !this.sent) {
event.setCancelled();
}
};
@EventLink
public final Listener<JumpEvent> onJump = event -> {
if (this.canAbuse() && !this.sent) {
event.setCancelled();
}
};
@EventLink
public final Listener<PacketSendEvent> onPacketSend = event -> {
final Packet<?> p = event.getPacket();
if (p instanceof C0EPacketClickWindow) {
if (this.canAbuse() && !this.sent) {
event.setCancelled();
packets.add(p);
return;
}
this.clicks++;
}
};
@EventLink
public final Listener<WorldChangeEvent> onWorldChange = event -> {
packets.clear();
};
private boolean canAbuse() {
return clicks > 0 && clicks % this.clicksSetting.getValue().intValue() == 0;
}
private final KeyBinding[] AFFECTED_BINDINGS = new KeyBinding[]{
mc.gameSettings.keyBindForward,
mc.gameSettings.keyBindBack,
mc.gameSettings.keyBindRight,
mc.gameSettings.keyBindLeft,
mc.gameSettings.keyBindJump
};
@EventLink
public final Listener<PreUpdateEvent> onPreUpdate = event -> {
if (mc.currentScreen instanceof GuiChat || mc.currentScreen == this.getClickGUI()) {
return;
}
for (final KeyBinding bind : AFFECTED_BINDINGS) {
bind.setPressed(GameSettings.isKeyDown(bind));
}
};
}
// NOTE (AI): Rise 6.2.4 BufferAbuseInventoryMove: complete file. Sends raw no-arg C0E (line ~45) on a cycle and cancels legit C0E (line ~76).
Automatically click the Redesky captcha item and send register/login commands on login.
Intercepts S2FPacketSetSlot; when a slot's item display name contains 'aqui', sends C0EPacketClickWindow(windowId, slotId, 0, 0, item, 1919) via the send queue, confirming the captcha. A companion register/login routine sends C01 chat commands on world join.
// ===== FILE: Rise 5.99, dev/rise/module/impl/other/Auto.java =====
/*
Copyright Alan Wood 2021
None of this code to be reused without my written permission
Intellectual Rights owned by Alan Wood
*/
package dev.rise.module.impl.other;
import dev.rise.event.impl.motion.PreMotionEvent;
import dev.rise.event.impl.packet.PacketReceiveEvent;
import dev.rise.module.Module;
import dev.rise.module.api.ModuleInfo;
import dev.rise.module.enums.Category;
import dev.rise.setting.impl.BooleanSetting;
import net.minecraft.item.ItemStack;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C0EPacketClickWindow;
import net.minecraft.network.play.server.S2FPacketSetSlot;
@ModuleInfo(name = "Auto", description = "Automatically does things for you", category = Category.OTHER)
public final class Auto extends Module {
private final BooleanSetting redeskyAutoCaptcha = new BooleanSetting("Redesky Auto Captcha", this, false);
private final BooleanSetting redeskyAutoRegister = new BooleanSetting("Redesky Auto Register", this, false);
boolean sentReg, sentLogin;
int ticks;
int amountFlagged;
@Override
public void onPacketReceive(final PacketReceiveEvent event) {
final Packet packet = event.getPacket();
if (redeskyAutoCaptcha.isEnabled()) {
if (packet instanceof S2FPacketSetSlot) {
final S2FPacketSetSlot S2F = (S2FPacketSetSlot) packet;
if (S2F.func_149175_c() == 0) {
return;
}
final ItemStack item = S2F.func_149174_e();
if (item != null && item.getDisplayName().toLowerCase().contains("aqui")) {
mc.thePlayer.sendQueue.addToSendQueue(new C0EPacketClickWindow(S2F.func_149175_c(), S2F.func_149173_d(), 0, 0, item, (short) 1919));
}
}
}
}
@Override
public void onPreMotion(final PreMotionEvent event) {
if (mc.thePlayer.ticksExisted % 20 == 0)
amountFlagged--;
if (amountFlagged < 0)
amountFlagged = 0;
if (redeskyAutoRegister.isEnabled()) {
if (mc.thePlayer.ticksExisted == 1) {
sentLogin = sentReg = false;
}
if (mc.currentScreen == null) {
ticks++;
if (ticks > 30) {
if (!sentReg) {
mc.thePlayer.sendChatMessage("/register Lolxd00 Lolxd00");
sentReg = true;
} else if (!sentLogin) {
mc.thePlayer.sendChatMessage("/login Lolxd00");
sentLogin = true;
}
}
} else {
ticks = 0;
}
}
}
}
// NOTE (AI): Rise 5.99 Auto: complete file. C0E captcha click (line ~48) built from the S2F slot data with a fixed action number 1919.
Bypass use-item slowdown by swapping the held item to an armor slot with a window click instead of a C08 use packet.
While using an item and not in a GUI, send C0DPacketCloseWindow(0) followed by C0EPacketClickWindow(0, 36 + currentItem, 0, 6, null, nextTransactionID). Mode 6 with button 0 swaps the held item into the armor slot, ending the use state server-side without the slowdown, then the item is swapped back. A 'Watchdog' mode toggles this per-AC.
// ===== FILE: Tenacity 6.0, dev/tenacity/module/impl/movement/NoSlowModule.java =====
package dev.tenacity.module.impl.movement;
import dev.tenacity.event.Event;
import dev.tenacity.event.IEventListener;
import dev.tenacity.event.impl.packet.PacketReceiveEvent;
import dev.tenacity.event.impl.player.MotionEvent;
import dev.tenacity.event.impl.player.SlowDownEvent;
import dev.tenacity.module.Module;
import dev.tenacity.module.ModuleCategory;
import java.util.ArrayList;
import java.util.Arrays;
import dev.tenacity.setting.impl.ModeSetting;
import net.minecraft.item.ItemSword;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.C0DPacketCloseWindow;
import net.minecraft.network.play.client.C0EPacketClickWindow;
import net.minecraft.network.play.server.S2FPacketSetSlot;
import net.minecraft.world.gen.layer.GenLayerEdge;
public final class NoSlowModule extends Module {
private boolean isItemGhost;
private final ModeSetting mode = new ModeSetting("Mode", "Vanilla", "Watchdog");
public NoSlowModule() {
super("NoSlow", "Makes you not take slow down", ModuleCategory.MOVEMENT);
initializeSettings(mode);
}
private final IEventListener<SlowDownEvent> onSlowDownEvent = Event::cancel;
private final IEventListener<MotionEvent> onMotionEvent = event -> {
switch (mode.getCurrentMode()) {
case "Vanilla": {
if (event.isPre() && mc.thePlayer != null) {
if (!isItemGhost)
sendBypass();
if (!mc.thePlayer.isUsingItem())
isItemGhost = false;
}
}
case "Watchdog": {
if (mc.thePlayer.isUsingItem()) {
if (mc.currentScreen == null && mc.thePlayer.getHeldItem() != null) {
}
}
break;
}
}
};
private final IEventListener<PacketReceiveEvent> onPacketReceiveEvent = event -> {
if (event.getPacket() instanceof S2FPacketSetSlot && mc.thePlayer != null) {
final S2FPacketSetSlot s2f = (S2FPacketSetSlot) event.getPacket();
if (s2f.func_149175_c() == 0 && mc.thePlayer.isUsingItem() && mc.currentScreen == null && mc.thePlayer.getHeldItem() != null && !(mc.thePlayer.getHeldItem().getItem() instanceof ItemSword)) {
event.cancel();
//isItemGhost = false;
}
}
};
private void sendBypass() {
if (mc.thePlayer.isUsingItem() && mc.currentScreen == null && mc.thePlayer.getHeldItem() != null && !(mc.thePlayer.getHeldItem().getItem() instanceof ItemSword)) {
mc.getNetHandler().addToSendQueue(new C0DPacketCloseWindow(0));
mc.getNetHandler().addToSendQueue(new C0EPacketClickWindow(0, 36 + mc.thePlayer.inventory.currentItem, 0, 6, null, mc.thePlayer.inventoryContainer.getNextTransactionID(mc.thePlayer.inventory)));
isItemGhost = true;
}
}
}
// NOTE (AI): Tenacity 6.0 NoSlowModule: complete file. The click-window bypass (line ~66-67) swaps the held item to armor slot 6 to clear the use state; S2F slot cancels keep the ghost item hidden.
Route every inventory click through a cancelable ClickWindowEvent before the C0E is queued, so LiquidBounce modules can veto or observe clicks.
@Overwrite of PlayerControllerMP.windowClick: build ClickWindowEvent, call it on the client event manager, return null if cancelled; otherwise run slotClick locally, then addToSendQueue(new C0EPacketClickWindow(windowId, slotId, mouseButtonClicked, mode, itemstack, (short) -1)). The computed getNextTransactionID value is discarded.
// ===== FILE: LiquidSense Dev, net/ccbluex/liquidbounce/injection/forge/mixins/entity/MixinPlayerControllerMP.java =====
/*
* LiquidBounce Hacked Client
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
* https://github.com/CCBlueX/LiquidBounce/
*/
package net.ccbluex.liquidbounce.injection.forge.mixins.entity;
import net.ccbluex.liquidbounce.LiquidBounce;
import net.ccbluex.liquidbounce.event.AttackEvent;
import net.ccbluex.liquidbounce.event.ClickWindowEvent;
import net.ccbluex.liquidbounce.features.module.modules.exploit.AbortBreaking;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.C0EPacketClickWindow;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(PlayerControllerMP.class)
@SideOnly(Side.CLIENT)
public class MixinPlayerControllerMP {
@Inject(method = "attackEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/PlayerControllerMP;syncCurrentPlayItem()V"))
private void attackEntity(EntityPlayer entityPlayer, Entity targetEntity, CallbackInfo callbackInfo) {
LiquidBounce.eventManager.callEvent(new AttackEvent(targetEntity));
}
@Inject(method = "getIsHittingBlock", at = @At("HEAD"), cancellable = true)
private void getIsHittingBlock(CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
if (LiquidBounce.moduleManager.getModule(AbortBreaking.class).getState())
callbackInfoReturnable.setReturnValue(false);
}
@Shadow
@Final
public NetHandlerPlayClient netClientHandler;
@Overwrite
public ItemStack windowClick(int windowId, int slotId, int mouseButtonClicked, int mode, EntityPlayer playerIn) {
final ClickWindowEvent event = new ClickWindowEvent(windowId, slotId, mouseButtonClicked, mode);
LiquidBounce.eventManager.callEvent(event);
if (event.isCancelled())
return null;
short short1 = playerIn.openContainer.getNextTransactionID(playerIn.inventory);
ItemStack itemstack = playerIn.openContainer.slotClick(slotId, mouseButtonClicked, mode, playerIn);
this.netClientHandler.addToSendQueue(new C0EPacketClickWindow(windowId, slotId, mouseButtonClicked, mode, itemstack, (short) -1));
return itemstack;
}
}
// NOTE (AI): The @Overwrite fires the cancelable ClickWindowEvent before any packet exists, so click vetoing happens above the network layer. The computed transaction id is discarded in favor of (short) -1; the server echoes the action unvalidated in S32, so clicks still confirm.
anticheat Anti-Cheat Checks
The click window packet is the only inventory interaction the server sees: window id, slot, button, action number and the dragged item. Anticheats use it to police click cadence and protocol correctness (Frequency InventoryA, NCP InventoryListener with FastClick and Gutenberg), and to catch movement while an inventory is open, the inventory-move cheat domain (CheaterDeleter InventoryMoveCheck, Negativity InventoryMoveProtocol). Because the packet is also the acknowledgement channel for server transactions, it feeds NCP's window-click and frequency bookkeeping.
Classic statistical inventory-click check: legit clicks arrive with variable spacing, clicker clicks do not.
Samples the number of flying packets between WrappedPlayInWindowClick packets when fewer than 5 movements separate clicks and the player is not teleporting. At 5 samples it computes the standard deviation and outlier count; a deviation below 1 with zero outliers fails the check.
// ===== FILE: ElevatedDev-Frequency, src/main/java/xyz/elevated/frequency/check/impl/inventory/InventoryA.java =====
package xyz.elevated.frequency.check.impl.inventory;
import com.google.common.collect.Lists;
import xyz.elevated.frequency.check.CheckData;
import xyz.elevated.frequency.check.type.PacketCheck;
import xyz.elevated.frequency.data.PlayerData;
import xyz.elevated.frequency.exempt.type.ExemptType;
import xyz.elevated.frequency.util.MathUtil;
import xyz.elevated.frequency.util.Pair;
import xyz.elevated.frequency.wrapper.impl.client.WrappedPlayInFlying;
import xyz.elevated.frequency.wrapper.impl.client.WrappedPlayInWindowClick;
import java.util.Deque;
import java.util.List;
@CheckData(name = "Inventory (A)")
public final class InventoryA extends PacketCheck {
private int movements = 0;
private final Deque<Integer> samples = Lists.newLinkedList();
public InventoryA(final PlayerData playerData) {
super(playerData);
}
@Override
public void process(final Object object) {
if (object instanceof WrappedPlayInWindowClick) {
final boolean valid = movements < 5 && !this.isExempt(ExemptType.TELEPORTING);
// Make sure the player has not teleported and the movements are below 5
if (valid) samples.add(movements);
// Once the sample size is 5
if (samples.size() == 5) {
final Pair<List<Double>, List<Double>> outlierPair = MathUtil.getOutliers(samples);
// Get the outliers and the deviation from the math utility
final double deviation = MathUtil.getStandardDeviation(samples);
final double outliers = outlierPair.getX().size() + outlierPair.getY().size();
// If the deviation is low and there are no outliers, flag
if (deviation < 1.f && outliers == 0.0) fail();
samples.clear();
}
movements = 0;
} else if (object instanceof WrappedPlayInFlying) {
++movements;
}
}
}
// NOTE (AI): Frequency InventoryA samples the movement gaps between window click packets: a deviation below 1 with zero outliers across 5 clicks means the clicks are arriving at mechanically constant intervals, which is the inventory-clicker signature.
Modern Fabric-side inventory-move check: position changes while a screen handler is open must agree with the player's velocity.
A CDModule listening to movement, packet and damage callbacks. While the current screen handler is open and the player is not flying or in a collision cluster, position-change packets are validated: vertical rises with downward velocity flag immediately, and horizontal deltas that grow from a zero-velocity baseline flag after the 500 ms grace window. Closing the screen or taking damage resets the deltas.
// ===== FILE: CoolMineman-CheaterDeleter, src/main/java/io/github/coolmineman/cheaterdeleter/modules/movement/InventoryMoveCheck.java =====
package io.github.coolmineman.cheaterdeleter.modules.movement;
import io.github.coolmineman.cheaterdeleter.events.PlayerMovementListener;
import io.github.coolmineman.cheaterdeleter.events.PacketCallback;
import io.github.coolmineman.cheaterdeleter.events.PlayerDamageListener;
import io.github.coolmineman.cheaterdeleter.modules.CDModule;
import io.github.coolmineman.cheaterdeleter.objects.PlayerMoveC2SPacketView;
import io.github.coolmineman.cheaterdeleter.objects.entity.CDPlayer;
import io.github.coolmineman.cheaterdeleter.util.BlockCollisionUtil;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.network.Packet;
import net.minecraft.network.listener.ServerPlayPacketListener;
import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket;
import net.minecraft.util.ActionResult;
public class InventoryMoveCheck extends CDModule
implements PlayerMovementListener, PacketCallback, PlayerDamageListener {
public InventoryMoveCheck() {
super("inventorymove_check");
PlayerMovementListener.EVENT.register(this);
PacketCallback.EVENT.register(this);
PlayerDamageListener.EVENT.register(this);
}
@Override
public long getFlagCoolDownMs() {
return 100;
}
@Override
public void onMovement(CDPlayer player, PlayerMoveC2SPacketView packet, MoveCause cause) {
if (
!enabledFor(player) ||
player.isFallFlying() ||
player.isSpectator() ||
BlockCollisionUtil.isNearby(player, 2, 4, BlockCollisionUtil.NON_SOLID_COLLISION)
) {
return;
}
InventoryMoveCheckData data = player.getOrCreateData(InventoryMoveCheckData.class, InventoryMoveCheckData::new);
if (packet.isChangePosition() && player.getCurrentScreenHandler() != null) {
if (!data.wasOpen) {
data.wasOpen = true;
data.openTime = System.currentTimeMillis();
}
if (invalidateMove(player, packet)) {
flag(player, FlagSeverity.MINOR, "Inventory Move");
}
} else if (player.getCurrentScreenHandler() == null) {
data.lastDeltaX = Double.MAX_VALUE;
data.lastDeltaZ = Double.MAX_VALUE;
data.wasOpen = false;
}
}
private boolean invalidateMove(CDPlayer player, PlayerMoveC2SPacketView packet) {
InventoryMoveCheckData data = player.getOrCreateData(InventoryMoveCheckData.class, InventoryMoveCheckData::new);
if (System.currentTimeMillis() - data.openTime < 500)
return false;
if (player.getVelocity().getY() < 0.0 && packet.getY() > player.getPacketY())
return true;
double delaX = Math.abs(packet.getX() - player.getPacketX());
double delaZ = Math.abs(packet.getZ() - player.getPacketZ());
if (player.getVelocity().getX() == 0.0 && delaX > 0.0 && delaX > data.lastDeltaX)
return true;
if (player.getVelocity().getX() != 0.0) {
data.lastDeltaX = Double.MAX_VALUE;
} else {
data.lastDeltaX = delaX;
}
if (player.getVelocity().getZ() == 0.0 && delaZ > 0.0 && delaZ > data.lastDeltaZ)
return true;
if (player.getVelocity().getZ() != 0.0) {
data.lastDeltaZ = Double.MAX_VALUE;
} else {
data.lastDeltaZ = delaZ;
}
return false;
}
public static class InventoryMoveCheckData {
volatile double lastDeltaX = Double.MAX_VALUE;
volatile double lastDeltaZ = Double.MAX_VALUE;
volatile boolean wasOpen = false;
volatile long openTime = 0;
}
@Override
public ActionResult onPacket(CDPlayer player, Packet<ServerPlayPacketListener> packet) {
if (packet instanceof CloseHandledScreenC2SPacket) {
InventoryMoveCheckData data = player.getOrCreateData(InventoryMoveCheckData.class,
InventoryMoveCheckData::new);
data.wasOpen = false;
}
return ActionResult.PASS;
}
@Override
public void onPlayerDamage(CDPlayer player, DamageSource source, float amount) {
InventoryMoveCheckData data = player.getOrCreateData(InventoryMoveCheckData.class, InventoryMoveCheckData::new);
data.lastDeltaX = Double.MAX_VALUE;
data.lastDeltaZ = Double.MAX_VALUE;
data.openTime = System.currentTimeMillis() + 1000;
}
}
// NOTE (AI): CheaterDeleter's InventoryMoveCheck is a Fabric-module: while a screen handler is open it validates position-change packets against the player's velocity, flagging horizontal acceleration that contradicts zero velocity. It ties the click window packet family to the movement module.
Inventory-move scoring protocol: movement while an inventory is open is compared against the baseline captured at open time.
Arms on InventoryClickEvent and InventoryOpenEvent, then on PlayerMoveEvent accumulates an alert amount: starting to sprint or sneak since the inventory opened adds points, and covering distance at or beyond walk speed since open adds more. When the inventory has been open for 3 ticks and the amount exceeds 2, it alerts with a confidence based on time open.
// ===== FILE: Elikill58-Negativity, src/com/elikill58/negativity/spigot/protocols/InventoryMoveProtocol.java =====
package com.elikill58.negativity.spigot.protocols;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.PlayerMoveEvent;
import com.elikill58.negativity.spigot.SpigotNegativity;
import com.elikill58.negativity.spigot.SpigotNegativityPlayer;
import com.elikill58.negativity.spigot.blocks.SpigotLocation;
import com.elikill58.negativity.spigot.utils.LocationUtils;
import com.elikill58.negativity.universal.Cheat;
import com.elikill58.negativity.universal.CheatKeys;
import com.elikill58.negativity.universal.ReportType;
import com.elikill58.negativity.universal.adapter.Adapter;
import com.elikill58.negativity.universal.utils.UniversalUtils;
public class InventoryMoveProtocol extends Cheat implements Listener {
public InventoryMoveProtocol() {
super(CheatKeys.INVENTORY_MOVE, false, Material.NETHER_STAR, CheatCategory.MOVEMENT, true, "invmove");
}
@EventHandler
public void onMove(PlayerMoveEvent e) {
Player p = e.getPlayer();
SpigotNegativityPlayer np = SpigotNegativityPlayer.getNegativityPlayer(p);
if (!np.hasDetectionActive(this) || np.isUsingTrident() || np.hasElytra() || p.isInsideVehicle() || p.getFallDistance() > 0.5 || np.inventoryMoveData == null
|| LocationUtils.isInWater(new SpigotLocation(p.getLocation())) || p.getVelocity().length() > 0.1 || !np.inventoryMoveData.active || LocationUtils.hasMaterialsAround(new SpigotLocation(e.getFrom()), "PISTON")) {
Adapter.getAdapter().debug("Velocity length: " + p.getVelocity().length());
return;
}
if (p.getOpenInventory() == null) {
np.inventoryMoveData = null;
Adapter.getAdapter().debug("No opened inventory but data always running ?");
return;
}
InventoryMoveData data = np.inventoryMoveData;
int amount = 0;
if (p.isSprinting())
amount += data.sprint ? 1 : 5; // means it started sprinting since inv open
if (p.isSneaking())
amount += data.sneak ? 1 : 5; // means it started sneaking since inv open
double distance = e.getFrom().distance(e.getTo());
double distanceXZ = LocationUtils.distanceXZ(e.getFrom(), e.getTo());
if (distanceXZ >= data.distanceXZ && distanceXZ >= p.getWalkSpeed()) // if running at least at the same
amount += (data.distanceXZ - distanceXZ) + 1; // +1 to always have alert
if (distance >= data.distance && distance >= p.getWalkSpeed() && p.getFallDistance() < 0.5) // fall "allow" to make the distance goes brr
amount += (data.distanceXZ - distanceXZ) + 1 - p.getFallDistance();
if (data.timeSinceOpen > 2)
Adapter.getAdapter().debug("Time: " + data.timeSinceOpen + ", amount: " + amount);
if (data.timeSinceOpen >= 3 && amount > 2) {
SpigotNegativity.alertMod(ReportType.WARNING, p, this, UniversalUtils.parseInPorcent(80 + data.timeSinceOpen),
"Sprint: " + p.isSprinting() + ", Sneak: " + p.isSneaking() + ", data: " + data + ", vel: " + p.getVelocity() + ", fd: " + String.format("%.5f", p.getFallDistance()),
(CheatHover) null, amount);
}
data.update(distance, distanceXZ);
}
@EventHandler
public void onClick(InventoryClickEvent e) {
if (!(e.getWhoClicked() instanceof Player) || e.getClickedInventory() == null || !e.getSlotType().equals(SlotType.CONTAINER) || e.isCancelled())
return;
SpigotNegativityPlayer np = SpigotNegativityPlayer.getNegativityPlayer((Player) e.getWhoClicked());
if (!np.hasDetectionActive(this))
return;
checkInvMove(np, (Player) e.getWhoClicked(), "Click");
}
@EventHandler
public void onOpen(InventoryOpenEvent e) {
if (!(e.getPlayer() instanceof Player) || e.isCancelled())
return;
SpigotNegativityPlayer np = SpigotNegativityPlayer.getNegativityPlayer((Player) e.getPlayer());
if (!np.hasDetectionActive(this))
return;
checkInvMove(np, (Player) e.getPlayer(), "Open");
}
@EventHandler
public void onClose(InventoryCloseEvent e) {
if (e.getPlayer() instanceof Player)
SpigotNegativityPlayer.getNegativityPlayer((Player) e.getPlayer()).inventoryMoveData.reset((Player) e.getPlayer());
}
private void checkInvMove(SpigotNegativityPlayer np, Player p, String from) {
if (np.hasElytra() || p.isInsideVehicle() || p.getLocation().getBlock().getType().name().contains("WATER"))
return;
np.inventoryMoveData.active = true;
}
@Override
public boolean isBlockedInFight() {
return true;
}
public static class InventoryMoveData {
public Player p;
public double distance = 0, distanceXZ = 0;
public int timeSinceOpen = 0;
public boolean sprint, sneak, active;
public InventoryMoveData() {
reset(null);
}
public void update(double distance, double distanceXZ) {
this.distance = distance;
this.distanceXZ = distanceXZ;
this.timeSinceOpen++;
}
public void reset(Player p) {
this.sprint = p == null ? false : p.isSprinting();
this.sneak = p == null ? false : p.isSneaking();
this.active = false;
this.distance = 0;
this.distanceXZ = 0;
this.timeSinceOpen = 0;
}
@Override
public String toString() {
return "InventoryMoveData{sprint=" + sprint + ",sneak=" + sneak + ",distance=" + String.format("%.3f", distance) + ",distanceXZ=" + String.format("%.3f", distance) + ",time="
+ timeSinceOpen + "}";
}
}
}
// NOTE (AI): Negativity's InventoryMoveProtocol arms on InventoryClickEvent/InventoryOpenEvent and scores PlayerMoveEvent deltas while the inventory is open: sprinting, sneaking, or covering distance faster than walk speed since the inventory opened accumulates the alert amount.
The canonical window-click check set: FastClick, InstantBow, Gutenberg, MoreInventory and Open, driven by inventory events and the click window packet.
A CheckListener registering the inventory checks with per-player config and data, fed from Bukkit inventory events and the ProtocolLib InventoryAdapter wrapping PacketPlayInWindowClick. FastClick limits clicks per window per second, InstantBow flags bows fired without a charging period, Gutenberg caps creative item spam, MoreInventory catches rapid item nuking, and Open limits how often windows can be reopened.
// ===== FILE: Updated-NoCheatPlus-NoCheatPlus, NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/inventory/InventoryListener.java =====
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.neatmonster.nocheatplus.checks.inventory;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityPortalEnterEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.combined.Combined;
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
import fr.neatmonster.nocheatplus.compat.bukkit.BridgeHealth;
import fr.neatmonster.nocheatplus.compat.registry.BukkitAPIAccessFactory;
import fr.neatmonster.nocheatplus.compat.BridgeMisc;
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
import fr.neatmonster.nocheatplus.components.data.ICheckData;
import fr.neatmonster.nocheatplus.components.data.IData;
import fr.neatmonster.nocheatplus.components.entity.IEntityAccessVehicle;
import fr.neatmonster.nocheatplus.components.registry.event.IGenericInstanceHandle;
import fr.neatmonster.nocheatplus.components.registry.factory.IFactoryOne;
import fr.neatmonster.nocheatplus.components.registry.feature.JoinLeaveListener;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.players.IPlayerData;
import fr.neatmonster.nocheatplus.players.PlayerFactoryArgument;
import fr.neatmonster.nocheatplus.stats.Counters;
import fr.neatmonster.nocheatplus.utilities.entity.InventoryUtil;
import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
import fr.neatmonster.nocheatplus.utilities.math.MathUtil;
import fr.neatmonster.nocheatplus.utilities.moving.MovingUtil;
import fr.neatmonster.nocheatplus.worlds.WorldFactoryArgument;
/**
* Central location to listen to events that are relevant for the inventory checks.
*
* @see InventoryEvent
*/
public class InventoryListener extends CheckListener implements JoinLeaveListener {
// Checks
/** More Inventory check */
private final MoreInventory moreInv = addCheck(new MoreInventory());
/** The fast click check. */
private final FastClick fastClick = addCheck(new FastClick());
/** The instant bow check. */
private final InstantBow instantBow = addCheck(new InstantBow());
/** The fast consume check. */
private final FastConsume fastConsume = addCheck(new FastConsume());
private final Gutenberg gutenberg = addCheck(new Gutenberg());
/** The open check */
private final Open open = addCheck(new Open());
// Other/Auxiliary stuff
private boolean keepCancel = false;
private final boolean hasInventoryAction;
/** For temporary use: LocUtil.clone before passing deeply, call setWorld(null) after use. */
private final Location useLoc = new Location(null, 0, 0, 0);
private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class);
private final int idCancelDead = counters.registerKey("cancel.dead");
private final IGenericInstanceHandle<IEntityAccessVehicle> handleVehicles = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstanceHandle(IEntityAccessVehicle.class);
@SuppressWarnings("unchecked")
public InventoryListener() {
super(CheckType.INVENTORY);
final NoCheatPlusAPI api = NCPAPIProvider.getNoCheatPlusAPI();
api.register(api.newRegistrationContext()
// InventoryConfig
.registerConfigWorld(InventoryConfig.class)
.factory(new IFactoryOne<WorldFactoryArgument, InventoryConfig>() {
@Override
public InventoryConfig getNewInstance(
WorldFactoryArgument arg) {
return new InventoryConfig(arg.worldData);
}
})
.registerConfigTypesPlayer()
.context() //
// InventoryData
.registerDataPlayer(InventoryData.class)
.factory(new IFactoryOne<PlayerFactoryArgument, InventoryData>() {
@Override
public InventoryData getNewInstance(
PlayerFactoryArgument arg) {
return new InventoryData();
}
})
.addToGroups(CheckType.INVENTORY, true, IData.class, ICheckData.class)
.context() //
);
hasInventoryAction = ReflectionUtil.getClass("org.bukkit.event.inventory.InventoryAction") != null;
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onEntityShootBow(final EntityShootBowEvent event) {
// Only if a player shot the arrow.
if (event.getEntity() instanceof Player) {
final Player player = (Player) event.getEntity();
final IPlayerData pData = DataManager.getPlayerData(player);
if (instantBow.isEnabled(player, pData)) {
final long now = System.currentTimeMillis();
final Location loc = player.getLocation(useLoc);
if (Combined.checkYawRate(player, loc.getYaw(), now, loc.getWorld().getName(), pData)) {
// No else if with this, could be cancelled due to other checks feeding, does not have actions.
event.setCancelled(true);
}
final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
// Still check instantBow, whatever yawrate says.
if (instantBow.check(player, event.getForce(), now)) {
event.setCancelled(true);
}
else if (cc.instantBowImprobableWeight > 0.0f) {
if (cc.instantBowImprobableFeedOnly) {
Improbable.feed(player, cc.instantBowImprobableWeight, now);
}
else if (Improbable.check(player, cc.instantBowImprobableWeight, now, "inventory.instantbow", pData)) {
// Combined fighting speed (Else if: Matter of taste, preventing extreme cascading and actions spam).
event.setCancelled(true);
}
}
useLoc.setWorld(null);
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onFoodLevelChange(final FoodLevelChangeEvent event) {
// Only if a player ate food.
if (event.getEntity() instanceof Player) {
final Player player = (Player) event.getEntity();
if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
// Eat after death.
event.setCancelled(true);
counters.addPrimaryThread(idCancelDead, 1);
}
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(final InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player)) {
return;
}
final long now = System.currentTimeMillis();
final HumanEntity entity = event.getWhoClicked();
if (!(entity instanceof Player)) {
return;
}
final Player player = (Player) entity;
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
final int slot = event.getSlot();
final String inventoryAction = hasInventoryAction ? event.getAction().name() : null;
final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
if (pData.isDebugActive(checkType)) {
outputDebugInventoryClick(player, slot, event, inventoryAction);
}
// Set this one as soon as we can and regardless if the click was cancelled or not.
if (data.inventoryOpenTime == 0) {
data.inventoryOpenTime = now;
if (pData.isDebugActive(CheckType.INVENTORY)) {
debug(player, "InventoryClickEvent: inventory wasn't explicitly open previously but an inventory click was sent; register time of the 1st click (assume inventory is open from this moment on)");
}
}
if (event.isCancelled()) {
// Previously: ignoreCancelled = true
// We still want to know if the player clicked in the inventory (even if cancelled) for the inventory-open estimate above.
return;
}
if (slot == -999 || slot < 0) {
// Set and return, not interested in these clicks.
data.lastClickTime = now;
return;
}
final ItemStack cursor = event.getCursor();
final ItemStack clicked = event.getCurrentItem();
boolean cancel = false;
// Fast inventory manipulation check.
if (fastClick.isEnabled(player, pData)) {
if (!((event.getInventory().getType().equals(InventoryType.CREATIVE) || player.getGameMode() == GameMode.CREATIVE) && cc.fastClickSpareCreative)) {
boolean check = true;
try {
// Exempted inventories are not checked.
check = !cc.inventoryExemptions.contains(ChatColor.stripColor(BukkitAPIAccessFactory.getBukkitAccess().getInventoryTitle(event)));
}
catch (IllegalStateException e) {
// Uhm... Can this ISE be fixed?
check = true;
}
if (check) {
// Check for too quick interactions first (we don't need to check for fast clicking if the interaction is inhumanly fast)
if (InventoryUtil.isContainerInventory(event.getInventory().getType())
&& fastClick.checkContainerInteraction(player, data, cc)) {
cancel = true;
keepCancel = true;
}
// Then check for too fast inventory clicking
if (!cancel && fastClick.check(player, now, event, slot, cursor, clicked, event.isShiftClick(), inventoryAction, data, cc, pData)) {
cancel = true;
}
}
}
}
data.lastClickTime = now;
data.clickedSlotType = event.getSlotType();
// Cancel the event.
if (cancel || keepCancel) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEditingABook(final PlayerEditBookEvent event) {
final Player player = event.getPlayer();
if (!gutenberg.isEnabled(player)) {
return;
}
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
final BookMeta newMeta = event.getNewBookMeta();
final int pages = newMeta.getPageCount();
if (gutenberg.check(player, data, pData, pages)) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onConsumingFoodOrPotions(final PlayerItemConsumeEvent event){
final Player player = event.getPlayer();
if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
// Eat after death.
event.setCancelled(true);
counters.addPrimaryThread(idCancelDead, 1);
return;
}
final IPlayerData pData = DataManager.getPlayerData(player);
if (!fastConsume.isEnabled(player)) {
return;
}
final InventoryData data = pData.getGenericInstance(InventoryData.class);
final long time = System.currentTimeMillis();
if (fastConsume.check(player, event.getItem(), time, data, pData)) {
event.setCancelled(true);
DataManager.getPlayerData(player).requestUpdateInventory();
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onClosingAnyInventory(final InventoryCloseEvent event) {
// NOTE: ignoreCancelled is kept to true here. Cancelled events won't reset data.
// NOTE: Priority level -> same as opening time.
final HumanEntity entity = event.getPlayer();
if (entity instanceof Player) {
final Player player = (Player) entity;
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
data.inventoryOpenTime = 0;
data.containerInteractTime = 0;
if (pData.isDebugActive(CheckType.INVENTORY)) {
debug(player, "InventoryCloseEvent: reset timing data.");
}
}
keepCancel = false;
}
@EventHandler(priority = EventPriority.LOWEST)
public final void onPlayerInteract(final PlayerInteractEvent event) {
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
final CombinedData cData = pData.getGenericInstance(CombinedData.class);
// Set the container opening time.
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null
// Sneaking and right clicking with a block in hand will cause the player to place the block down, not to open the container.
&& !(BridgeMisc.isUsingItem(player) || pData.isShiftKeyPressed() && event.isBlockInHand())) {
if (BlockProperties.isContainer(event.getClickedBlock().getType())) {
data.containerInteractTime = System.currentTimeMillis();
if (pData.isDebugActive(CheckType.INVENTORY)) {
debug(player, "Interacted with a container: register the interaction time.");
}
}
}
// Only interested in right-clicks while holding an item.
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
boolean resetAll = false;
if (event.hasItem()) {
final ItemStack item = event.getItem();
final Material type = item.getType();
// TODO: Get Magic values (800) from the config.
// TODO: Cancelled / deny use item -> reset all?
if (type == Material.BOW) {
final long now = System.currentTimeMillis();
// It was a bow, the player starts to pull the string, remember this time.
data.instantBowInteract = (data.instantBowInteract > 0 && now - data.instantBowInteract < 800) ? Math.min(System.currentTimeMillis(), data.instantBowInteract) : System.currentTimeMillis();
}
else if (InventoryUtil.isConsumable(type)) {
final long now = System.currentTimeMillis();
// It was food, the player starts to eat some food, remember this time and the type of food.
data.fastConsumeFood = type;
data.fastConsumeInteract = (data.fastConsumeInteract > 0 && now - data.fastConsumeInteract < 800) ? Math.min(System.currentTimeMillis(), data.fastConsumeInteract) : System.currentTimeMillis();
data.instantBowInteract = 0;
}
else resetAll = true;
}
else resetAll = true;
if (resetAll) {
// Nothing that we are interested in, reset data.
data.instantBowInteract = 0;
data.fastConsumeInteract = 0;
data.fastConsumeFood = null;
}
}
// TODO: Why is this handler inside the INVENTORY listener!?
@EventHandler(priority = EventPriority.LOWEST)
public final void onPlayerInteractEntity(final PlayerInteractEntityEvent event) {
final Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE || !DataManager.getPlayerData(player).isCheckActive(CheckType.INVENTORY, player)) {
return;
}
if (player.isDead() && BridgeHealth.getHealth(player) <= 0.0) {
// No zombies.
event.setCancelled(true);
counters.addPrimaryThread(idCancelDead, 1);
return;
}
else if (MovingUtil.hasScheduledPlayerSetBack(player)) {
event.setCancelled(true);
return;
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public final void onContainerOpen(final InventoryOpenEvent event) {
// Possibly already prevented by block + entity interaction.
// NOTE: ignoreCancelled is kept true. Denied openings won't register timing data.
final long now = System.currentTimeMillis();
final HumanEntity entity = event.getPlayer();
if (entity instanceof Player) {
final Player player = (Player) entity;
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
if (MovingUtil.hasScheduledPlayerSetBack(player)) {
// Don't allow players to open inventories on set-backs.
event.setCancelled(true);
data.inventoryOpenTime = 0; // Just to be sure
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(player, "InventoryOpenEvent: attempted to open a container during set back processing; reset timing data and prevent opening.");
}
}
else if (data.inventoryOpenTime == 0) {
// Only set the inventory opening time, if a setback is not scheduled.
data.inventoryOpenTime = now;
if (pData.isDebugActive(CheckType.INVENTORY)) {
debug(player, "Fired an explicit InventoryOpenEvent; inventory is now open (no assumptions): register time.");
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onItemHeldChange(final PlayerItemHeldEvent event) {
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
if (pData.isDebugActive(checkType) && data.fastConsumeFood != null) {
debug(player, "PlayerItemHeldEvent, reset fastconsume.");
}
data.instantBowInteract = 0;
data.fastConsumeInteract = System.currentTimeMillis();
data.fastConsumeFood = null;
if (event.getPreviousSlot() != event.getNewSlot()) {
if (open.check(player)) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(player, "Force-close inventory on changing slots.");
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) {
// Data is reset regardless of cancellation state (better safe than sorry)
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
if (open.check(event.getPlayer())) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(player, "Force-close inventory on changing worlds.");
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onBreakingBlocks(final BlockBreakEvent event) {
final Player player = event.getPlayer();
final IPlayerData pData = DataManager.getPlayerData(player);
// Can't break blocks with inventory open.
if (open.check(event.getPlayer())) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(player, "Force-close inventory on breaking blocks (cheat prevention).");
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlacingBlocks(final BlockPlaceEvent event) {
final IPlayerData pData = DataManager.getPlayerData(event.getPlayer());
// Can't place blocks with inventory open.
if (open.check(event.getPlayer())) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(event.getPlayer(), "Force-close inventory on placing blocks (cheat prevention).");
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerPortal(final PlayerPortalEvent event) {
// Note: ignore cancelother setting.
final IPlayerData pData = DataManager.getPlayerData(event.getPlayer());
if (open.check(event.getPlayer())) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(event.getPlayer(), "Force-close inventory on using a portal.");
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerRespawn(final PlayerRespawnEvent event) {
// NOTE: Data is reset regardless of cancellation state (better safe than sorry)
final IPlayerData pData = DataManager.getPlayerData(event.getPlayer());
if (open.check(event.getPlayer())) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(event.getPlayer(), "Force-close inventory on respawning.");
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(final EntityDeathEvent event) {
// NOTE: Data is reset regardless of cancellation state (better safe than sorry)
final LivingEntity entity = event.getEntity();
if (entity instanceof Player) {
final Player player = (Player) entity;
final IPlayerData pData = DataManager.getPlayerData(player);
if (open.check(player)) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(player, "Force-close inventory on death.");
}
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerSleep(final PlayerBedEnterEvent event) {
final IPlayerData pData = DataManager.getPlayerData(event.getPlayer());
if (open.check(event.getPlayer())) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(event.getPlayer(), "Force-close inventory on sleeping.");
}
}
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerWake(final PlayerBedLeaveEvent event) {
final IPlayerData pData = DataManager.getPlayerData(event.getPlayer());
if (open.check(event.getPlayer())) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(event.getPlayer(), "Force-close inventory on waking up.");
}
}
}
// Check even if cancelled
// (Players swing their arm when dropping items.)
// @EventHandler(priority = EventPriority.MONITOR)
// public void onSwingingArm(final PlayerAnimationEvent event) {
// final IPlayerData pData = DataManager.getPlayerData(event.getPlayer());
// if (open.check(event.getPlayer())) {
// if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
// debug(event.getPlayer(), "Force-close inventory on swinging arm (cheat prevention).");
// }
// }
// }
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onEntityPortal(final EntityPortalEnterEvent event) {
// Check passengers flat for now.
final Entity entity = event.getEntity();
if (entity instanceof Player) {
final IPlayerData pData = DataManager.getPlayerData((Player) entity);
if (open.check((Player) entity)) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug((Player) entity, "Force-close inventory on using a portal (entity).");
}
}
}
else {
for (final Entity passenger : handleVehicles.getHandle().getEntityPassengers(entity)) {
if (passenger instanceof Player) {
final IPlayerData pData = DataManager.getPlayerData((Player) entity);
if (open.check((Player) passenger)) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug((Player) passenger, "Force-close inventory of passenger on using a portal, passenger: " + passenger.toString());
}
}
}
}
}
}
/** Event priority must be set to priority used for moving checks due using moving data from there */
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerMove(final PlayerMoveEvent event) {
final Location from = event.getFrom();
final Location to = event.getTo();
final boolean PoYdiff = from.getPitch() != to.getPitch() || from.getYaw() != to.getYaw();
final IPlayerData pData = DataManager.getPlayerData(event.getPlayer());
if (MovingUtil.hasScheduledPlayerSetBack(event.getPlayer())) {
// On 1.8 set back technique is different, as we do not cancel the event.
return;
}
final CombinedData cData = pData.getGenericInstance(CombinedData.class);
final InventoryConfig cc = pData.getGenericInstance(InventoryConfig.class);
final Inventory inv = BukkitAPIAccessFactory.getBukkitAccess().getTopInventory(event.getPlayer());
boolean moreInvCheck = false;
if (moreInv.isEnabled(event.getPlayer(), pData)
&& moreInv.check(event.getPlayer(), cData, pData, inv.getType(), inv, PoYdiff)) {
for (int i = 1; i <= 4; i++) {
final ItemStack item = inv.getItem(i);
// Ensure air-clicking is not detected... :)
if (item != null && !BlockProperties.isAir(item.getType())) {
// NOTE: dropItemsNaturally does not fire InvDrop events, so don't use it here. Simply close the inventory,
event.getPlayer().closeInventory(); // Do not call Open.checkClose() here, as it checks for if the inventory is open again, and we're not interested in that.
if (pData.isDebugActive(CheckType.INVENTORY_MOREINVENTORY)) {
debug(event.getPlayer(), "On PlayerMoveEvent: force-close inventory on MoreInv detection.");
}
moreInvCheck = true;
break;
}
}
}
if (moreInvCheck) {
// Already closed inventory; no need to also check for open-on-move.
return;
}
// Determine if the inventory should be closed.
if (cc.openCancelOnMove && !pData.hasBypass(CheckType.INVENTORY_OPEN, event.getPlayer())) {
if (InventoryUtil.hasInventoryOpen(event.getPlayer()) && open.checkOnMove(event.getPlayer(), pData)) {
event.getPlayer().closeInventory(); // Do not call open.check() here. <- Uhm... Why did I write this note?
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(event.getPlayer(), "Player is actively moving: force-close open inventory.");
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleport(final PlayerTeleportEvent event) {
// NOTE: Data is reset regardless of cancellation state (better safe than sorry)
final IPlayerData pData = DataManager.getPlayerData(event.getPlayer());
if (open.check(event.getPlayer())) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(event.getPlayer(), "Force-close inventory on teleporting.");
}
}
}
@Override
public void playerJoins(Player player) {
// Just to be sure...
final IPlayerData pData = DataManager.getPlayerData(player);
final InventoryData data = pData.getGenericInstance(InventoryData.class);
data.inventoryOpenTime = 0;
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(player, "Reset inventory timings data on join.");
}
}
@Override
public void playerLeaves(Player player) {
final IPlayerData pData = DataManager.getPlayerData(player);
if (open.check(player)) {
if (pData.isDebugActive(CheckType.INVENTORY_OPEN)) {
debug(player, "Force-close inventory on leaving the server.");
}
}
}
/**
* Debug inventory classes. Contains information about classes, to indicate
* if cross-plugin compatibility issues can be dealt with easily.
*
* @param player
* @param slot
* @param event
*/
private void outputDebugInventoryClick(final Player player, final int slot, final InventoryClickEvent event,
final String action) {
// TODO: Consider only logging where different from expected (CraftXY, more/other viewer than player).
final StringBuilder builder = new StringBuilder(512);
final InventoryData data = DataManager.getPlayerData(player).getGenericInstance(InventoryData.class);
builder.append("Inventory click: slot: " + slot);
builder.append(" , Inventory has been opened for: " + MathUtil.toSeconds(System.currentTimeMillis() - data.inventoryOpenTime) + " secs");
builder.append(" , Time between inventory click and last interaction time: " + MathUtil.toSeconds(data.lastClickTime - data.containerInteractTime) + " secs");
// Viewers.
builder.append(" , Viewers: ");
for (final HumanEntity entity : event.getViewers()) {
builder.append(entity.getName());
builder.append("(");
builder.append(entity.getClass().getName());
builder.append(")");
}
// Inventory view.
builder.append(" , View: ");
//final InventoryView view = BridgeBukkitAPI.getInventoryView(event);
//builder.append(view.getClass().getName());
// Bottom inventory.
addInventory(BukkitAPIAccessFactory.getBukkitAccess().getBottomInventory(event), BukkitAPIAccessFactory.getBukkitAccess().getInventoryTitle(event), " , Bottom: ", builder);
// Top inventory.
addInventory(BukkitAPIAccessFactory.getBukkitAccess().getTopInventory(event), BukkitAPIAccessFactory.getBukkitAccess().getInventoryTitle(event), " , Top: ", builder);
if (action != null) {
builder.append(" , Action: ");
builder.append(action);
}
// Event class.
builder.append(" , Event: ");
builder.append(event.getClass().getName());
// Log debug.
debug(player, builder.toString());
}
private void addInventory(final Inventory inventory, final String name, final String prefix, final StringBuilder builder) {
builder.append(prefix);
if (inventory == null) {
builder.append("(none)");
}
else {
builder.append(name);
builder.append("/");
builder.append(inventory.getClass().getName());
}
}
}
// NOTE (AI): NCP's InventoryListener is the canonical window-click handler: it drives FastClick (click speed), InstantBow (bow drawn without charging), Gutenberg (creative item spam), MoreInventory (nuking with items) and Open (close/open cycle rate) from inventory events fed by the ProtocolLib InventoryAdapter.
Related Packets
Wiki Cross-Reference
The server ignores any click targeting a window ID other than the currently open one, including window 0 while another window is open. Right-clicking an odd-sized stack picks up half and leaves the smaller half in the slot, and the mode and button fields jointly encode left, right, shift-click, number-key, drop-key, drag-painting and double-click operations with slot -999 meaning outside the window.
MCP 1.8.9 C0EPacketClickWindow implements Packet
1.8.9 callers: PlayerControllerMP.windowClick sends new C0EPacketClickWindow (line 538): https://github.com/Marcelektro/MavenMCP-1.8.9/blob/master/src/main/java/net/minecraft/client/multiplayer/PlayerControllerMP.java
Cross-checked against minecraft.wiki (CC BY-SA 3.0) for 1.8.9 accuracy.
Vanilla Internals
Full 1.8.9 logic-class sources that send or handle this packet, stored verbatim.
Module Analyses Using C0EPacketClickWindow
Full source walkthroughs of the modules and anti-cheats that use this packet.