execute at @e[type=end_crystal,distance=..200] run fill ~-6 91 ~-6 ~6 130 ~6 air replace obsidian
#execute at @e[type=end_crystal,distance=..200,tag=!SummonedCrys] run summon end_crystal ~ 92 ~ {Tags:["SummonedCrys"]}
#kill @e[type=end_crystal,distance=..200,tag=!SummonedCrys]

#iron bars for middle bit
fill 1 90 -38 1 90 -2 iron_bars
fill 2 90 1 38 90 1 minecraft:iron_bars
fill -1 90 2 -1 90 38 minecraft:iron_bars
fill -2 90 -1 -38 90 -1 minecraft:iron_bars

#makes the main wall
summon armor_stand 41 90 0 {Tags:["KyuEndWall"],NoGravity:1b,Invulnerable:1b,Marker:1b,Invisible:1b,Silent:1b,Silent:1b,Rotation:[-180F,0F]}
summon armor_stand -41 90 0 {Tags:["KyuEndWall"],NoGravity:1b,Invulnerable:1b,Marker:1b,Invisible:1b,Silent:1b,Silent:1b,Rotation:[0F,0F]}
summon armor_stand 0 90 41 {Tags:["KyuEndWall"],NoGravity:1b,Invulnerable:1b,Marker:1b,Invisible:1b,Silent:1b,Silent:1b,Rotation:[-90F,0F]}
summon armor_stand 0 90 -41 {Tags:["KyuEndWall"],NoGravity:1b,Invulnerable:1b,Marker:1b,Invisible:1b,Silent:1b,Silent:1b,Rotation:[90F,0F]}
execute as @e[type=armor_stand,tag=KyuEndWall] run execute at @s run function zzzzdonotuse:enderdragon/summonwall2


#wall corner entrances
summon armor_stand 29 90 -29 {Tags:["KyuEndWallC","KyuEndWallC1"],NoGravity:1b,Invulnerable:1b,Marker:1b,Invisible:1b,Silent:1b,Silent:1b,Rotation:[45F,0F]}
summon armor_stand -29 90 29 {Tags:["KyuEndWallC","KyuEndWallC2"],NoGravity:1b,Invulnerable:1b,Marker:1b,Invisible:1b,Silent:1b,Silent:1b,Rotation:[-135F,0F]}
summon armor_stand -29 90 -29 {Tags:["KyuEndWallC","KyuEndWallC3"],NoGravity:1b,Invulnerable:1b,Marker:1b,Invisible:1b,Silent:1b,Silent:1b,Rotation:[-45F,0F]}
summon armor_stand 29 90 29 {Tags:["KyuEndWallC","KyuEndWallC4"],NoGravity:1b,Invulnerable:1b,Marker:1b,Invisible:1b,Silent:1b,Silent:1b,Rotation:[135F,0F]}
execute as @e[type=armor_stand,tag=KyuEndWallC] run execute at @s run function zzzzdonotuse:enderdragon/findground
execute at @e[type=armor_stand,tag=KyuEndWallC1] run setblock 29 ~ -29 minecraft:structure_block[mode=load]{name:"suhc:wallentrance",posX:-5,posZ:-5,posY:0,rotation:NONE,mirror:NONE,mode:LOAD,ignoreEntities:1b} destroy
execute at @e[type=armor_stand,tag=KyuEndWallC2] run setblock -29 ~ 29 minecraft:structure_block[mode=load]{name:"suhc:wallentrance",posX:5,posZ:5,posY:0,rotation:CLOCKWISE_180,mirror:NONE,mode:LOAD,ignoreEntities:1b} destroy
execute at @e[type=armor_stand,tag=KyuEndWallC3] run setblock -29 ~ -29 minecraft:structure_block[mode=load]{name:"suhc:wallentrance",posX:-5,posZ:5,posY:0,rotation:COUNTERCLOCKWISE_90,mirror:NONE,mode:LOAD,ignoreEntities:1b} destroy
execute at @e[type=armor_stand,tag=KyuEndWallC4] run setblock 29 ~ 29 minecraft:structure_block[mode=load]{name:"suhc:wallentrance",posX:5,posZ:-5,posY:0,rotation:CLOCKWISE_90,mirror:NONE,mode:LOAD,ignoreEntities:1b} destroy
execute at @e[type=armor_stand,tag=KyuEndWallC1] run setblock 29 ~1 -29 redstone_block
execute at @e[type=armor_stand,tag=KyuEndWallC2] run setblock -29 ~1 29 redstone_block
execute at @e[type=armor_stand,tag=KyuEndWallC3] run setblock -29 ~1 -29 redstone_block
execute at @e[type=armor_stand,tag=KyuEndWallC4] run setblock 29 ~1 29 redstone_block
kill @e[type=armor_stand,tag=KyuEndWallC]



#staircases in each quadrant
setblock 1 62 -38 minecraft:structure_block[mode=load]{name:"suhc:wallstairs",posX:-5,posZ:0,posY:1,rotation:NONE,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
setblock 1 63 -38 minecraft:redstone_block
execute positioned 1 63 -38 run tag @e[type=armor_stand,tag=KyuWallStair2,distance=..10] add WestStairs
setblock -1 62 38 minecraft:structure_block[mode=load]{name:"suhc:wallstairs",posX:5,posZ:0,posY:1,rotation:CLOCKWISE_180,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
setblock -1 63 38 minecraft:redstone_block
execute positioned -1 63 38 run tag @e[type=armor_stand,tag=KyuWallStair2,distance=..10] add EastStairs
execute positioned -1 63 38 run execute as @e[type=armor_stand,tag=KyuWallStair2,distance=..10] run execute at @s run tp @s ~ ~ ~ 90 ~
setblock 38 62 1 minecraft:structure_block[mode=load]{name:"suhc:wallstairs",posX:0,posZ:-5,posY:1,rotation:CLOCKWISE_90,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
setblock 38 63 1 minecraft:redstone_block
execute positioned 38 63 1 run tag @e[type=armor_stand,tag=KyuWallStair2,distance=..10] add NorthStairs
execute positioned 38 63 1 run execute as @e[type=armor_stand,tag=KyuWallStair2,distance=..10] run execute at @s run tp @s ~ ~ ~ 0 ~
setblock -38 62 -1 minecraft:structure_block[mode=load]{name:"suhc:wallstairs",posX:0,posZ:5,posY:1,rotation:COUNTERCLOCKWISE_90,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
setblock -38 63 -1 minecraft:redstone_block
execute positioned -38 63 -1 run tag @e[type=armor_stand,tag=KyuWallStair2,distance=..10] add SouthStairs
execute positioned -38 63 -1 run execute as @e[type=armor_stand,tag=KyuWallStair2,distance=..10] run execute at @s run tp @s ~ ~ ~ ~-180 ~
execute at @e[type=armor_stand,tag=KyuWallStair] run fill ~ ~ ~ ~ ~-15 ~ polished_blackstone_brick_wall replace air
kill @e[type=armor_stand,tag=KyuWallStair]
execute as @e[type=armor_stand,tag=KyuWallStair2] run function zzzzdonotuse:enderdragon/buildstairs
kill @e[type=armor_stand,tag=KyuWallStair2]


#end crystals in the middle area
setblock 0 91 0 minecraft:structure_block[mode=load]{name:"suhc:middlebit",posX:-2,posZ:-2,posY:-8,rotation:NONE,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy
setblock 0 92 0 redstone_block

#choose 6-10 crystal spawns on top of the wall
execute if predicate suhc:25percent run tag @e[type=armor_stand,tag=KyuCrystalSumm,limit=6,sort=random] add SpawnCrystalKyu
execute if predicate suhc:25percent run execute unless entity @e[type=armor_stand,tag=SpawnCrystalKyu] run tag @e[type=armor_stand,tag=KyuCrystalSumm,limit=7,sort=random] add SpawnCrystalKyu
execute if predicate suhc:25percent run execute unless entity @e[type=armor_stand,tag=SpawnCrystalKyu] run tag @e[type=armor_stand,tag=KyuCrystalSumm,limit=8,sort=random] add SpawnCrystalKyu
execute if predicate suhc:25percent run execute unless entity @e[type=armor_stand,tag=SpawnCrystalKyu] run tag @e[type=armor_stand,tag=KyuCrystalSumm,limit=9,sort=random] add SpawnCrystalKyu
execute unless entity @e[type=armor_stand,tag=SpawnCrystalKyu] run tag @e[type=armor_stand,tag=KyuCrystalSumm,limit=10,sort=random] add SpawnCrystalKyu

function zzzzdonotuse:enderdragon/spawncrystals

#execute as @e[type=armor_stand,tag=SpawnCrystalKyu] run function zzzzdonotuse:enderdragon/spawncrystals




#execute as @e[type=armor_stand,tag=SpawnCrystalKyu] run setblock ~ ~ ~ minecraft:structure_block[mode=load]{name:"suhc:endcrystals",posX:-4,posZ:-4,posY:-1,rotation:NONE,mirror:NONE,mode:LOAD,ignoreEntities:0b} destroy

execute as @e[type=armor_stand,tag=KyuCrystalWall] run execute at @s run execute if block ~ ~-1 ~ air run fill ~ ~ ~ ~ ~-40 ~ polished_blackstone_brick_wall replace air
kill @e[type=armor_stand,tag=KyuCrystalWall]

