function lbdm:main/loop with storage lbdm:main
execute as @e[tag=quest1_end] at @s unless data storage lbdm:main {quest:"e_elevator"} if entity @a[distance=..1] run function lbdm:queste/elevator_start
execute as @e[tag=quest2_start] at @s if data storage lbdm:main {quest:"2_dialogue"} if entity @a[distance=..1.5] run function lbdm:quest2/transformation/start
execute as @e[tag=quest3_end] at @s unless data storage lbdm:main {quest:"4_elevator"} if entity @a[distance=..1] run function lbdm:quest3/elevator/close
execute as @e[tag=quest4_start] at @s unless data storage lbdm:main {quest:"4_intro"} if entity @a[distance=..2] run function lbdm:quest4/transition/start
execute as @e[tag=quest4_end] at @s if data storage lbdm:main {quest:4} if entity @a[distance=..2] run title @a times 20 0 20
execute as @e[tag=quest4_end] at @s if data storage lbdm:main {quest:4} if entity @a[distance=..2] run title @a title {"text":"\uA000","font": "extra"}
execute as @e[tag=quest4_end] at @s if data storage lbdm:main {quest:4} if entity @a[distance=..2] run schedule function lbdm:the_end/start 20t
execute as @e[tag=quest4_end] at @s if data storage lbdm:main {quest:4} if entity @a[distance=..2] run kill @s
execute as @e[tag=the_end_portal] at @s if data storage lbdm:main {quest:"the_end"} if entity @a[distance=..2.5] run function lbdm:the_end/end
effect give @a resistance infinite 128 true
execute as @a[nbt={active_effects:[{id:"minecraft:luck"}]}] run function lbdm:the_end/box_open

execute as @a at @s if data storage lbdm:main {quest:"none"} if block ~ ~-1 ~ black_wool run function lbdm:main/start