
# -> Decrease animal stamina
scoreboard players remove @s OverlyRealistic.Animal.Stamina 1

# -> If animal is out of stamina then return and do tiredness operations
execute if score @s OverlyRealistic.Animal.Stamina matches ..0 run \
    return run \
        function overly_realistic:animals/operations/animal_get_tired_from_fleeing

# -> If currently in a liquid then return
execute if block ~ ~-0.5 ~ #overly_realistic:animal_panic_returnables run \
    return run \
        function overly_realistic:animals/operations/forward_velocity_animal_panic_liquid

# -> If there is a blockage then look elsewhere
execute if block ^ ^-1 ^1.5 #overly_realistic:animal_panic_block run \
    rotate @s ~95 ~
execute at @s if block ^ ^-1 ^1.5 #overly_realistic:animal_panic_block run \
    rotate @s ~95 ~
execute at @s if block ^ ^-1 ^1.5 #overly_realistic:animal_panic_block run \
    rotate @s ~95 ~

# -> Apply invulnerability
data modify entity @s Invulnerable set value 1b

# -> Move entity
tp ~ ~-9999 ~

# -> Apply velocity
execute positioned ~ ~-9999 ~ \
    positioned ^ ^ ^-9.45 \
    summon end_crystal run \
        damage @s 0

# -> Move entity back
tp ~ ~ ~

# -> Gravity
execute if block ~ ~-1 ~ #overly_realistic:animal_panic_gravity_enabled run \
    data modify entity @s Motion[1] set value -1

# -> Jump up block
# -> (@NOTE: This is only here for now to be compatible with previous versions!)
attribute @s step_height modifier add overly_realistic:animal_panic_step_height 0.55 add_value

# -> Remove invulnerability
data modify entity @s Invulnerable set value 0b