execute at @s run execute store result score #ECSpell KyuDummy5 run locate structure suhc:enchantedcavernbase

#execute as @s[tag=LocateSpell2,tag=!LocatorUpgrade2] run execute at @s run execute if score #ECSpell KyuDummy5 matches 0..20 run tellraw @s ["",{"text":"You're inside an enchanted cavern right now! Why are you using this spell?","color":"green"}]

tag @s remove KyuInOW
tag @s[nbt={Dimension:"minecraft:overworld"}] add KyuInOW
execute as @s[tag=!KyuInOW,tag=LocateSpell2] run execute at @s run tellraw @s ["",{"text":"This spell will only work in the overworld.","color":"gold"}]


execute as @s[tag=KyuInOW,tag=LocateSpell2,tag=!LocatorUpgrade2] run execute at @s run execute if entity @e[tag=ECChestMarker,distance=..18] run execute if score #ECSpell KyuDummy5 matches 0..40 run tellraw @s ["",{"text":"You're inside an enchanted cavern right now! Why are you using this spell?","color":"aqua"}]
execute as @s[tag=KyuInOW,tag=LocateSpell2,tag=!LocatorUpgrade2] run execute at @s run execute unless entity @e[tag=ECChestMarker,distance=..18] run execute if score #ECSpell KyuDummy5 matches 0..40 run tellraw @s ["",{"text":"There is an enchanted cavern so closely nearby you can almost taste it...","color":"aqua"}]
execute as @s[tag=KyuInOW,tag=LocateSpell2,tag=!LocatorUpgrade2] run execute at @s run execute if score #ECSpell KyuDummy5 matches 41..99 run tellraw @s ["",{"text":"There is an enchanted cavern fairly close nearby.","color":"yellow"}]
execute as @s[tag=KyuInOW,tag=LocateSpell2,tag=!LocatorUpgrade2] run execute at @s run execute if score #ECSpell KyuDummy5 matches 100..162 run tellraw @s ["",{"text":"There is an enchanted cavern a fair distance away.","color":"gold"}]
execute as @s[tag=KyuInOW,tag=LocateSpell2,tag=!LocatorUpgrade2] run execute at @s run execute if score #ECSpell KyuDummy5 matches 163..225 run tellraw @s ["",{"text":"There is an enchanted cavern a long ways away.","color":"red"}]

execute as @s[tag=KyuInOW,tag=LocateSpell2,tag=LocatorUpgrade2] run execute at @s run execute as @e[tag=ECChestMarker,distance=0..225] run execute store result score @s PosX run data get entity @s Pos[0]
execute as @s[tag=KyuInOW,tag=LocateSpell2,tag=LocatorUpgrade2] run execute at @s run execute as @e[tag=ECChestMarker,distance=0..225] run execute store result score @s PosY run data get entity @s Pos[1]
execute as @s[tag=KyuInOW,tag=LocateSpell2,tag=LocatorUpgrade2] run execute at @s run execute as @e[tag=ECChestMarker,distance=0..225] run execute store result score @s PosZ run data get entity @s Pos[2]
execute at @s[tag=KyuInOW,tag=LocateSpell2,tag=LocatorUpgrade2] run execute as @e[tag=ECChestMarker,distance=0..225] run tellraw @p ["",{"text":"Enchanted cavern found! Coordinates are: "},{"score":{"name":"@s","objective":"PosX"}},{"text":"x, "},{"score":{"name":"@s","objective":"PosY"}},{"text":"y, "},{"score":{"name":"@s","objective":"PosZ"}},{"text":"z."}]

execute as @s[tag=KyuInOW,tag=LocateSpell2,tag=LocatorUpgrade2] run execute at @s run execute if score #ECSpell KyuDummy5 matches 0..225 run execute unless entity @e[tag=ECChestMarker,distance=0..225] run tellraw @s ["",{"text":"There is an enchanted cavern located nearby, but you can't quite make out its location.","color":"gold"}]
execute as @s[tag=KyuInOW,tag=LocateSpell2] run execute at @s run execute if score #ECSpell KyuDummy5 matches 226.. run tellraw @s ["",{"text":"There is no enchanted cavern located nearby.","color":"dark_red"}]
scoreboard players set @s KyuSpells 0