Basalt's own: EntityHurtBeforeEvent for players alone, with the knockback.
Interface in @minecraft/server
Extends CancellableEvent
Basalt’s own: EntityHurtBeforeEvent for players alone, with the knockback.
import type { PlayerHurtBeforeEvent } from '@minecraft/server';Subscribe to it with world.beforeEvents.playerHurt.
Example
Section titled “Example”import { world, type PlayerHurtBeforeEvent } from '@minecraft/server';
world.beforeEvents.playerHurt.subscribe((event: PlayerHurtBeforeEvent) => { console.log('playerHurt', event.hurtEntity.name, event.damage, event.cancelKnockback);
// Uncomment to stop it from happening. // event.cancel = true;});import { world } from '@minecraft/server';
world.beforeEvents.playerHurt.subscribe((event) => { console.log('playerHurt', event.hurtEntity.name, 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: Player;Types
damage
Section titled “damage”damage: number;damageSource
Section titled “damageSource”read-only
readonly damageSource: EntityDamageSource;Types
knockback
Section titled “knockback”knockback: Vector3;The push the hit gives, which handlers may change.
Types
cancelKnockback
Section titled “cancelKnockback”cancelKnockback: boolean;Set true and the hit pushes nobody, so the plugin can push its own way.
Used by
Section titled “Used by”Inherited
Section titled “Inherited”From CancellableEvent: cancel