
# -> If entity is in the water then boost it
execute if block ~ ~ ~ water run \
    data modify entity @s[type=!hoglin] Motion[1] set value 0.3

# -> If there are no players nearby then return
execute unless entity @p[distance=..8] run \
    return fail

# -> If entity is smart, if there are 3+ players nearby, then de-aggro
execute if entity @s[tag=OverlyRealistic.Animal.SmartFearAggroAnimal] \
    if function overly_realistic:animals/operations/player_count_3_smart_fear run \
        return run \
            function overly_realistic:animals/operations/aggro_flee

# -> If entity has the tribal fear trait, if there are 3+ tribal-mask-wearing players nearby, then de-aggro
execute if entity @s[tag=OverlyRealistic.Animal.TribalFearAggroAnimal] \
    if function overly_realistic:animals/operations/player_count_3_tribal_fear run \
        return run \
            function overly_realistic:animals/operations/aggro_flee

# -> Get entity health
execute store result score #or.global OverlyRealistic.General.ArbitraryData run \
    data get entity @s Health

# -> If animal health <= 18 then return and pacify it
execute unless score #or.global OverlyRealistic.General.ArbitraryData matches 19.. run \
    return run \
        function overly_realistic:animals/operations/aggro_flee

# -> If animal health <= 25 and there are >= 4 players nearby then return and flee
execute unless score #or.global OverlyRealistic.General.ArbitraryData matches 26.. \
    if function overly_realistic:animals/operations/player_count_4 run \
    return run \
        function overly_realistic:animals/operations/aggro_flee

# -> Attack nearby players
execute positioned ~-1 ~ ~-1 run \
    damage @p[dx=1,dy=2,dz=1] 2 mob_attack by @s from @s
