Death
com.jsmacrosce.jsmacros.client.api.event.impl.player.EventDeath
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
The player's block position when the death packet is handled.
inventory
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
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();
}))
}))