#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#
#    This function has been created by Skilendarz Group.
#             https://skilendarz.com
#
#      GIVE MAP MAKERS THE CREDIT THEY DESERVE!
#             COPYING IS PROHIBITED!
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#Height
scoreboard players operation $low_pos pos_y = @s pos_y
scoreboard players operation $high_pos pos_y = @s pos_y
scoreboard players remove $low_pos pos_y 10
scoreboard players add $high_pos pos_y 10

execute if score $compass_pos pos_y > $high_pos pos_y run data modify storage minecraft:compass Height set value "↑"
execute if score $compass_pos pos_y < $low_pos pos_y run data modify storage minecraft:compass Height set value "↓"
execute if score $compass_pos pos_y < $high_pos pos_y if score $compass_pos pos_y > $low_pos pos_y run data modify storage minecraft:compass Height set value "●"

#sqrt(x^2+y^2+z^2)
scoreboard players operation @s pos_x -= $compass_pos pos_x
scoreboard players operation @s pos_y -= $compass_pos pos_y
scoreboard players operation @s pos_z -= $compass_pos pos_z

scoreboard players operation @s pos_x *= @s pos_x
scoreboard players operation @s pos_y *= @s pos_y
scoreboard players operation @s pos_z *= @s pos_z

scoreboard players set @s distance 0
scoreboard players operation @s distance += @s pos_x
scoreboard players operation @s distance += @s pos_y
scoreboard players operation @s distance += @s pos_z

scoreboard players operation $sqrt distance = @s distance
scoreboard players set $sqrt pos_x 1
scoreboard players set $2 pos_x 2
scoreboard players set $10 pos_x 10

#Sqrt
execute if score $sqrt distance > $sqrt pos_x run function f:game/compass/sqrt

scoreboard players operation @s distance = $sqrt distance
scoreboard players operation @s distance /= $10 pos_x
scoreboard players operation $sqrt distance %= $10 pos_x



#Info
title @s[scores={mode=0}] actionbar ["",{"translate":"compass.tracking"},{"text":": "},{"translate":"compass.item.pumpkin","color":"gold","bold":true},{"text":" - ","color":"none","bold":false},{"translate":"compass.distance","color":"none"},{"text":": ","color":"none"},{"score":{"name":"@s","objective":"distance"},"color":"green","bold":true},{"text":".","color":"green","bold":true},{"score":{"name":"$sqrt","objective":"distance"},"color":"green","bold":true},{"text":"m ","color":"green","bold":true},{"nbt":"Height","storage":"minecraft:compass"}]
title @s[scores={mode=1}] actionbar ["",{"translate":"compass.tracking"},{"text":": "},{"translate":"compass.item.powerup","color":"gold","bold":true},{"text":" - ","color":"none","bold":false},{"translate":"compass.distance","color":"none"},{"text":": ","color":"none"},{"score":{"name":"@s","objective":"distance"},"color":"green","bold":true},{"text":".","color":"green","bold":true},{"score":{"name":"$sqrt","objective":"distance"},"color":"green","bold":true},{"text":"m ","color":"green","bold":true},{"nbt":"Height","storage":"minecraft:compass"}]
title @s[scores={mode=2}] actionbar ["",{"translate":"compass.tracking"},{"text":": "},{"selector":"@p[tag=selected_compass]","color":"gold","bold":true},{"text":" - ","color":"none","bold":false},{"translate":"compass.distance","color":"none"},{"text":": ","color":"none"},{"score":{"name":"@s","objective":"distance"},"color":"green","bold":true},{"text":".","color":"green","bold":true},{"score":{"name":"$sqrt","objective":"distance"},"color":"green","bold":true},{"text":"m ","color":"green","bold":true},{"nbt":"Height","storage":"minecraft:compass"}]