DropSlot
com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventDropSlot
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, ornullfor a screenless hotbar-key dropslot: the source inventory-menu index;-999denotes an outside-window drop, and hotbar-key indices conventionally range from36through44; the value is stored without validationall: the stored flag indicating a whole-stack rather than one-item drop; it does not guarantee that a drop occurs
Fields
all
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
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
toString
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