This event allows users to modify the piglin behavior towards a player. It supports a tri-state.
attack -> attack the player
ignore -> ignore the player
keep -> keep the old behavior (don't modify anything)
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');
});
This event allows users to modify the piglin behavior towards a player. It supports a tri-state.
attack
-> attack the playerignore
-> ignore the playerkeep
-> keep the old behavior (don't modify anything)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: