Skip to content

ClickSlot ​

com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventClickSlot

Since1.6.4Cancellable

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.

js
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)#
Stores the screen reference and click values unchanged, and initializes the event with the client core. A null screen is accepted and is not dereferenced here.

Parameters:

  • screen: source container screen; may be null
  • mode: numeric click-action ID; no click-type range is enforced
  • button: action button or key number
  • slot: source inventory-menu index; the out-of-window convention is not validated

Fields ​

button ​

button: intread-only#
Which button or key produced the click, as a number. For a pick up or a throw this is the mouse 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 ​

mode: intread-only#
Numeric id of the game's click action. 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 ​

slot: intread-only#
the index of the clicked slot in the open screen's menu, the same numbering getSlot() uses. This is -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.

Methods ​

getInventory ​

getInventory(): Inventory<?>#
Returns a fresh Inventory wrapper for the menu of the screen where the click occurred. The wrapper refers to that same menu; -999 is not a menu slot.
Returns: the inventory of the screen this click happened in

toString ​

toString(): String#
Formats a diagnostic string using the event name, stored slot, and screen name. The result has the form %s:{"slot": %d, "screen": "%s"}; a null screen name appears as the quoted text "null".
Returns: formatted diagnostic string; this is not JSON serialization