ClickSlot
com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventClickSlot
Fires when the local player clicks a slot in an open container screen, which includes the player's own inventory and the creative inventory. It is raised for every click the screen handles, whether the click ends up moving items or not, and the fields describe the click rather than its result.
Cancelling stops the click. The event is raised before the click is handed to the game mode,
and cancelling makes the mixin abort before that call happens, so the click packet is never sent and no slot changes. This is also why EventDropSlot is not raised for a cancelled click: the drop event is only reached once the click itself has been allowed through.
For drops on their own, see EventDropSlot. For a single slot changing because the server sent an update, see EventSlotUpdate.
JsMacros.on("ClickSlot", JavaWrapper.methodToJava(function (event) {
if (event.mode === 1) {
// mode 1 is the shift-click quick move, refuse it entirely
event.cancel();
return;
}
if (event.slot === -999) {
// -999 is the out-of-window slot, nothing lives there to protect
return;
}
const stack = event.getInventory().getSlot(event.slot);
if (stack.getItemID() === "minecraft:diamond_sword") {
Chat.log("diamond swords are not allowed to move out of this chest");
event.cancel();
}
}))Constructors
new EventClickSlot
new EventClickSlot(AbstractContainerScreen<?> screen, int mode, int button, int slot)#null screen is accepted and is not dereferenced here.Parameters:
screen: source container screen; may benullmode: numeric click-action ID; no click-type range is enforcedbutton: action button or key numberslot: source inventory-menu index; the out-of-window convention is not validated
Fields
button
0 for the left button, or for dropping a single item, and 1 for the right button, or for dropping the whole stack. For a swap it is the hotbar slot that was pressed, 0 through 8, or 40 for the offhand key. The creative inventory also uses 9 and 10 for its two extra buttons.mode
0 is a plain pick up or place, 1 is the shift-click quick move, 2 is a hotbar swap, 3 is the creative middle-click clone, 4 is a throw or drop, 5 is a right-click quick craft, and 6 is a double-click pick up all, which sweeps everything of that item type into the cursor. These ids correspond to the ClickType action ids on Minecraft 1.21.8.slot
-999, the game's out-of-window slot, when the click landed outside the container window. That case is also reported as a drop by EventDropSlot.