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


#spread the markers around
spreadplayers ~ ~ 1 55 false @e[type=marker,tag=LilyCheck]

#summon another one on top of the main marker
summon minecraft:marker ~ ~ ~ {Tags:["LilyCheck"]}


#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=LilyCheck] run execute at @s positioned ~ ~ ~ run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run execute unless block ~ ~-1 ~ water run execute at @s run tp @s ~ ~-1 ~
execute as @e[type=marker,tag=LilyCheck] run execute at @s positioned ~ ~ ~ run execute if block ~ ~-1 ~ #suhc:bloodboltpassthrough run execute unless block ~ ~-1 ~ water run execute at @s run tp @s ~ ~-1 ~

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


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

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

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