#scoreboard objectives add walk dummy
#scoreboard objectives add walking dummy
#scoreboard objectives add MotX dummy
#scoreboard objectives add MotZ dummy
#execute as @e[name=animationTime] at @s run function giant:animation


execute as @e[name=Giant] at @s run tp @e[tag=legR,limit=1,sort=nearest,tag=Mar] ^0.04 ^-0.55 ^
effect give @e[name=Giant] minecraft:invisibility 1000 1 true
execute as @e[name=Giant] at @s run tp @e[tag=legL,limit=1,sort=nearest,tag=Mar] ^-0.04 ^-0.55 ^
execute as @e[name=Giant] at @s run tp @e[tag=Body,limit=1,sort=nearest,tag=Mar] ~ ~ ~
execute as @e[name=Giant] at @s positioned ~ ~ ~ run tp @e[tag=armR,limit=1,sort=nearest,tag=Mar] ^-0.004 ^ ^
execute as @e[name=Giant] at @s positioned ~ ~ ~ run tp @e[tag=armL,limit=1,sort=nearest,tag=Mar] ^0.004 ^ ^
execute as @e[name=Giant] at @s run tp @e[tag=Head,limit=1,sort=nearest,tag=Mar] ~ ~ ~
execute as @e[tag=Mar] store result entity @s Rotation[0] float 1 run data get entity @e[name=Giant,limit=1,sort=nearest] Rotation[0]
execute as @e[tag=Mar,tag=!Head] run data merge entity @s {Fire:10s}
scoreboard players add @e[tag=NPC] walking 0
scoreboard players add @e[tag=NPC] walk 0
execute as @e[tag=Mar] at @s run tp @s ~ ~ ~

#
execute as @e[name=Giant2] at @s run tp @e[tag=legR,limit=1,sort=nearest,tag=Mar2] ^0.04 ^-0.55 ^
effect give @e[name=Giant2] minecraft:invisibility 1000 1 true
execute as @e[name=Giant2] at @s run tp @e[tag=legL,limit=1,sort=nearest,tag=Mar2] ^-0.04 ^-0.55 ^
execute as @e[name=Giant2] at @s run tp @e[tag=Body,limit=1,sort=nearest,tag=Mar2] ~ ~ ~
execute as @e[name=Giant2] at @s positioned ~ ~ ~ run tp @e[tag=armR,limit=1,sort=nearest,tag=Mar2] ^-0.002 ^ ^
execute as @e[name=Giant2] at @s positioned ~ ~ ~ run tp @e[tag=armL,limit=1,sort=nearest,tag=Mar2] ^0.002 ^ ^
execute as @e[name=Giant2] at @s run tp @e[tag=Head,limit=1,sort=nearest,tag=Mar2] ~ ~ ~
execute as @e[tag=Mar2] store result entity @s Rotation[0] float 1 run data get entity @e[name=Giant2,limit=1,sort=nearest] Rotation[0]
execute as @e[tag=Mar2,tag=!Head] run data merge entity @s {Fire:10s}
scoreboard players set -1 walk -1
execute as @e[tag=Mar2] at @s run tp @s ~ ~ ~


execute as @e[name=Giant3] at @s run tp @e[tag=legR,limit=1,sort=nearest,tag=Mar3] ^0.04 ^-0.55 ^
effect give @e[name=Giant3] minecraft:invisibility 1000 1 true
execute as @e[name=Giant3] at @s run tp @e[tag=legL,limit=1,sort=nearest,tag=Mar3] ^-0.04 ^-0.55 ^
execute as @e[name=Giant3] at @s run tp @e[tag=Body,limit=1,sort=nearest,tag=Mar3] ~ ~ ~
execute as @e[name=Giant3] at @s positioned ~ ~ ~ run tp @e[tag=armR,limit=1,sort=nearest,tag=Mar3] ^-0.002 ^ ^
execute as @e[name=Giant3] at @s positioned ~ ~ ~ run tp @e[tag=armL,limit=1,sort=nearest,tag=Mar3] ^0.002 ^ ^
execute as @e[name=Giant3] at @s run tp @e[tag=Head,limit=1,sort=nearest,tag=Mar3] ~ ~ ~
execute as @e[tag=Mar3] store result entity @s Rotation[0] float 1 run data get entity @e[name=Giant3,limit=1,sort=nearest] Rotation[0]
execute as @e[tag=Mar3,tag=!Head] run data merge entity @s {Fire:10s}
scoreboard players set -1 walk -1
execute as @e[tag=Mar3] at @s run tp @s ~ ~ ~

execute as @e[name=Giant4] at @s run tp @e[tag=legR,limit=1,sort=nearest,tag=Mar4] ^0.04 ^-0.55 ^
effect give @e[name=Giant4] minecraft:invisibility 1000 1 true
execute as @e[name=Giant4] at @s run tp @e[tag=legL,limit=1,sort=nearest,tag=Mar4] ^-0.04 ^-0.55 ^
execute as @e[name=Giant4] at @s run tp @e[tag=Body,limit=1,sort=nearest,tag=Mar4] ~ ~ ~
execute as @e[name=Giant4] at @s positioned ~ ~ ~ run tp @e[tag=armR,limit=1,sort=nearest,tag=Mar4] ^-0.002 ^ ^
execute as @e[name=Giant4] at @s positioned ~ ~ ~ run tp @e[tag=armL,limit=1,sort=nearest,tag=Mar4] ^0.002 ^ ^
execute as @e[name=Giant4] at @s run tp @e[tag=Head,limit=1,sort=nearest,tag=Mar4] ~ ~ ~
execute as @e[tag=Mar4] store result entity @s Rotation[0] float 1 run data get entity @e[name=Giant4,limit=1,sort=nearest] Rotation[0]
execute as @e[tag=Mar4,tag=!Head] run data merge entity @s {Fire:10s}
scoreboard players set -1 walk -1
execute as @e[tag=Mar4] at @s run tp @s ~ ~ ~


execute as @e[tag=NPC] if entity @s[scores={walk=0},tag=walking] run scoreboard players operation @s walk = reach walk
execute as @e[tag=NPC] if entity @s[tag=!walking,scores={walking=1..}] run scoreboard players set @s walk 0
execute as @e[tag=NPC] if entity @s[tag=!walking,scores={walking=..-1}] run scoreboard players set @s walk 0
execute as @e[tag=NPC] if score @s walking = @s walk run scoreboard players operation @s walk *= -1 walk
execute as @e[tag=NPC] if score @s walking < @s walk run scoreboard players operation @s walking += speed walk
execute as @e[tag=NPC] if score @s walking > @s walk run scoreboard players operation @s walking -= speed walk

execute as @e[tag=armR] run data merge entity @s {Invisible:1b,Pose:{Head:[0.1f,0.1f,0.1f]},Marker:1b}
execute as @e[tag=armL] run data merge entity @s {Invisible:1b,Pose:{Head:[0.1f,0.1f,0.1f]},Marker:1b}
execute as @e[tag=legR] run data merge entity @s {Invisible:1b,Pose:{Head:[0.1f,0.1f,0.1f]},Marker:1b}
execute as @e[tag=legL] run data merge entity @s {Invisible:1b,Pose:{Head:[0.1f,0.1f,0.1f]},Marker:1b}
execute as @e[name=Giant] store result entity @e[tag=armR,limit=1,sort=nearest,tag=Mar] Pose.Head[0] float 1.4 run scoreboard players get @s walking
execute as @e[name=Giant] store result entity @e[tag=armL,limit=1,sort=nearest,tag=Mar] Pose.Head[0] float -1.4 run scoreboard players get @s walking
execute as @e[name=Giant] store result entity @e[tag=legR,limit=1,sort=nearest,tag=Mar] Pose.Head[0] float -1.4 run scoreboard players get @s walking
execute as @e[name=Giant] store result entity @e[tag=legL,limit=1,sort=nearest,tag=Mar] Pose.Head[0] float 1.4 run scoreboard players get @s walking
execute as @e[name=Giant2] store result entity @e[tag=armR,limit=1,sort=nearest,tag=Mar2] Pose.Head[0] float 1.4 run scoreboard players get @s walking
execute as @e[name=Giant2] store result entity @e[tag=armL,limit=1,sort=nearest,tag=Mar2] Pose.Head[0] float -1.4 run scoreboard players get @s walking
execute as @e[name=Giant2] store result entity @e[tag=legR,limit=1,sort=nearest,tag=Mar2] Pose.Head[0] float -1.4 run scoreboard players get @s walking
execute as @e[name=Giant2] store result entity @e[tag=legL,limit=1,sort=nearest,tag=Mar2] Pose.Head[0] float 1.4 run scoreboard players get @s walking
execute as @e[name=Giant3] store result entity @e[tag=armR,limit=1,sort=nearest,tag=Mar3] Pose.Head[0] float 1.4 run scoreboard players get @s walking
execute as @e[name=Giant3] store result entity @e[tag=armL,limit=1,sort=nearest,tag=Mar3] Pose.Head[0] float -1.4 run scoreboard players get @s walking
execute as @e[name=Giant3] store result entity @e[tag=legR,limit=1,sort=nearest,tag=Mar3] Pose.Head[0] float -1.4 run scoreboard players get @s walking
execute as @e[name=Giant3] store result entity @e[tag=legL,limit=1,sort=nearest,tag=Mar3] Pose.Head[0] float 1.4 run scoreboard players get @s walking
execute as @e[name=Giant4] store result entity @e[tag=armR,limit=1,sort=nearest,tag=Mar4] Pose.Head[0] float 1.4 run scoreboard players get @s walking
execute as @e[name=Giant4] store result entity @e[tag=armL,limit=1,sort=nearest,tag=Mar4] Pose.Head[0] float -1.4 run scoreboard players get @s walking
execute as @e[name=Giant4] store result entity @e[tag=legR,limit=1,sort=nearest,tag=Mar4] Pose.Head[0] float -1.4 run scoreboard players get @s walking
execute as @e[name=Giant4] store result entity @e[tag=legL,limit=1,sort=nearest,tag=Mar4] Pose.Head[0] float 1.4 run scoreboard players get @s walking

execute as @e[tag=NPC,tag=still,tag=!invert] run scoreboard players add @s standTimer 1
execute as @e[tag=NPC,tag=still,tag=invert] run scoreboard players remove @s standTimer 1
execute as @e[tag=NPC,tag=still] if score @s standTimer matches 0 run tag @s remove invert
execute as @e[tag=NPC,tag=still] if score @s standTimer matches 45 run tag @s add invert
execute as @e[tag=NPC,tag=!still,scores={standTimer=1..}] run scoreboard players remove @s standTimer 1
execute as @e[tag=NPC,tag=!still] run tag @s remove invert

execute as @e[name=Giant,scores={standTimer=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar] Pose.Head[2] float 0.07 run scoreboard players get @s standTimer
execute as @e[name=Giant,scores={standTimer=1..}] at @s store result entity @e[tag=armL,limit=1,tag=Mar] Pose.Head[2] float -0.07 run scoreboard players get @s standTimer
execute as @e[name=Giant2,scores={standTimer=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar2] Pose.Head[2] float 0.07 run scoreboard players get @s standTimer
execute as @e[name=Giant2,scores={standTimer=1..}] at @s store result entity @e[tag=armL,limit=1,tag=Mar2] Pose.Head[2] float -0.07 run scoreboard players get @s standTimer
execute as @e[name=Giant3,scores={standTimer=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar3] Pose.Head[2] float 0.07 run scoreboard players get @s standTimer
execute as @e[name=Giant3,scores={standTimer=1..}] at @s store result entity @e[tag=armL,limit=1,tag=Mar3] Pose.Head[2] float -0.07 run scoreboard players get @s standTimer
execute as @e[name=Giant4,scores={standTimer=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar4] Pose.Head[2] float 0.07 run scoreboard players get @s standTimer
execute as @e[name=Giant4,scores={standTimer=1..}] at @s store result entity @e[tag=armL,limit=1,tag=Mar4] Pose.Head[2] float -0.07 run scoreboard players get @s standTimer

execute as @e[tag=NPC,tag=swing,tag=!invert2] run scoreboard players add @s swing 9
execute as @e[tag=NPC,tag=swing,tag=invert2] run scoreboard players remove @s swing 9
execute as @e[tag=NPC,tag=swing,tag=invert2] if score @s swing matches 0 run tag @s remove invert2
execute as @e[tag=NPC,tag=swing,tag=!invert2] if score @s swing matches 0 run tag @s remove swing
execute as @e[tag=NPC,tag=swing] if score @s swing matches 45 run tag @s add invert2
execute as @e[tag=NPC,tag=!swing,scores={swing=1..}] run scoreboard players remove @s swing 9
execute as @e[tag=NPC,tag=!swing] run tag @s remove invert2

execute as @e[name=Giant,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar] Pose.Head[2] float 0.35 run scoreboard players get @s swing
execute as @e[name=Giant,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar] Pose.Head[1] float -0.25 run scoreboard players get @s swing
execute as @e[name=Giant,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar] Pose.Head[0] float -1.85 run scoreboard players get @s swing
execute as @e[name=Giant,scores={swing=1..}] at @s store result entity @e[tag=armL,limit=1,tag=Mar] Pose.Head[0] float -0.23 run scoreboard players get @s swing
execute as @e[name=Giant2,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar2] Pose.Head[2] float 0.35 run scoreboard players get @s swing
execute as @e[name=Giant2,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar2] Pose.Head[1] float -0.25 run scoreboard players get @s swing
execute as @e[name=Giant2,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar2] Pose.Head[0] float -0.85 run scoreboard players get @s swing
execute as @e[name=Giant2,scores={swing=1..}] at @s store result entity @e[tag=armL,limit=1,tag=Mar2] Pose.Head[0] float 0.23 run scoreboard players get @s swing
execute as @e[name=Giant3,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar3] Pose.Head[2] float 0.35 run scoreboard players get @s swing
execute as @e[name=Giant3,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar3] Pose.Head[1] float -0.25 run scoreboard players get @s swing
execute as @e[name=Giant3,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar3] Pose.Head[0] float -0.85 run scoreboard players get @s swing
execute as @e[name=Giant3,scores={swing=1..}] at @s store result entity @e[tag=armL,limit=1,tag=Mar3] Pose.Head[0] float 0.23 run scoreboard players get @s swing
execute as @e[name=Giant4,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar4] Pose.Head[2] float 0.35 run scoreboard players get @s swing
execute as @e[name=Giant4,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar4] Pose.Head[1] float -0.25 run scoreboard players get @s swing
execute as @e[name=Giant4,scores={swing=1..}] at @s store result entity @e[tag=armR,limit=1,tag=Mar4] Pose.Head[0] float -0.85 run scoreboard players get @s swing
execute as @e[name=Giant4,scores={swing=1..}] at @s store result entity @e[tag=armL,limit=1,tag=Mar4] Pose.Head[0] float 0.23 run scoreboard players get @s swing









