Forge 1.17.1
Hello. I want to do something like scare mobs potion effect. It basically would make mobs ignore the player, just like on gamemode creative. I discovered that when I give player disableDamage ability (player.abilities.disableDamage), mobs start to ignore the player. But I don't want to make player invulnerable (I'll use tags).
Then I found this method in MobEntity class:
public boolean canAttack(LivingEntity target) {
return target.getType() == EntityType.PLAYER && ((PlayerEntity)target).abilities.disableDamage ? false : super.canAttack(target);
}
I just need to somehow override/change/...? it to something like
return target.getType() == EntityType.PLAYER && ((PlayerEntity)target).getTags().contains("scare_mobs") ? false && ((PlayerEntity)target).abilities.disableDamage ? false : super.canAttack(target);)
but I don't really know how. What is the best way to do this, without breaking the game?