Skip to content

DropSlot ​

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

Since1.6.4Cancellable

Fires for drops from a container screen (including clicking outside it) and for hotbar-key drops when no screen is open. Cancelling prevents the drop. Screen drops first raise EventClickSlot; cancelling that click prevents this event from firing. Other item-moving clicks, such as shift-clicks, do not raise this event.
Use getInventory() to access the source inventory; the hotbar-key case has no screen.

js
JsMacros.on("DropSlot", JavaWrapper.methodToJava(function (event) {
  if (event.slot === -999) {
    // dropping what is on the cursor by clicking outside the window
    event.cancel();  
    return;  
  }
  const stack = event.getInventory().getSlot(event.slot);  
  if (stack.getItemID() === "minecraft:diamond_sword") {
    Chat.log(event.all ? "no dropping whole swords" : "no dropping swords");  
    event.cancel();  
  }
}))

Constructors ​

new EventDropSlot ​

new EventDropSlot(AbstractContainerScreen<?> screen, int slot, boolean all)#
Stores the source screen and drop-slot values on the event after initializing its base event. This does not perform or dispatch a drop, look up the inventory, or validate, normalize, or copy the supplied values.

Parameters:

  • screen: the source container screen, or null for a screenless hotbar-key drop
  • slot: the source inventory-menu index; -999 denotes an outside-window drop, and hotbar-key indices conventionally range from 36 through 44; the value is stored without validation
  • all: the stored flag indicating a whole-stack rather than one-item drop; it does not guarantee that a drop occurs

Fields ​

all ​

all: booleanread-only#
Whether this action drops the whole stack rather than one item. For a screen drop this is true for a right-click throw; for a hotbar-key drop it reflects the game's entireStack argument.

slot ​

slot: intread-only#
The index of the slot being dropped from, in the screen menu's numbering, or -999 when the drop came from clicking outside the window with a stack on the cursor. When there is no screen, because the drop came from the hotbar key, this is 36 plus the hotbar slot, which is the numbering the player's own inventory menu uses for hotbar slots 36 through 44. The number can be passed straight to getInventory()'s getSlot().

Methods ​

getInventory ​

getInventory(): Inventory<?>#
Returns a new inventory wrapper for the source: the screen menu for screen drops, or the player's inventory for hotbar-key drops. The event's slot can be used with getSlot() on the returned wrapper.
Returns: the inventory the drop is coming from

toString ​

toString(): String#
Returns a diagnostic string in the format %s:{"slot": %d, "screen": "%s"}, containing the event name, stored slot, and screen name. A null screen is rendered as the quoted string "null"; this is not a JSON null value, and the string does not include the all flag.
Returns: the diagnostic string in the format shown above