Skip to content

Death ​

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

Since1.2.7Not cancellable

Fires while handling the server's player-combat-kill packet, before the client shows the death screen. Call 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 ​

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. The list and wrappers are created at construction time, without copying the underlying item stacks.

Fields ​

deathPos ​

deathPos: BlockPosHelperread-only#
The player's block position when the death packet is handled.

inventory ​

inventory: List<ItemStackHelper>read-only#
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 ​

respawn(): voidSince1.8.4#
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.
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();
  }))
}))

toString ​

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