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


#spread the markers around
spreadplayers ~ ~ 10 60 false @e[type=marker,tag=TaigaTowerCheck]

#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=TavernCheck] 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=TavernCheck] 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=TaigaTowerCheck] run execute at @s run function zzzzdonotuse:structures/taigatower/taigatowerblockcheck

#teleport the main marker to a random marker from above that survived the function run(which checks the wooden+stone supports for appropriate spawning conditions)
tp @s @e[type=marker,tag=TaigaTowerCheck,limit=1,sort=random,distance=..120]

#if the main marker gets teleported successfuly to a marker with the appropriate conditions, place the structure, and place a few stairs if needed to help it blend with the ground
execute at @s run execute if entity @e[type=marker,tag=TaigaTowerCheck,distance=..4,scores={KyuDummy=16}] run setblock ~ ~ ~ minecraft:structure_block[mode=load]{name:"suhc:taigatower",posX:-8,posZ:-7,posY:0,rotation:NONE,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
execute at @s run execute if entity @e[type=marker,tag=TaigaTowerCheck,distance=..4,scores={KyuDummy=16}] run setblock ~ ~1 ~ redstone_block
execute at @s run execute if entity @e[type=marker,tag=TaigaTowerCheck,distance=..4,scores={KyuDummy=16}] run execute positioned ~-5 ~ ~-5 run fill ~ ~ ~1 ~ ~ ~ minecraft:spruce_stairs[facing=east,half=bottom] replace #suhc:bloodboltpassthrough
execute at @s run execute if entity @e[type=marker,tag=TaigaTowerCheck,distance=..4,scores={KyuDummy=16}] run execute positioned ~-5 ~ ~-5 run fill ~ ~ ~1 ~ ~ ~ minecraft:spruce_stairs[facing=east,half=bottom] replace cave_air
execute at @s run execute if entity @e[type=marker,tag=TaigaTowerCheck,distance=..4,scores={KyuDummy=16}] run tag @s add GotPlaceSpot
execute at @s run execute if entity @e[type=marker,tag=TaigaTowerCheck,distance=..4,scores={KyuDummy=16}] run scoreboard players set @s KyuDummy5 20

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