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


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

#sometimes the markers get placed on blocks such as leaves, flowers or tall_grass, so move them down if so
execute as @e[type=marker,tag=LogCabCheck] run execute at @s positioned ~ ~ ~ run function zzzzdonotuse:structures/logcabin/logcabinmovedown

#run the block-check function as(and at) each marker, 1 block above ground level as thats where the structure block is located within the structure.nbt
execute as @e[type=marker,tag=LogCabCheck] run execute at @s positioned ~ ~1 ~ run function zzzzdonotuse:structures/logcabin/logcabinblockcheck

#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=LogCabCheck,limit=1,sort=random,distance=..150]

#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=LogCabCheck,distance=..4,scores={KyuDummy=13..}] run setblock ~ ~1 ~ minecraft:structure_block[mode=load]{name:"suhc:logcabin",posX:-9,posZ:-6,posY:-4,rotation:NONE,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
execute at @s run execute if entity @e[type=marker,tag=LogCabCheck,distance=..4,scores={KyuDummy=13..}] run setblock ~ ~2 ~ redstone_block
execute at @s run execute if entity @e[type=marker,tag=LogCabCheck,distance=..4,scores={KyuDummy=13..}] run tag @s add GotPlaceSpot
execute at @s run execute if entity @e[type=marker,tag=LogCabCheck,distance=..4,scores={KyuDummy=13..}] run scoreboard players set @s KyuDummy5 20

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