#summon a marker, if it's on top of a tree, then kill it
summon minecraft:marker ~ ~ ~ {Tags:["StalagmiteYLevel"]}
execute as @e[limit=1,sort=nearest,type=marker,tag=StalagmiteYLevel] run execute at @s run execute if block ~ ~-1 ~ #leaves run kill @s

#randomly select 1 of the 3 stalagmite shapes
execute if predicate suhc:33percent run tag @e[distance=..2,type=marker,tag=StalagmiteYLevel] add Stalagmite1
execute if predicate suhc:50percent run tag @e[distance=..2,type=marker,tag=StalagmiteYLevel,tag=!Stalagmite1] add Stalagmite2
tag @e[distance=..2,type=marker,tag=StalagmiteYLevel,tag=!Stalagmite1,tag=!Stalagmite2] add Stalagmite3

#depending on which shape was picked, run the appropriate function
execute at @e[distance=..2,type=marker,tag=StalagmiteYLevel,tag=Stalagmite1] run function zzzzdonotuse:structures/stalagmite/stalagmite1spawning
execute at @e[distance=..2,type=marker,tag=StalagmiteYLevel,tag=Stalagmite2] run function zzzzdonotuse:structures/stalagmite/stalagmite2spawning
execute at @e[distance=..2,type=marker,tag=StalagmiteYLevel,tag=Stalagmite3] run function zzzzdonotuse:structures/stalagmite/stalagmite3spawning

#get the main marker's Y coord, stored as a scoreboard
execute as @e[type=marker,distance=..2,tag=StalagmiteYLevel] run execute store result score @s KyuDummy run data get entity @s Pos[1] 1

#running as the markers spawned from the function above, run the following function
##the function, in short, checks the borders of the stalagmite(via the markers from the function above) to see if the blocks below are solid blocks, and will move them downwards if the block is NON-SOLID(air, water, flowers, etc)
###each marker runs the command individually, and the MAIN MARKER's KyuDummy scoreboard will be set to the scoreboard of the marker that has the lowest Y coord
####super tl;dr - move the MAIN MARKER down to an appropriate Y coordinate
execute at @s run execute as @e[type=marker,tag=StalagmiteLook,distance=..7] run function zzzzdonotuse:structures/stalagmite/stalagmitecheckylevel

#set the MAIN MARKER's Y coord to that of its KyuDummy scoreboard, which was set from the function above
execute as @e[type=marker,distance=..2,tag=StalagmiteYLevel] run execute store result entity @s Pos[1] double 1 run scoreboard players get @s KyuDummy

#trees
execute as @e[type=marker,tag=StalagmiteYLevel,limit=1,sort=nearest] run execute at @s run function zzzzdonotuse:structures/stalagmite/checktrees
#depending on which shape was picked, summon the appropriate structure
execute at @e[limit=1,sort=nearest,type=marker,tag=StalagmiteYLevel,tag=Stalagmite1] run setblock ~ ~ ~ minecraft:structure_block[mode=load]{name:"suhc:genericpillar",posX:-3,posZ:-3,posY:0,rotation:NONE,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
execute at @e[limit=1,sort=nearest,type=marker,tag=StalagmiteYLevel,tag=Stalagmite2] run setblock ~ ~ ~ minecraft:structure_block[mode=load]{name:"suhc:genericpillar2",posX:-3,posZ:-4,posY:0,rotation:NONE,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
execute at @e[limit=1,sort=nearest,type=marker,tag=StalagmiteYLevel,tag=Stalagmite3] run setblock ~ ~ ~ minecraft:structure_block[mode=load]{name:"suhc:genericpillar3",posX:-3,posZ:-4,posY:0,rotation:NONE,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
execute at @e[limit=1,sort=nearest,type=marker,tag=StalagmiteYLevel] run setblock ~ ~1 ~ redstone_block
tag @s add GotPlaceSpot
scoreboard players set @s KyuDummy5 20
execute as @s run execute at @s run execute as @e[limit=1,sort=nearest,type=marker,tag=StalagmiteYLevel] run function zzzzdonotuse:structures/stalagmite/stalagmitebiomes


#kill the MAIN MARKER
kill @e[limit=1,sort=nearest,type=marker,tag=StalagmiteYLevel]

#setblock ~ ~ ~ minecraft:structure_block[mode=load]{name:"suhc:treecove",posX:-13,posZ:-13,posY:1,rotation:NONE,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
