The EntityHurtBeforeEvent interface in @minecraft/server.
Interface in @minecraft/server
Extends CancellableEvent
import type { EntityHurtBeforeEvent } from '@minecraft/server';Subscribe to it with world.beforeEvents.entityHurt.
Example
Section titled “Example”import { world, type EntityHurtBeforeEvent } from '@minecraft/server';
world.beforeEvents.entityHurt.subscribe((event: EntityHurtBeforeEvent) => { console.log('entityHurt', event.hurtEntity.typeId, event.damage, event.cancelKnockback);
// Uncomment to stop it from happening. // event.cancel = true;});import { world } from '@minecraft/server';
world.beforeEvents.entityHurt.subscribe((event) => { console.log('entityHurt', event.hurtEntity.typeId, event.damage, event.cancelKnockback);
// Uncomment to stop it from happening. // event.cancel = true;});Properties
Section titled “Properties”hurtEntity
Section titled “hurtEntity”read-only
readonly hurtEntity: Entity;The player or mob about to be hurt.
Types
damage
Section titled “damage”damage: number;The damage before armour and resistance, which handlers may change.
damageSource
Section titled “damageSource”read-only
readonly damageSource: EntityDamageSource;Types
knockback
Section titled “knockback”knockback: Vector3;The velocity the hit leaves the player or mob with, which handlers may change. A sprinting attacker’s hits push further, as PowerNukkitX’s do.
Types
cancelKnockback
Section titled “cancelKnockback”cancelKnockback: boolean;True and the hit pushes nobody. True already for hurts with no push.
Used by
Section titled “Used by”WorldBeforeEvents.entityHurt, EntityHurtBeforeEventSignal.subscribe, EntityHurtBeforeEventSignal.unsubscribe
Inherited
Section titled “Inherited”From CancellableEvent: cancel