##when first entering the end:

kill @e[type=minecraft:ender_dragon]

-> check if portal is in the center
    -> if so, continue, otherwise, check for the next few seconds

#clear end gateways
execute in minecraft:the_end positioned 96 75 0 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned 91 75 29 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned 77 75 56 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned 56 75 77 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned 29 75 91 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned 0 75 96 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned -29 75 91 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned -56 75 77 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned -77 75 56 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned -91 75 29 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned -96 75 0 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned -91 75 -29 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned -77 75 -56 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned -56 75 -77 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned -29 75 -91 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned 0 75 -96 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned 29 75 -91 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned 56 75 -77 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned 77 75 -56 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air
execute in minecraft:the_end positioned 91 75 -29 run fill ~-1 ~-2 ~-1 ~1 ~2 ~1 minecraft:air

#set end generation markers, tick immediately
execute in minecraft:the_end run summon minecraft:marker -16 0 -16 {Tags:["end_gen_marker","priority"],data:{phase:1,coordinate:g7}}
execute in minecraft:the_end run summon minecraft:marker 0 0 -16 {Tags:["end_gen_marker","priority"],data:{phase:1,coordinate:g8}}
execute in minecraft:the_end run summon minecraft:marker -16 0 0 {Tags:["end_gen_marker","priority"],data:{phase:1,coordinate:h7}}
execute in minecraft:the_end run summon minecraft:marker 0 0 0 {Tags:["end_gen_marker","priority"],data:{phase:1,coordinate:h8}}

execute in minecraft:the_end positioned 0 0 0 as @e[type=minecraft:marker,tag=end_gen_marker,tag=priority,distance=..256] at @s function custom_ender_dragon:generate_end with entity @s data