Skip to content

PlayerDeathEvent

Namespace Mc.Scripting.Events · Kind struct (ref)

public ref struct PlayerDeathEvent : IEvent

A player died. The death message, inventory/experience drops and level keeping can be changed.

Id 112
Key mc:player_death
Cancellable no
Fired by the engine yes
Field Type Handlers may write Description
Player player no (readonly) The player.
Killer Entity no (readonly) The entity responsible (none if there is none).
Cause enum:DamageCause no (readonly) The damage cause.
DeathMessage component yes Broadcast to everybody (empty = none).
DropInventory bool yes Drop the items (false keeps them, like keepInventory). Only the items: the experience is controlled by the two fields below.
KeepLevel bool yes Keep the experience level through the respawn (default: the keepInventory rule). True drops no experience orbs.
DropExperience int yes Experience points dropped as orbs at the death position (default the vanilla amount min(level*7, 100), 0 with keepInventory); independent of drop_inventory.
Member Description
Constructor Creates the event (for firing it from a plugin; native code builds its own).
public PlayerDeathEvent(Player player, Entity killer, DamageCause cause, Utf8String deathMessage, bool dropInventory, bool keepLevel, int dropExperience)

Creates the event (for firing it from a plugin; native code builds its own). Signature of API 1.0.

Parameters

Name Type Description
player Player
killer Entity
cause DamageCause
deathMessage Utf8String
dropInventory bool
keepLevel bool
dropExperience int
Member Description
DamageCause Cause { get; } The damage cause.
Component DeathMessage { get; } Broadcast to everybody (empty = none).
Utf8String DeathMessageJson { get; } Broadcast to everybody (empty = none).
int DropExperience { get; set; } Experience points dropped as orbs at the death position (default the vanilla amount min(level*7, 100), 0 with keepInventory); independent of drop_inventory.
bool DropInventory { get; set; } Drop the items (false keeps them, like keepInventory).
bool KeepLevel { get; set; } Keep the experience level through the respawn (default: the keepInventory rule).
Entity Killer { get; } The entity responsible (none if there is none).
Player Player { get; } The player.
static ushort CatalogueId { get; } Catalogue id (stable ABI).
static bool IsCancellable { get; } Whether handlers can cancel the event.
static string Key { get; } Registry key of the event.
public DamageCause Cause { get; }

The damage cause.

public Component DeathMessage { get; }

Broadcast to everybody (empty = none). (parsed on access; allocates).

public Utf8String DeathMessageJson { get; }

Broadcast to everybody (empty = none). as JSON text (borrowed).

public int DropExperience { get; set; }

Experience points dropped as orbs at the death position (default the vanilla amount min(level*7, 100), 0 with keepInventory); independent of drop_inventory.

public bool DropInventory { get; set; }

Drop the items (false keeps them, like keepInventory). Only the items: the experience is controlled by the two fields below.

public bool KeepLevel { get; set; }

Keep the experience level through the respawn (default: the keepInventory rule). True drops no experience orbs.

public Entity Killer { get; }

The entity responsible (none if there is none).

public Player Player { get; }

The player.

public static ushort CatalogueId { get; }

Catalogue id (stable ABI).

public static bool IsCancellable { get; }

Whether handlers can cancel the event.

public static string Key { get; }

Registry key of the event.

Member Description
void SetDeathMessage(Component value) Replaces PlayerDeathEvent.DeathMessage; an empty component clears it where the event says so.
public void SetDeathMessage(Component value)

Replaces PlayerDeathEvent.DeathMessage; an empty component clears it where the event says so.

Parameters

Name Type Description
value Component

Component · DamageCause · Entity · IEvent · Player · Utf8String