EntityDamageEvent
Namespace Mc.Scripting.Events · Kind struct (ref)
public ref struct EntityDamageEvent : IEventA 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.
Constructors
Section titled “Constructors”| Member | Description |
|---|---|
Constructor |
Creates the event (for firing it from a plugin; native code builds its own). |
Constructor
Section titled “Constructor”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 |
Properties
Section titled “Properties”| 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. |
Amount
Section titled “Amount”public float Amount { get; set; }Final damage after armor and enchantments.
Attacker
Section titled “Attacker”public Entity Attacker { get; }The responsible entity, none when there is no attacking entity.
BlockSource
Section titled “BlockSource”public BlockPos BlockSource { get; }Position of the block that caused the damage.
Cancelled
Section titled “Cancelled”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.
DamageType
Section titled “DamageType”public string DamageType { get; }The damage type key, e.g. minecraft:fall. (a registry key such as “minecraft:damage”; resolved on first access).
HasBlockSource
Section titled “HasBlockSource”public bool HasBlockSource { get; }Whether block_source is valid (cactus, magma, fire, …).
RawAmount
Section titled “RawAmount”public float RawAmount { get; }Damage before armor and enchantments.
Target
Section titled “Target”public Entity Target { get; }The damaged entity.
CatalogueId
Section titled “CatalogueId”public static ushort CatalogueId { get; }Catalogue id (stable ABI).
IsCancellable
Section titled “IsCancellable”public static bool IsCancellable { get; }Whether handlers can cancel the event.
public static string Key { get; }Registry key of the event.
See also
Section titled “See also”BlockPos · DamageCause · Entity · IEvent