0x2E S2EPacketCloseWindow
Server forces the client to close an inventory window.
Published 2026-06-18 · Updated 2026-10-14
Fields
| Field | Type | Description |
|---|---|---|
| windowId | byte | Window ID |
Wire Encoding
| Field | Type | Notes |
|---|---|---|
| Window ID | unsigned byte |
MCP References
NetHandlerPlayClient.handleCloseWindow()Handler Interface
INetHandlerPlayClientVanilla 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 | |
Deobfuscated MCP 1.8.9 source of S2EPacketCloseWindow, fetched directly from Marcelektro/MavenMCP-1.8.9 (net/minecraft/network/play/server/S2EPacketCloseWindow.java) at build time and verified present.
Deep Dive
Role in the protocol
Server-initiated window close. It carries a single unsigned byte windowId and tells the client to tear down the open container and re-sync the held item. Server-side, EntityPlayerMP.closeScreen sends it when the server decides the player's window must close, which happens on death, teleport, dimension change, and anti-cheat interventions. The client counterpart C0DPacketCloseWindow is the player-initiated echo; the S2E path is always server-driven.
Vanilla handling
NetHandlerPlayClient.handleCloseWindow calls thePlayer.func_175159_q(), which resets the carried item and closes the current screen. It does not check the windowId against the open container: any S2E closes whatever GUI is up. Server-side, EntityPlayerMP.closeScreen sends S2E with openContainer.windowId and closes the container. The asymmetry is the hook: a server can yank any GUI, and the client obeys blindly.
Why clients touch it
Two module families. NoGuiClose in Rise 5.99, 6.1.30 and 6.2.4 cancels S2E so servers cannot close the player's GUI; Rise 5.99 defaults the Chat Only setting on, meaning the cancel only applies while the chat screen is open, which preserves the ability to type while a container stays open. Rise 6.2.4 defaults it off, blocking every server close. LiquidSense Dev's KeepContainer uses S2E in the opposite direction: it reads the server's close to drop its cached container reference, and it cancels the client's own C0D close packets while the keep is armed. The other six clients (Memeware, Nekoware, Sigma, Spicy, Tenacity, November Recode 2.0) have no S2E module reference at all.
Exploit surface
The unguarded close is the surface: servers close windows to interrupt chest-stealing macros and inventory manipulation, and NoGuiClose defeats that by holding the GUI open. The cost is protocol desync: the server has closed its container while the client still shows it, so later clicks (C0E) reference a dead window. This is safe only while the player does not actually interact; the Chat Only mode exists precisely to limit the desync window to chat-while-looting use. Vanilla's failure to validate windowId on S2E also means a server can send a mismatched id to force-close anything.
Server-Side Handling
EntityPlayerMP.closeScreen sends S2E with the current openContainer.windowId, then closes the server-side container and re-syncs the held item. NetHandlerPlayClient.handleCloseWindow runs func_175159_q() unconditionally: it resets the carried item and closes whatever screen is active, ignoring the packet's windowId entirely. Because the client never validates the id, the packet is a blind close lever from the server's perspective.
Protocol Analysis
Encoding: single unsigned byte windowId. It is one of the smallest packets in the play state. The client handler performs no id comparison against openContainer.windowId, which is the load-bearing detail for NoGuiClose: cancelling the packet has no side effects beyond keeping the GUI open. The windowId matters only for server bookkeeping, since the client close path is unconditional.
Anti-Cheat Landscape
Anti-cheats flag the desync NoGuiClose creates: a window the server closed but the client keeps open will eventually produce clicks (C0E) against a dead windowId, which window-state checks flag as inventory manipulation. The Chat Only default in Rise 5.99 keeps the desync window small (chat open while looting); blocking every S2E (6.2.4 default) widens it and increases the flag surface. This is a utility module with a real anti-cheat cost, unlike the purely cosmetic filters elsewhere in this group.
implementation Implementation Cases
The server-driven window close. Rise ships NoGuiClose in all three releases to cancel S2E and hold the GUI open, with a Chat Only mode in 5.99 to limit the desync. LiquidSense Dev's KeepContainer listens to S2E to invalidate its cached container when the server closes it. The other six clients never touch the packet outside vanilla.
Cancel server window-close packets so the player's GUI cannot be yanked away.
A PacketReceiveEvent handler cancels any S2E, gated by a Chat Only setting: when enabled, the cancel only fires while mc.currentScreen is a GuiChat. Rise 5.99 defaults Chat Only to true (onPacketReceive + event.setCancelled), Rise 6.2.4 defaults its chatonly value to false (Listener with event.setCancelled).
// ===== FILE: Rise 5.99, dev/rise/module/impl/other/NoGuiClose.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.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.client.gui.GuiChat;
import net.minecraft.network.play.server.S2EPacketCloseWindow;
@ModuleInfo(name = "NoGuiClose", description = "Prevents servers from closing opened Guis", category = Category.OTHER)
public final class NoGuiClose extends Module {
private final BooleanSetting chatOnly = new BooleanSetting("Chat Only", this, true);
@Override
public void onPacketReceive(final PacketReceiveEvent event) {
if (event.getPacket() instanceof S2EPacketCloseWindow && (mc.currentScreen instanceof GuiChat || !chatOnly.isEnabled()))
event.setCancelled(true);
}
}
// NOTE (AI): The whole module is the single onPacketReceive guard. The chatOnly setting defaults to true in 5.99, limiting the cancel to chat-open moments; 6.2.4 inverts the default to false.Keep a formerly opened inventory container accessible anywhere: re-open it with the INSERT key and suppress close packets while armed.
Stores the last non-inventory GuiContainer on ScreenEvent; pressing INSERT re-opens it via displayGuiScreen. On PacketEvent it cancels every C0DPacketCloseWindow and, for S2EPacketCloseWindow, clears the cached container when the packet's windowId matches the stored container, so the cache cannot be resurrected after the server closed it. Disabling the module sends the C0D close it had been suppressing.
// ===== FILE: LiquidSense Dev, net/ccbluex/liquidbounce/features/module/modules/exploit/KeepContainer.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.features.module.modules.exploit;
import net.ccbluex.liquidbounce.event.EventTarget;
import net.ccbluex.liquidbounce.event.KeyEvent;
import net.ccbluex.liquidbounce.event.PacketEvent;
import net.ccbluex.liquidbounce.event.ScreenEvent;
import net.ccbluex.liquidbounce.features.module.Module;
import net.ccbluex.liquidbounce.features.module.ModuleCategory;
import net.ccbluex.liquidbounce.features.module.ModuleInfo;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.network.play.client.C0DPacketCloseWindow;
import net.minecraft.network.play.server.S2EPacketCloseWindow;
import org.lwjgl.input.Keyboard;
@ModuleInfo(name = "KeepContainer", description = "Allows you to open a formerly closed inventory container everywhere. (Press INSERT Key to open)", category = ModuleCategory.EXPLOIT)
public class KeepContainer extends Module {
private GuiContainer container;
@Override
public void onDisable() {
if(container != null)
mc.getNetHandler().addToSendQueue(new C0DPacketCloseWindow(container.inventorySlots.windowId));
container = null;
}
@EventTarget
public void onGui(final ScreenEvent event) {
if(event.getGuiScreen() instanceof GuiContainer && !(event.getGuiScreen() instanceof GuiInventory))
container = (GuiContainer) event.getGuiScreen();
}
@EventTarget
public void onKey(final KeyEvent event) {
if(event.getKey() == Keyboard.KEY_INSERT) {
if(container == null)
return;
mc.displayGuiScreen(container);
}
}
@EventTarget
public void onPacket(final PacketEvent event) {
if(event.getPacket() instanceof C0DPacketCloseWindow)
event.cancelEvent();
if(event.getPacket() instanceof S2EPacketCloseWindow) {
final S2EPacketCloseWindow packetCloseWindow = (S2EPacketCloseWindow) event.getPacket();
if(container != null && container.inventorySlots != null && packetCloseWindow.windowId == container.inventorySlots.windowId)
container = null;
}
}
}
// NOTE (AI): The S2E branch is defensive bookkeeping: it keeps the cached GuiContainer from outliving the server's close. The C0D cancel is the actual exploit surface, and the disable path flushes the suppressed close.anticheat Anti-Cheat Checks
The server-close packet is consumed on the send side to reset simulated window state. Grim's CompensatedInventory closes the emulated inventory transaction-ordered after the S2E, and Artemis transaction-confirms the close to clear its inventory-open flag. Both anticheats do this so that later C0E clicks against the closed window are recognized as invalid. Intave and the classic repos only handle the client-side close (C0D) and are therefore not part of this packet's story.
Reset the emulated open window when the server closes it, so clicks against a closed window are flagged.
A send-side handler matches PacketType.Play.Server.CLOSE_WINDOW and schedules closeActiveInventory as a real-time task ordered after the last transaction; the reset restores isPacketInventoryActive, sets openWindowID back to 0, swaps the menu back to the player inventory and clears the carried item. Clicks that follow with the old window id no longer match openWindowID.
// ===== FILE: GrimAnticheat-Grim, common/src/main/java/ac/grim/grimac/utils/latency/CompensatedInventory.java =====
package ac.grim.grimac.utils.latency;
import ac.grim.grimac.checks.Check;
import ac.grim.grimac.checks.type.PacketReceiveListener;
import ac.grim.grimac.checks.type.PacketSendListener;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.anticheat.update.BlockPlace;
import ac.grim.grimac.utils.inventory.EquipmentType;
import ac.grim.grimac.utils.inventory.Inventory;
import ac.grim.grimac.utils.inventory.inventory.AbstractContainerMenu;
import ac.grim.grimac.utils.inventory.inventory.MenuType;
import ac.grim.grimac.utils.inventory.inventory.NotImplementedMenu;
import ac.grim.grimac.utils.lists.CorrectingPlayerInventoryStorage;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.item.ItemStack;
import com.github.retrooper.packetevents.protocol.item.type.ItemType;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.DiggingAction;
import com.github.retrooper.packetevents.protocol.player.GameMode;
import com.github.retrooper.packetevents.protocol.player.InteractionHand;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientClickWindow;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientCreativeInventoryAction;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientHeldItemChange;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerDigging;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientUseItem;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerOpenHorseWindow;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerOpenWindow;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetPlayerInventory;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetSlot;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerWindowItems;
import lombok.Getter;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
// Updated to support modern 1.17 protocol
public class CompensatedInventory extends Check implements PacketReceiveListener, PacketSendListener {
private static final int PLAYER_INVENTORY_CASE = -1;
private static final int UNSUPPORTED_INVENTORY_CASE = -2;
// "Temporarily" public for debugging
public final Inventory inventory;
// "Temporarily" public for debugging
public AbstractContainerMenu menu;
// Not all inventories are supported due to complexity and version differences
public boolean isPacketInventoryActive = true;
public boolean needResend = false;
public int stateID = 0; // Don't mess up the last sent state ID by changing it
private int openWindowID = 0;
// Special values:
// Player inventory is -1
// Unsupported inventory is -2
private int packetSendingInventorySize = PLAYER_INVENTORY_CASE;
// The item held at the start of the current client tick (processed at the end of the previous tick)
// also updated before slot changes to account for the delay when using hotbar keybinds
// Currently only used by 1.21.11+ players to handle attribute swapping items with the ATTACK_RANGE Component
@Getter
private ItemStack startOfTickStack = ItemStack.EMPTY;
public CompensatedInventory(GrimPlayer playerData) {
super(playerData);
CorrectingPlayerInventoryStorage storage = new CorrectingPlayerInventoryStorage(player, 46);
inventory = new Inventory(playerData, storage);
menu = inventory;
}
// Meant for 1.17+ clients who send changed slots, making the server not send the entire inventory
private void markPlayerSlotAsChanged(int clicked) {
// Player inventory
if (openWindowID == 0) {
inventory.getInventoryStorage().handleClientClaimedSlotSet(clicked);
return;
}
// We don't know size of the inventory, so we can't do anything
// We will resync later.
if (menu instanceof NotImplementedMenu) return;
// 9-45 are the player inventory slots that are used
// There are 36 player slots in each menu that we care about and track.
int nonPlayerInvSize = menu.getSlots().size() - 36 + 9;
int playerInvSlotclicked = clicked - nonPlayerInvSize;
// Bypass player inventory
inventory.getInventoryStorage().handleClientClaimedSlotSet(playerInvSlotclicked);
}
public ItemStack getItemInHand(InteractionHand hand) {
return hand == InteractionHand.MAIN_HAND ? getHeldItem() : getOffHand();
}
/**
* Marks that the server has updated a slot by the specified ID in the specified inventory ID.
* @param clicked the updated slot
* @param windowID the inventory ID
*/
private void markServerForChangingSlot(int clicked, int windowID) {
// Unsupported inventory
if (packetSendingInventorySize == UNSUPPORTED_INVENTORY_CASE) return;
// Player inventory
if (packetSendingInventorySize == PLAYER_INVENTORY_CASE || windowID == 0) {
// Result slot isn't included in storage, we must ignore it
inventory.getInventoryStorage().handleServerCorrectSlot(clicked);
return;
}
// See note in above method.
int nonPlayerInvSize = menu.getSlots().size() - 36 + 9;
int playerInvSlotclicked = clicked - nonPlayerInvSize;
inventory.getInventoryStorage().handleServerCorrectSlot(playerInvSlotclicked);
}
public ItemStack getHeldItem() {
ItemStack item = isPacketInventoryActive || player.platformPlayer == null ? inventory.getHeldItem() :
player.platformPlayer.getInventory().getItemInHand();
return item == null ? ItemStack.EMPTY : item;
}
public ItemStack getOffHand() {
if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_9))
return ItemStack.EMPTY;
ItemStack item = isPacketInventoryActive || player.platformPlayer == null ? inventory.getOffhand() :
player.platformPlayer.getInventory().getItemInOffHand();
return item == null ? ItemStack.EMPTY : item;
}
public ItemStack getHelmet() {
ItemStack item = isPacketInventoryActive || player.platformPlayer == null ? inventory.getHelmet() :
player.platformPlayer.getInventory().getHelmet();
return item == null ? ItemStack.EMPTY : item;
}
public ItemStack getChestplate() {
ItemStack item = isPacketInventoryActive || player.platformPlayer == null ? inventory.getChestplate() :
player.platformPlayer.getInventory().getChestplate();
return item == null ? ItemStack.EMPTY : item;
}
public ItemStack getLeggings() {
ItemStack item = isPacketInventoryActive || player.platformPlayer == null ? inventory.getLeggings() :
player.platformPlayer.getInventory().getLeggings();
return item == null ? ItemStack.EMPTY : item;
}
public ItemStack getBoots() {
ItemStack item = isPacketInventoryActive || player.platformPlayer == null ? inventory.getBoots() :
player.platformPlayer.getInventory().getBoots();
return item == null ? ItemStack.EMPTY : item;
}
private ItemStack getByEquipmentType(EquipmentType type) {
return switch (type) {
case HEAD -> getHelmet();
case CHEST -> getChestplate();
case LEGS -> getLeggings();
case FEET -> getBoots();
case OFFHAND -> getOffHand();
case MAINHAND -> getHeldItem();
};
}
public boolean hasItemType(ItemType type) {
if (isPacketInventoryActive || player.platformPlayer == null)
return inventory.hasItemType(type);
// Fall back to platform inventories
for (ItemStack itemStack : player.platformPlayer.getInventory().getContents()) {
if (itemStack != null && itemStack.getType() == type) return true;
}
return false;
}
@Override
public void onPacketReceive(final PacketReceiveEvent event) {
if (event.getPacketType() == PacketType.Play.Client.USE_ITEM) {
WrapperPlayClientUseItem item = new WrapperPlayClientUseItem(event);
ItemStack use = item.getHand() == InteractionHand.MAIN_HAND ? getHeldItem() : getOffHand();
EquipmentType equipmentType = EquipmentType.getEquipmentSlotForItem(use);
if (equipmentType != null) {
int slot;
switch (equipmentType) {
case HEAD -> slot = Inventory.SLOT_HELMET;
case CHEST -> slot = Inventory.SLOT_CHESTPLATE;
case LEGS -> slot = Inventory.SLOT_LEGGINGS;
case FEET -> slot = Inventory.SLOT_BOOTS;
default -> {
return; // Not armor, therefore we shouldn't run this code
}
}
ItemStack currentEquippedItem = getByEquipmentType(equipmentType);
// Only 1.19.4+ clients support swapping with non-empty items
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_19_4) && !currentEquippedItem.isEmpty())
return;
// 1.19.4+ clients support swapping with non-empty items
int swapItemSlot = item.getHand() == InteractionHand.MAIN_HAND ? inventory.getSelected() + Inventory.HOTBAR_OFFSET : Inventory.SLOT_OFFHAND;
// Mojang implemented this stupidly, I rewrote their item swap code to make it somewhat cleaner.
// Slot in hotbar
inventory.getInventoryStorage().handleClientClaimedSlotSet(swapItemSlot);
inventory.getInventoryStorage().setItem(swapItemSlot, currentEquippedItem);
// Equipment slot
inventory.getInventoryStorage().handleClientClaimedSlotSet(slot);
inventory.getInventoryStorage().setItem(slot, use);
}
} else if (event.getPacketType() == PacketType.Play.Client.PLAYER_DIGGING) {
WrapperPlayClientPlayerDigging dig = new WrapperPlayClientPlayerDigging(event);
// 1.8 clients don't predict dropping items
if (player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_8)) return;
if (dig.getAction() == DiggingAction.DROP_ITEM) {
ItemStack heldItem = getHeldItem();
if (heldItem != null) {
heldItem.setAmount(heldItem.getAmount() - 1);
if (heldItem.getAmount() <= 0) {
heldItem = null;
}
}
inventory.setHeldItem(heldItem);
inventory.getInventoryStorage().handleClientClaimedSlotSet(Inventory.HOTBAR_OFFSET + player.packetStateData.lastSlotSelected);
}
if (dig.getAction() == DiggingAction.DROP_ITEM_STACK) {
inventory.setHeldItem(null);
inventory.getInventoryStorage().handleClientClaimedSlotSet(Inventory.HOTBAR_OFFSET + player.packetStateData.lastSlotSelected);
}
} else if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_CHANGE) {
final int slot = new WrapperPlayClientHeldItemChange(event).getSlot();
// Stop people from spamming the server with an out-of-bounds exception
if (slot > 8 || slot < 0) return;
// set this before we change the selected slot so we get the previous item held
this.startOfTickStack = getHeldItem();
inventory.setSelected(slot);
} else if (event.getPacketType() == PacketType.Play.Client.CREATIVE_INVENTORY_ACTION) {
WrapperPlayClientCreativeInventoryAction action = new WrapperPlayClientCreativeInventoryAction(event);
if (player.gamemode != GameMode.CREATIVE) return;
boolean valid = action.getSlot() >= 1 &&
(PacketEvents.getAPI().getServerManager().getVersion().isNewerThan(ServerVersion.V_1_8) ?
action.getSlot() <= 45 : action.getSlot() < 45);
if (valid) {
inventory.getSlot(action.getSlot()).set(action.getItemStack());
inventory.getInventoryStorage().handleClientClaimedSlotSet(action.getSlot());
}
} else if (event.getPacketType() == PacketType.Play.Client.CLICK_WINDOW && !event.isCancelled()) {
WrapperPlayClientClickWindow click = new WrapperPlayClientClickWindow(event);
// How is this possible? Maybe transaction splitting.
if (click.getWindowId() != openWindowID) {
return;
}
// Don't care about this click since we can't track it.
if (menu instanceof NotImplementedMenu) {
return;
}
// Mark the slots the player has changed as changed, then continue simulating what they changed
Optional<Map<Integer, ItemStack>> slots = click.getSlots();
slots.ifPresent(integerItemStackMap -> integerItemStackMap.keySet().forEach(this::markPlayerSlotAsChanged));
// 0 for left click
// 1 for right click
int button = click.getButton();
// Offset by the number of slots in the inventory actively open
// Is -999 when clicking off the screen
int slot = click.getSlot();
// Self-explanatory, look at the enum's values
WrapperPlayClientClickWindow.WindowClickType clickType = click.getWindowClickType();
if (slot == -1 || slot == -999 || slot < menu.getSlots().size()) {
menu.doClick(button, slot, clickType);
}
} else if (event.getPacketType() == PacketType.Play.Client.CLOSE_WINDOW) {
this.closeActiveInventory();
} else if (isTickPacket(event.getPacketType())) {
this.startOfTickStack = getHeldItem();
}
}
public void markSlotAsResyncing(BlockPlace place) {
// Update held item tracking
if (place.hand == InteractionHand.MAIN_HAND) {
inventory.getInventoryStorage().handleClientClaimedSlotSet(Inventory.HOTBAR_OFFSET + player.packetStateData.lastSlotSelected);
} else {
inventory.getInventoryStorage().handleServerCorrectSlot(Inventory.SLOT_OFFHAND);
}
}
public void onBlockPlace(BlockPlace place) {
if (player.gamemode != GameMode.CREATIVE && place.itemStack.getType() != ItemTypes.POWDER_SNOW_BUCKET) {
markSlotAsResyncing(place);
place.itemStack.setAmount(place.itemStack.getAmount() - 1);
}
}
@Override
public void onPacketSend(final PacketSendEvent event) {
// Not 1:1 MCP, based on Wiki.VG to be simpler as we need less logic...
// For example, we don't need permanent storage, only storing data until the client closes the window
// We also don't need a lot of server-sided only logic
if (event.getPacketType() == PacketType.Play.Server.OPEN_WINDOW) {
WrapperPlayServerOpenWindow open = new WrapperPlayServerOpenWindow(event);
MenuType menuType = MenuType.getMenuType(open.getType());
AbstractContainerMenu newMenu;
if (PacketEvents.getAPI().getServerManager().getVersion().isNewerThanOrEquals(ServerVersion.V_1_14)) {
newMenu = MenuType.getMenuFromID(player, inventory, menuType);
} else {
newMenu = MenuType.getMenuFromString(player, inventory, open.getLegacyType(), open.getLegacySlots(), open.getHorseId());
}
packetSendingInventorySize = newMenu instanceof NotImplementedMenu ? UNSUPPORTED_INVENTORY_CASE : newMenu.getSlots().size();
// There doesn't seem to be a check against using 0 as the window ID - let's consider that an invalid packet
// It will probably mess up a TON of logic both client and server sided, so don't do that!
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
openWindowID = open.getContainerId();
menu = newMenu;
isPacketInventoryActive = !(newMenu instanceof NotImplementedMenu);
needResend = newMenu instanceof NotImplementedMenu;
});
}
// I'm not implementing this lol
if (event.getPacketType() == PacketType.Play.Server.OPEN_HORSE_WINDOW) {
WrapperPlayServerOpenHorseWindow open = new WrapperPlayServerOpenHorseWindow(event);
packetSendingInventorySize = UNSUPPORTED_INVENTORY_CASE;
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
isPacketInventoryActive = false;
needResend = true;
openWindowID = open.getWindowId();
});
}
// 1:1 MCP
if (event.getPacketType() == PacketType.Play.Server.CLOSE_WINDOW) {
packetSendingInventorySize = PLAYER_INVENTORY_CASE;
// Disregard provided window ID, client doesn't care...
// We need to do this because the client doesn't send a packet when closing the window
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), this::closeActiveInventory);
}
// Should be 1:1 MCP
if (event.getPacketType() == PacketType.Play.Server.WINDOW_ITEMS) {
WrapperPlayServerWindowItems items = new WrapperPlayServerWindowItems(event);
stateID = items.getStateId();
List<ItemStack> slots = items.getItems();
for (int i = 0; i < slots.size(); i++) {
markServerForChangingSlot(i, items.getWindowId());
}
final int cachedPacketInvSize = packetSendingInventorySize;
final AtomicBoolean updatedValue = new AtomicBoolean();
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
// Never true when the inventory is unsupported.
// Vanilla ALWAYS sends the entire inventory to resync, this is a valid thing to check
// 01/07/2025: Somehow, the server sends a window id 0 update when the player is not in their inventory?
// I guess just revert isPacketInventoryActive if the player has a NotImplementedMenu open?
// Regardless, the client does accept this packet and updates its inventory, so we must do the same.
boolean forceUpdate = slots.size() == cachedPacketInvSize || items.getWindowId() == 0;
if (!isPacketInventoryActive && forceUpdate) {
isPacketInventoryActive = true;
updatedValue.set(true);
}
});
if (items.getWindowId() == 0) { // Player inventory
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
if (!isPacketInventoryActive) return;
for (int i = 0; i < slots.size(); i++) {
inventory.getSlot(i).set(slots.get(i));
}
if (items.getCarriedItem().isPresent()) {
inventory.setCarried(items.getCarriedItem().get());
}
});
} else {
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
if (!isPacketInventoryActive) return;
if (items.getWindowId() == openWindowID) {
for (int i = 0; i < slots.size(); i++) {
menu.getSlot(i).set(slots.get(i));
}
}
if (items.getCarriedItem().isPresent()) {
inventory.setCarried(items.getCarriedItem().get());
}
});
}
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
// The server sent a packet for the player's inventory when they had another inventory open - revert.
if (updatedValue.get() && !menu.equals(inventory)) {
isPacketInventoryActive = false;
}
});
}
// This packet replaces SET_SLOT for player inventory for 1.21.2+
if (event.getPacketType() == PacketType.Play.Server.SET_PLAYER_INVENTORY) {
WrapperPlayServerSetPlayerInventory slot = new WrapperPlayServerSetPlayerInventory(event);
final int slotID = slot.getSlot();
final ItemStack item = slot.getStack();
inventory.getInventoryStorage().handleServerCorrectSlot(slotID);
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
if (!isPacketInventoryActive) return;
inventory.getSlot(slotID).set(item);
});
}
// Also 1:1 MCP
if (event.getPacketType() == PacketType.Play.Server.SET_SLOT) {
// Only edit hotbar (36 to 44) if window ID is 0
// Set cursor by putting -1 as window ID and as slot
// Window ID -2 means any slot can be used
WrapperPlayServerSetSlot slot = new WrapperPlayServerSetSlot(event);
final int slotID = slot.getSlot();
final int inventoryID = slot.getWindowId();
final ItemStack item = slot.getItem();
if (inventoryID == -2) { // Direct inventory change
inventory.getInventoryStorage().handleServerCorrectSlot(slotID);
} else if (inventoryID == 0) { // Inventory change through window ID, no crafting result
inventory.getInventoryStorage().handleServerCorrectSlot(slotID);
} else {
markServerForChangingSlot(slotID, inventoryID);
}
stateID = slot.getStateId();
player.latencyUtils.addRealTimeTask(player.lastTransactionSent.get(), () -> {
if (!isPacketInventoryActive) return;
if (inventoryID == -1) { // Carried item
inventory.setCarried(item);
} else if (inventoryID == -2) { // Direct inventory change (only applied if valid slot)
if (inventory.getInventoryStorage().getSize() > slotID && slotID >= 0) {
inventory.getInventoryStorage().setItem(slotID, item);
}
} else if (inventoryID == 0) { // Player inventory
// This packet can only be used to edit the hotbar and offhand of the player's inventory if
// window ID is set to 0 (slots 36 through 45) if the player is in creative, with their inventory open,
// and not in their survival inventory tab. Otherwise, when window ID is 0, it can edit any slot in the player's inventory.
if (slotID >= 0 && slotID <= 45) {
inventory.getSlot(slotID).set(item);
}
} else if (inventoryID == openWindowID) { // Opened inventory (if not valid, client crashes)
menu.getSlot(slotID).set(item);
}
});
}
}
/**
* Closes the player's currently open inventory on the client by resetting to the player's inventory.
*/
private void closeActiveInventory() {
isPacketInventoryActive = true;
openWindowID = 0;
menu = inventory;
menu.setCarried(ItemStack.EMPTY); // Reset carried item
}
}
// NOTE (AI): The server CLOSE_WINDOW branch (line 355) schedules closeActiveInventory, which resets openWindowID, menu and carried item. The same file carries the S2D open tracking, so the close completes the window state machine.Clear the inventory-open flag on the server close so downstream checks stop treating the player as windowed.
fastHandle matches GPacketPlayServerWindowClose and schedules a transaction-confirmed PacketAction whose pre() sets the inventory-open flag to false. The same handler resets the flag on respawn, and handle() clears it on the client's own C0D close.
// ===== FILE: artemisac-artemis-minecraft-anticheat, ac.artemis.core/src/main/java/ac/artemis/core/v4/processor/miscellaneous/MiscellaneousPreProcessor.java =====
package ac.artemis.core.v4.processor.miscellaneous;
import ac.artemis.core.v4.check.FastProcessHandler;
import ac.artemis.core.v4.data.PlayerData;
import ac.artemis.core.v4.data.holders.ConnectionHolder;
import ac.artemis.core.v4.nms.NMSManager;
import ac.artemis.core.v4.processor.AbstractHandler;
import ac.artemis.core.v4.utils.function.PacketAction;
import cc.ghast.packet.PacketAPI;
import cc.ghast.packet.wrapper.mc.PlayerEnums;
import ac.artemis.packet.spigot.wrappers.GPacket;
import cc.ghast.packet.wrapper.packet.play.client.GPacketPlayClientClientCommand;
import cc.ghast.packet.wrapper.packet.play.client.GPacketPlayClientWindowClose;
import cc.ghast.packet.wrapper.packet.play.client.GPacketPlayClientHeldItemSlot;
import cc.ghast.packet.wrapper.packet.play.client.GPacketPlayClientTransaction;
import cc.ghast.packet.wrapper.packet.play.server.*;
import java.util.ArrayList;
import java.util.Arrays;
/**
* @author Ghast
* @since 06-Mar-20
*/
public class MiscellaneousPreProcessor extends AbstractHandler implements FastProcessHandler {
public MiscellaneousPreProcessor(PlayerData data) {
super("Misc [0x01]", data);
}
@Override
public void handle(final GPacket packet) {
long now = System.currentTimeMillis();
if (packet instanceof GPacketPlayClientHeldItemSlot) {
data.user.usingItem = false;
}
else if (packet instanceof GPacketPlayClientClientCommand) {
final GPacketPlayClientClientCommand cmd = (GPacketPlayClientClientCommand) packet;
if (cmd.getCommand().equals(PlayerEnums.ClientCommand.PERFORM_RESPAWN)) {
data.user.setLastRespawn(packet.getTimestamp());
data.prediction.setVehicle(null);
}
}
else if (packet instanceof GPacketPlayClientTransaction) {
final GPacketPlayClientTransaction trx = (GPacketPlayClientTransaction) packet;
if (!trx.isAccepted()) {
//data.user.setInventoryOpen(true);
}
}
else if (packet instanceof GPacketPlayClientWindowClose) {
data.user.setInventoryOpen(false);
}
/*else if (packet instanceof GPacketPlayServerEntityTeleport) {
final GPacketPlayServerEntityTeleport tp = (GPacketPlayServerEntityTeleport) packet;
if (data.prediction.getVehicle() != null &&
(tp.getEntityId() == data.getPlayer().getEntityId() || tp.getEntityId() == data.prediction.getVehicle().getEntityId())) {
data.connection.confirmFunction(ConnectionHolder.ConfirmationType.TRANSACTION, new PacketAction() {
@Override
public void pre() {
data.prediction.setVehicle(null);
}
});
}
}*/
/*else if (packet instanceof GPacketPlayServerPosition) {
if (data.prediction.getVehicle() != null) {
data.connection.confirmFunction(ConnectionHolder.ConfirmationType.TRANSACTION, new PacketAction() {
@Override
public void pre() {
data.prediction.setVehicle(null);
}
});
}
}*/
data.timing.miscTiming.addTime(now, System.currentTimeMillis());
}
@Override
public void fastHandle(GPacket packet) {
if (packet instanceof GPacketPlayServerRespawn) {
data.connection.confirmFunction(ConnectionHolder.ConfirmationType.TRANSACTION, new PacketAction() {
@Override
public void pre() {
data.user.setLastRespawn(packet.getTimestamp());
data.user.setInventoryOpen(false);
data.prediction.setVehicle(null);
}
});
}
else if (packet instanceof GPacketPlayServerWindowClose) {
data.connection.confirmFunction(ConnectionHolder.ConfirmationType.TRANSACTION, new PacketAction() {
@Override
public void pre() {
data.user.setInventoryOpen(false);
}
});
}
else if (packet instanceof GPacketPlayServerEntityAttach) {
final GPacketPlayServerEntityAttach attach = (GPacketPlayServerEntityAttach) packet;
if (attach.getEntityId() == data.getPlayer().getEntityId()) {
data.connection.confirmFunctionAndTick(ConnectionHolder.ConfirmationType.TRANSACTION, new PacketAction() {
@Override
public void pre() {
data.prediction.setVehicle(NMSManager.getInms().getEntity(data.getPlayer().getWorld(), attach.getVehicleId()));
if (data.prediction.getVehicle() == null) {
data.resetMotion();
}
}
});
}
}
else if (packet instanceof GPacketPlayServerEntityDestroy) {
final GPacketPlayServerEntityDestroy dtr = (GPacketPlayServerEntityDestroy) packet;
final boolean flag = data.prediction.getVehicle() != null
&& Arrays.stream(dtr.getEntities()).anyMatch(e -> data.prediction.getVehicle().getEntityId() == e);
if (flag) {
data.connection.confirmFunction(ConnectionHolder.ConfirmationType.TRANSACTION, new PacketAction() {
@Override
public void pre() {
data.prediction.setVehicle(null);
data.resetMotion();
}
});
}
}
else if (packet instanceof GPacketPlayServerBed) {
final GPacketPlayServerBed bed = (GPacketPlayServerBed) packet;
if (bed.getPlayerID() == data.getPlayer().getEntityId()) {
data.connection.confirmFunction(ConnectionHolder.ConfirmationType.TRANSACTION, new PacketAction() {
@Override
public void pre() {
data.prediction.setVehicle(null);
data.resetMotion();
}
});
}
}
}
}
// NOTE (AI): The GPacketPlayServerWindowClose branch in fastHandle is the S2E hook; the close is applied on transaction confirmation. handle() covers the client's own C0D close.Related Packets
Wiki Cross-Reference
The server sends this when a window is forcibly closed, for example when a chest is destroyed while open, and window ID 0 refers to the player inventory.
MCP 1.8.9 S2EPacketCloseWindow implements Packet
1.8.9 callers: EntityPlayerMP.closeScreen sends new S2EPacketCloseWindow (line 902): https://github.com/Marcelektro/MavenMCP-1.8.9/blob/master/src/main/java/net/minecraft/entity/player/EntityPlayerMP.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.