Skip to content
BasaltSoftware
Bedrock 1.26.60

Site colour

Discord
Esc

    ↑↓ moveEnter openEsc close

    Keyboard shortcuts
    Ctrl K
    Search the whole site, from any page
    /
    Jump to the sidebar search, or search the whole site where there isn't one
    Enter
    Open the top search result
    Esc
    Clear the search, or close this panel
    ?
    Show these shortcuts
    Before events

    PlayerHurtBeforeEvent

    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.

    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;
    });

    read-only

    readonly hurtEntity: Player;
    Types
    damage: number;

    read-only

    readonly damageSource: EntityDamageSource;
    knockback: Vector3;

    The push the hit gives, which handlers may change.

    Types
    cancelKnockback: boolean;

    Set true and the hit pushes nobody, so the plugin can push its own way.

    WorldBeforeEvents.playerHurt

    From CancellableEvent: cancel