Skip to content

Piglin Player Behavior

Relentless edited this page May 8, 2023 · 2 revisions

Piglin behavior towards Players

This event is 1.19+ only.

Piglin behaviors:

  • attack: The piglin will attack the player
  • ignore: The piglin will ignore the player
  • keep: The piglin will keep its old behavior
MoreJSEvents.piglinPlayerBehavior(event => {
    // `event.player`: The player that is currently being checked to change the behavior of the Piglin
    // `event.piglin`: The Piglin to change the behavior of
    // `event.aggressiveAlready`: True if the Piglin is already aggressive towards a player
    // `event.previousTargetPlayer`: The player that the Piglin was previously aggressive towards, or null
    // `event.behavior`: The current behavior of the Piglin towards the player, see above

    /**
     * Tells the Piglin to ignore the hand-held items of the player.
     * Piglins usually become passive when the player carries one of the items
     * of the `piglin_loved` tag in their hand or their offhand.
     */
    event.ignoreHoldingCheck();
});

Example:

MoreJSEvents.piglinPlayerBehavior(event => {

    // attack all players that have less than 3 levels, even if they hold a gold item
    if (event.player.getXpLevel() < 3) {
        event.setBehavior('attack');
        event.ignoreHoldingCheck();
        return;
    }

    // ignore players in the overworld
    if (event.player.level.dimension().location() == 'overworld') {
        event.setBehavior('ignore');
        return;
    }

    // otherwise it will remain its old behavior, default value
    event.setBehavior('keep');
});
Clone this wiki locally