#summon a bunch of markers
summon minecraft:marker ~ ~ ~ {Tags:["BlastSmithCheck"]}
summon minecraft:marker ~ ~ ~ {Tags:["BlastSmithCheck"]}
summon minecraft:marker ~ ~ ~ {Tags:["BlastSmithCheck"]}
summon minecraft:marker ~ ~ ~ {Tags:["BlastSmithCheck"]}


spreadplayers ~ ~ 1 45 false @e[type=marker,tag=BlastSmithCheck]

#sometimes the markers get placed on blocks such as flowers or tall_grass, so move them down if so
execute as @e[type=marker,tag=BlastSmithCheck] run execute at @s positioned ~ ~ ~ run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run execute at @s run tp @s ~ ~-1 ~
execute as @e[type=marker,tag=BlastSmithCheck] run execute at @s positioned ~ ~ ~ run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run execute at @s run tp @s ~ ~-1 ~

#run the block-check function as(and at) each marker
execute as @e[type=marker,tag=BlastSmithCheck] run execute at @s run execute at @s run function zzzzdonotuse:structures/blastsmith/blastsmithblockcheck


#teleport the main marker to a random marker from above that survived the function run(which checks the structure borders for appropriate spawning conditions)
tp @s @e[type=marker,tag=BlastSmithCheck,limit=1,sort=random,distance=..130]

#if the main marker gets teleported successfuly to a marker with the appropriate conditions, place the structure
execute at @s run execute if entity @e[type=marker,tag=BlastSmithCheck,distance=..4,scores={KyuDummy=2}] run execute at @s positioned ~ 64 ~ run summon marker ~ ~ ~ {Tags:["KyuBlastSmith"]}
execute at @s run execute if entity @e[type=marker,tag=BlastSmithCheck,distance=..4,scores={KyuDummy=2}] run execute at @s positioned ~ 64 ~ run fill ~-17 ~ ~-17 ~17 ~ ~17 minecraft:repeating_command_block{auto:1b,Command:"execute as @e[type=marker,tag=KyuBlastSmith,distance=..40,limit=1,sort=nearest] run function zzzzdonotuse:structures/blastsmith/blastsmithtimer",TrackOutput:0} replace blue_terracotta
execute at @s run execute if entity @e[type=marker,tag=BlastSmithCheck,distance=..4,scores={KyuDummy=2}] run tag @s add GotPlaceSpot
execute at @s run execute if entity @e[type=marker,tag=BlastSmithCheck,distance=..4,scores={KyuDummy=2}] run scoreboard players set @s KyuDummy5 20
#execute at @s run execute if entity @e[type=marker,tag=BlastSmithCheck,distance=..4,scores={KyuDummy=3}] run fill ~ ~-1 ~ ~-2 ~-1 ~1 jungle_planks





#kill all the entities
kill @e[type=marker,tag=BlastSmithCheck]
#kill @s[type=!player]