######################################################################################################### *** PHASE 3 - CAVES *** ##########################################################################################################



# Portal_in creation #

execute unless block 0 65 0 minecraft:end_gateway run tellraw @a {"text":"A portal has appeared !","italic":true,"color":"yellow"}
execute unless block 0 65 0 minecraft:end_gateway run playsound minecraft:entity.illusioner.cast_spell block @a 0 66 0
execute run fill 0 65 0 0 66 0 minecraft:end_gateway
execute run setblock 0 64 0 minecraft:bedrock



# Teleportation_in #

execute as @a at @s in minecraft:overworld if predicate simply_oneblock:portal run execute in simply_oneblock:phase_3 run tp @s 5 73 0



# Dungeon set #

execute as @a in simply_oneblock:phase_3 run execute if block 0 76 0 minecraft:air run place template simply_oneblock:phase_3 -1 70 -15

execute in simply_oneblock:phase_3 run execute if block 14 73 -14 minecraft:air unless block 14 71 -15 reinforced_deepslate run setblock 14 73 -14 minecraft:vault[facing=south]{config: {key_item: {components: {"minecraft:custom_name": "Graveyard Key"}, count: 1, id: "minecraft:trial_key"}, loot_table: "simply_oneblock:trial_gate"}}

execute in simply_oneblock:phase_3 run execute if block 28 73 0 minecraft:air unless block 29 71 0 reinforced_deepslate run setblock 28 73 0 minecraft:vault[facing=west]{config: {key_item: {components: {"minecraft:custom_name": "Crypt Key"}, count: 1, id: "minecraft:trial_key"}, loot_table: "simply_oneblock:trial_gate"}}

execute in simply_oneblock:phase_3 run execute if block 14 73 14 minecraft:air unless block 14 71 15 reinforced_deepslate run setblock 14 73 14 minecraft:vault[facing=north]{config: {key_item: {components: {"minecraft:custom_name": "Ossuary Key"}, count: 1, id: "minecraft:trial_key"}, loot_table: "simply_oneblock:trial_gate"}}

execute in simply_oneblock:phase_3 run execute if block 0 73 0 minecraft:air unless block -1 71 0 reinforced_deepslate run setblock 0 73 0 minecraft:vault[facing=east]{config: {key_item: {components: {"minecraft:custom_name": "Bunker Key"}, count: 1, id: "minecraft:trial_key"}, loot_table: "simply_oneblock:trial_gate"}}



execute in simply_oneblock:phase_3 run execute if block 14 73 -14 minecraft:vault{server_data:{total_ejections_needed: 3}} run place template simply_oneblock:phase_3_zombie -1 70 -45
execute in simply_oneblock:phase_3 run execute if block 14 73 -14 minecraft:vault{server_data:{total_ejections_needed: 3}} run playsound minecraft:entity.lightning_bolt.thunder block @a 14 73 -14
execute in simply_oneblock:phase_3 run execute if block 14 73 -14 minecraft:vault{server_data:{total_ejections_needed: 3}} run fill 15 72 -14 13 74 -14 air

execute in simply_oneblock:phase_3 run execute if block 28 73 0 minecraft:vault{server_data:{total_ejections_needed: 3}} run place template simply_oneblock:phase_3_spider 29 70 -15
execute in simply_oneblock:phase_3 run execute if block 28 73 0 minecraft:vault{server_data:{total_ejections_needed: 3}} run playsound minecraft:entity.lightning_bolt.thunder block @a 28 73 0
execute in simply_oneblock:phase_3 run execute if block 28 73 0 minecraft:vault{server_data:{total_ejections_needed: 3}} run fill 28 72 1 28 74 -1 air

execute in simply_oneblock:phase_3 run execute if block 14 73 14 minecraft:vault{server_data:{total_ejections_needed: 3}} run place template simply_oneblock:phase_3_skeleton -1 70 15
execute in simply_oneblock:phase_3 run execute if block 14 73 14 minecraft:vault{server_data:{total_ejections_needed: 3}} run playsound minecraft:entity.lightning_bolt.thunder block @a 14 73 14
execute in simply_oneblock:phase_3 run execute if block 14 73 14 minecraft:vault{server_data:{total_ejections_needed: 3}} run fill 13 72 14 15 74 14 air

execute in simply_oneblock:phase_3 run execute if block 0 73 0 minecraft:vault{server_data:{total_ejections_needed: 3}} run place template simply_oneblock:phase_3_creeper -31 70 -15
execute in simply_oneblock:phase_3 run execute if block 0 73 0 minecraft:vault{server_data:{total_ejections_needed: 3}} run playsound minecraft:entity.lightning_bolt.thunder block @a 0 73 0
execute in simply_oneblock:phase_3 run execute if block 0 73 0 minecraft:vault{server_data:{total_ejections_needed: 3}} run fill 0 72 -1 0 74 1 air



# Portal_out creation #

execute in simply_oneblock:phase_3 unless block 16 71 1 minecraft:end_gateway if block -16 73 0 minecraft:trial_spawner[trial_spawner_state=ejecting_reward] run tellraw @a {"text":"A portal has appeared !","italic":true,"color":"yellow"}

execute in simply_oneblock:phase_3 unless block 16 71 1 minecraft:end_gateway if block -16 73 0 minecraft:trial_spawner[trial_spawner_state=ejecting_reward] run playsound minecraft:entity.illusioner.cast_spell block @a 13 74 -1

execute in simply_oneblock:phase_3 unless block 16 71 1 minecraft:end_gateway if block -16 73 0 minecraft:trial_spawner[trial_spawner_state=ejecting_reward] run execute in simply_oneblock:phase_3 run fill 12 71 -1 12 71 1 minecraft:end_gateway
execute in simply_oneblock:phase_3 unless block 16 71 1 minecraft:end_gateway if block -16 73 0 minecraft:trial_spawner[trial_spawner_state=ejecting_reward] run execute in simply_oneblock:phase_3 run fill 13 71 -2 15 71 2 minecraft:end_gateway
execute in simply_oneblock:phase_3 unless block 16 71 1 minecraft:end_gateway if block -16 73 0 minecraft:trial_spawner[trial_spawner_state=ejecting_reward] run execute in simply_oneblock:phase_3 run fill 16 71 -1 16 71 1 minecraft:end_gateway



# Teleportation_back #

execute as @a at @s in simply_oneblock:phase_3 if predicate simply_oneblock:portal if score fake_player ib_minedcount matches 550 run execute in minecraft:overworld run fill 0 64 0 0 66 0 minecraft:air