data merge entity @e[type=minecraft:wandering_trader,limit=1,sort=nearest,tag=quest2_rawr_ai] {wander_target:[I;0,0,0]}

tp @e[tag=aj.quest2_rawr.root] @e[type=wandering_trader,limit=1,tag=quest2_rawr_ai]

execute as @e[tag=quest2_rawr_ai,sort=nearest,limit=1] at @s run data modify entity @s wander_target[0] set from entity @p[sort=nearest] Pos[0]
execute as @e[tag=quest2_rawr_ai,sort=nearest,limit=1] at @s run data modify entity @s wander_target[1] set from entity @p[sort=nearest] Pos[1]
execute as @e[tag=quest2_rawr_ai,sort=nearest,limit=1] at @s run data modify entity @s wander_target[2] set from entity @p[sort=nearest] Pos[2]

data merge entity 68bc90d5-7c04-490f-b490-e82025efb57a {Offers:{Recipes:[{buy:{id:"minecraft:air"}}]}}

execute as @e[tag=quest2_rawr_ai,limit=1,tag=!screamer] at @s if entity @p[distance=..2.45] run function lbdm:quest2/rawr/screamer

data merge entity @e[tag=quest2_rawr_ai,sort=nearest,limit=1] {Offers:{Recipes:[{buy:{id:"minecraft:air"}}]}}

# НЕ телепортировать бугагайку если он уже убрался
execute if data entity @n[tag=quest2_rawr_ai] {NoAI:1b} run return 0

# Шанс 1 к 200, что он телепортнётся за спину
execute store result score #rawr random run random value 1..200

# Проверка какое число
execute if score #rawr random matches 200 as @a at @s positioned ^ ^ ^-5 align y if block ~ ~ ~ air unless block ~ ~-1 ~ grass_block if block ~ ~-1 ~ mud_bricks run tp @e[tag=quest2_rawr_ai,sort=nearest,limit=1] ^ ^ ^-5
execute if score #rawr random matches 200 as @a at @s positioned ^ ^ ^-5 align y if block ~ ~ ~ air unless block ~ ~-1 ~ grass_block if block ~ ~-1 ~ mud_bricks run playsound ambient.cave master @s ~ ~ ~ 1 2
execute if score #rawr random matches 200 as @a at @s positioned ^ ^ ^-5 align y if block ~ ~ ~ air unless block ~ ~-1 ~ grass_block if block ~ ~-1 ~ packed_mud run tp @e[tag=quest2_rawr_ai,sort=nearest,limit=1] ^ ^ ^-5
execute if score #rawr random matches 200 as @a at @s positioned ^ ^ ^-5 align y if block ~ ~ ~ air unless block ~ ~-1 ~ grass_block if block ~ ~-1 ~ packed_mud run playsound ambient.cave master @s ~ ~ ~ 1 2