# DropSlot

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

**Since:** 1.6.4

**Cancellable:** Yes. Call `event.cancel()` in a handler before releasing the event lock.

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](EventClickSlot.md); cancelling that click prevents this event from firing. Other item-moving
 clicks, such as shift-clicks, do not raise this event.  
 Use [getInventory()](#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventDropSlot_getInventory-) to access the source inventory; the hotbar-key case has no screen.  
 ```js
JsMacros.on("DropSlot", true, 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 {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventDropSlot_constructor-AbstractContainerScreen-int-boolean-}

```js
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 {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventDropSlot_all}

```js
all: boolean
```

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 {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventDropSlot_slot}

```js
slot: int
```

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()](#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventDropSlot_getInventory-)'s [getSlot()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/inventory/Inventory.md#com.jsmacrosce.jsmacros.client.api.classes.inventory.Inventory_getSlot-int-).

## Methods

### getInventory {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventDropSlot_getInventory-}

```js
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()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/inventory/Inventory.md#com.jsmacrosce.jsmacros.client.api.classes.inventory.Inventory_getSlot-int-) on the returned wrapper.

**Returns:** the inventory the drop is coming from

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventDropSlot_toString-}

```js
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
