execute if entity @e[tag=quest4_dog.ai,tag=walk] as @e[tag=aj.quest4_dog.root] at @s if entity @a[distance=..3] run function lbdm:quest4/dog/animations/idle
execute if entity @e[tag=quest4_dog.ai,tag=idle] as @e[tag=aj.quest4_dog.root] at @s unless entity @a[distance=..3] run function lbdm:quest4/dog/animations/walk

data merge entity @n[tag=quest4_dog.ai,tag=walk] {wander_target:[I;0,0,0]}
execute as @e[tag=quest4_dog.ai,tag=walk] at @s run data modify entity @s wander_target[0] set from entity @p[sort=nearest] Pos[0]
execute as @e[tag=quest4_dog.ai,tag=walk] at @s run data modify entity @s wander_target[1] set from entity @p[sort=nearest] Pos[1]
execute as @e[tag=quest4_dog.ai,tag=walk] at @s run data modify entity @s wander_target[2] set from entity @p[sort=nearest] Pos[2]

execute at @e[tag=quest4_dog.ai] run tp @e[tag=quest4_dog] ~ ~ ~ ~ ~
item replace entity @e[tag=quest4_dog.ai] weapon.mainhand with air