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

#Holding
data modify storage minecraft:compass Pos set from entity @e[tag=player_indicator,limit=1,sort=nearest,distance=..2] Pos
execute store result score @s pos_x run data get storage minecraft:compass Pos[0] 10
execute store result score @s pos_y run data get storage minecraft:compass Pos[1] 10
execute store result score @s pos_z run data get storage minecraft:compass Pos[2] 10

#Get target
scoreboard players add @s mode 0
execute if score @s mode matches 0 run tag @e[tag=pumpkin,scores={time=0},limit=1,sort=nearest] add selected_compass
execute if score @s mode matches 1 run tag @e[tag=powerup,limit=1,sort=nearest] add selected_compass
execute if entity @s[team=blue] if score @s mode matches 2 run tag @p[distance=0.5..,gamemode=!spectator,team=!blue,tag=!invisible,limit=1,sort=nearest] add selected_compass
execute if entity @s[team=red] if score @s mode matches 2 run tag @p[distance=0.5..,gamemode=!spectator,team=!red,tag=!invisible,limit=1,sort=nearest] add selected_compass
execute if entity @s[team=green] if score @s mode matches 2 run tag @p[distance=0.5..,gamemode=!spectator,team=!green,tag=!invisible,limit=1,sort=nearest] add selected_compass
execute if entity @s[team=yellow] if score @s mode matches 2 run tag @p[distance=0.5..,gamemode=!spectator,team=!yellow,tag=!invisible,limit=1,sort=nearest] add selected_compass

execute if entity @s[team=hider] if score @s mode matches 2 run tag @p[distance=0.5..,gamemode=!spectator,team=seeker,tag=player,tag=!invisible,limit=1,sort=nearest] add selected_compass
execute if entity @s[team=seeker,tag=hold_compass,tag=has_gold] if score @s mode matches 2 run tag @p[distance=0.5..,gamemode=!spectator,team=hider,tag=!invisible,limit=1,sort=nearest] add selected_compass

execute if entity @e[tag=selected_compass] run scoreboard players set @s notarget 0
execute as @e[tag=selected_compass,limit=1,sort=nearest] run function f:game/compass/target

#No target
tag @s remove no_compass_target
execute unless entity @e[tag=selected_compass] run tag @s add no_compass_target

#Distance
execute if entity @s[tag=hold_compass,team=!seeker] if entity @e[tag=selected_compass] run function f:game/compass/distance

#Update compass
item replace entity @s hotbar.8 from block 14 107 -23 container.0

#Reset
tag @e[tag=selected_compass] remove selected_compass
tag @s add compass_async

#Next
scoreboard players remove compass_async id 1
execute if score compass_async id matches 0.. as @a[tag=compass_compatible,tag=!compass_async,limit=1] at @s run function f:game/compass/compass