AlmostReliable / morejs

A Minecraft mod to extend KubeJS with additional events.
https://www.curseforge.com/minecraft/mc-mods/morejs
GNU Lesser General Public License v3.0
12 stars 1 forks source link

[1.19] piglin aggression event towards players #4

Closed rlnt closed 1 year ago

rlnt commented 1 year ago

This event allows users to modify the piglin behavior towards a player. It supports a tri-state.

This should maybe be exposed as a binding, but that's up to you.

The event gives you access to the target player, the piglin entity, a boolean whether the piglin was already aggressive towards the player (e.g. for not wearing a piece of gold armor), and a function to specify if the item holding check should be ignored so you can make the piglin aggressive towards the player even if they carry an item of the piglin_loved tag.

The default behavior is always keep so the behavior works like the vanilla one when the event is not implemented.

Example script:

MoreJSEvents.piglinPlayerBehavior(event => {
    // console.log(event.isAggressiveAlready());
    // console.log(event.entity.getDisplayName().getString());

    // when the player name starts with 'Player', the piglin will ignore the player
    if (event.entity.getDisplayName().getString().startsWith('Player')) {
        event.setBehavior('ignore');
        return;
    }

    // when the player name is 'Lytho', the piglin will always attack
    // even when the player is holding an item from the 'piglin_loved' tag
    if (event.entity.getDisplayName().getString() == 'Lytho') {
        event.setBehavior('attack');
        event.ignoreHoldingCheck();
        return;
    }

    // otherwise it will remain its old behavior
    event.setBehavior('keep');
});