Skip to content

EntityDamageEvent

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

public ref struct EntityDamageEvent : IEvent

A living entity is about to take damage. Cancel to negate it. ‘amount’ (the damage after armor and enchantments, before absorption) may be rewritten.

Id 31
Key mc:entity_damage
Cancellable yes
Fired by the engine yes
Field Type Handlers may write Description
Target Entity no (readonly) The damaged entity.
Attacker Entity no (readonly) The responsible entity, none when there is no attacking entity.
DamageType key.damage_type no (readonly) The damage type key, e.g. minecraft:fall.
Amount float yes Final damage after armor and enchantments.
Cause enum:DamageCause no (readonly) The cause derived from the damage type.
RawAmount float no (readonly) Damage before armor and enchantments.
BlockSource BlockPos no (readonly) Position of the block that caused the damage.
HasBlockSource bool no (readonly) Whether block_source is valid (cactus, magma, fire, …).

Set e.Cancelled = true in a handler to cancel it; lower-priority handlers are skipped unless they subscribed with receiveCancelled: true.

Member Description
Constructor Creates the event (for firing it from a plugin; native code builds its own).
public EntityDamageEvent(Entity target, Entity attacker, int damageType, float amount, DamageCause cause, float rawAmount, BlockPos blockSource, bool hasBlockSource)

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

Parameters

Name Type Description
target Entity
attacker Entity
damageType int
amount float
cause DamageCause
rawAmount float
blockSource BlockPos
hasBlockSource bool
Member Description
float Amount { get; set; } Final damage after armor and enchantments.
Entity Attacker { get; } The responsible entity, none when there is no attacking entity.
BlockPos BlockSource { get; } Position of the block that caused the damage.
bool Cancelled { get; set; } Cancelling stops lower-priority handlers (unless they opt in) and the action itself.
DamageCause Cause { get; } The cause derived from the damage type.
string DamageType { get; } The damage type key, e.g.
bool HasBlockSource { get; } Whether block_source is valid (cactus, magma, fire, …).
float RawAmount { get; } Damage before armor and enchantments.
Entity Target { get; } The damaged entity.
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 float Amount { get; set; }

Final damage after armor and enchantments.

public Entity Attacker { get; }

The responsible entity, none when there is no attacking entity.

public BlockPos BlockSource { get; }

Position of the block that caused the damage.

public bool Cancelled { get; set; }

Cancelling stops lower-priority handlers (unless they opt in) and the action itself.

public DamageCause Cause { get; }

The cause derived from the damage type.

public string DamageType { get; }

The damage type key, e.g. minecraft:fall. (a registry key such as “minecraft:damage”; resolved on first access).

public bool HasBlockSource { get; }

Whether block_source is valid (cactus, magma, fire, …).

public float RawAmount { get; }

Damage before armor and enchantments.

public Entity Target { get; }

The damaged entity.

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.

BlockPos · DamageCause · Entity · IEvent