#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#
#    This function has been created by Skilendarz Group.
#             https://skilendarz.com
#
#      GIVE MAP MAKERS THE CREDIT THEY DESERVE!
#             COPYING IS PROHIBITED!
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#Facing
execute as @e[tag=head] at @s run tp @s ~ ~ ~ facing entity @p
execute as @e[tag=head1,y_rotation=-180..20] at @s run tp @s ~ ~ ~ 90 0
execute as @e[tag=head1,y_rotation=160..180] at @s run tp @s ~ ~ ~ 90 0
execute as @e[tag=head2,y_rotation=-180..-10] at @s run tp @s ~ ~ ~ 90 0
execute as @e[tag=head2,y_rotation=130..180] at @s run tp @s ~ ~ ~ 90 0
execute as @e[tag=head3,y_rotation=-170..50] at @s run tp @s ~ ~ ~ 90 0

#Store
execute as @e[tag=head] at @s run data merge entity @s {Pose:{Head:[0.01f,0.0f,0.0f]}}
execute as @e[tag=body] at @s run data merge entity @s {Pose:{RightArm:[0.01f,0.01f,0.01f]}}
execute as @e[tag=head] store result entity @s Pose.Head[0] float 1 run data get entity @s Rotation[1]
execute as @e[tag=body] store result entity @s Pose.RightArm[2] float 1 run scoreboard players get @s tick
execute as @e[tag=body] store result entity @s Pose.RightArm[0] float 1 run scoreboard players get @s main

#Animation
execute as @e[tag=body,scores={time=0}] at @s if entity @p[distance=..12] run scoreboard players set @s time 1
scoreboard players add @e[tag=body,scores={time=1..}] time 1

scoreboard players remove @e[tag=body,scores={time=1..6}] main 5
scoreboard players add @e[tag=body,scores={time=1..16}] tick 10
scoreboard players add @e[tag=body,scores={time=17..18}] tick 5
scoreboard players remove @e[tag=body,scores={time=19..20}] tick 5
scoreboard players remove @e[tag=body,scores={time=21..24}] tick 10
scoreboard players remove @e[tag=body,scores={time=25..26}] tick 5

scoreboard players add @e[tag=body,scores={time=31..36}] main 5
scoreboard players remove @e[tag=body,scores={time=27..36}] tick 10
scoreboard players set @e[tag=body,scores={time=36..}] tick 0
scoreboard players set @e[tag=body,scores={time=36..}] main 0
scoreboard players set @e[tag=body,scores={time=36..}] time 0

execute as @e[tag=body,scores={time=26}] at @s if entity @p[distance=..12] run scoreboard players set @s time 11