# Death

`com.jsmacrosce.jsmacros.client.api.event.impl.player.EventDeath`

**Since:** 1.2.7

**Cancellable:** No. Calling `event.cancel()` throws `UnsupportedOperationException`.

Fires while handling the server's player-combat-kill packet, before the client shows the death
screen. Call [respawn()](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventDeath_respawn-) on a later tick rather than during
packet handling; this requests respawn but does not guarantee that the death screen never opens.  
```js
JsMacros.on("Death", JavaWrapper.methodToJava(function (event) {
  const pos = event.deathPos;  
  Chat.log(`Died at ${pos.getX()}, ${pos.getY()}, ${pos.getZ()}`);  
  let filled = 0;  
  for (const stack of event.inventory) {
    if (!stack.isEmpty()) {
      filled += 1;  
    }
  }
  Chat.log(`Inventory had ${filled} non empty stacks when the event fired`);  
}))
```

## Constructors

### new EventDeath {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventDeath_constructor-}

```js
new EventDeath()
```

Captures the current local player's block position and inventory entries. Construction
requires a non-null local player; otherwise reading its block position throws a
[NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html). The list and wrappers are created at construction time,  
without copying the underlying item stacks.

## Fields

### deathPos {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventDeath_deathPos}

```js
deathPos: BlockPosHelper
```

The player's block position when the death packet is handled.

### inventory {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventDeath_inventory}

```js
inventory: List<ItemStackHelper>
```

A snapshot of the player inventory's slots in inventory order, including armor and offhand.  
Empty slots are represented by empty entries; check `isEmpty()` before reading one.

## Methods

### respawn {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventDeath_respawn-}

```js
respawn(): void
```

Requests respawn if the local player is not alive. Use from a later tick rather than
during death-packet handling. The server can ignore the request while its player is
still alive; sending it does not confirm respawn or guarantee the death screen never opens.  
```js
JsMacros.on("Death", JavaWrapper.methodToJava(function (event) {
  // the "Death" listener stays registered, so every death is caught
  // "once" is used for the tick, so nothing is left behind once it has fired
  JsMacros.once("Tick", JavaWrapper.methodToJava(function () {
    event.respawn();  
  }))
}))
```

**Since:** 1.8.4

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventDeath_toString-}

```js
toString(): String
```

Formats the event name and stored death position as `%s:{"deathPos": %s}`; the
inventory is not included.

**Returns:** the diagnostic event-name and death-position string
