## Get our position
execute store result score @s vb.dummy1 run data get entity @s Pos[0]
execute store result score @s vb.dummy2 run data get entity @s Pos[1]
execute store result score @s vb.dummy3 run data get entity @s Pos[2]
execute store result score @s vb.dummy4 run data get entity @s Rotation[0]

## Get lodestone position if possible
execute unless items entity @s weapon.mainhand minecraft:compass if data entity @s equipment.offhand.components.minecraft:lodestone_tracker store result score @s vb.dummy1 run data get entity @s equipment.offhand.components.minecraft:lodestone_tracker.target.pos[0]
execute unless items entity @s weapon.mainhand minecraft:compass if data entity @s equipment.offhand.components.minecraft:lodestone_tracker store result score @s vb.dummy2 run data get entity @s equipment.offhand.components.minecraft:lodestone_tracker.target.pos[1]
execute unless items entity @s weapon.mainhand minecraft:compass if data entity @s equipment.offhand.components.minecraft:lodestone_tracker store result score @s vb.dummy3 run data get entity @s equipment.offhand.components.minecraft:lodestone_tracker.target.pos[2]
execute unless items entity @s weapon.mainhand minecraft:compass if data entity @s equipment.offhand.components.minecraft:lodestone_tracker run scoreboard players set @s vb.dummy4 99999
execute if data entity @s SelectedItem.components.minecraft:lodestone_tracker store result score @s vb.dummy1 run data get entity @s SelectedItem.components.minecraft:lodestone_tracker.target.pos[0]
execute if data entity @s SelectedItem.components.minecraft:lodestone_tracker store result score @s vb.dummy2 run data get entity @s SelectedItem.components.minecraft:lodestone_tracker.target.pos[1]
execute if data entity @s SelectedItem.components.minecraft:lodestone_tracker store result score @s vb.dummy3 run data get entity @s SelectedItem.components.minecraft:lodestone_tracker.target.pos[2]
execute if data entity @s SelectedItem.components.minecraft:lodestone_tracker run scoreboard players set @s vb.dummy4 99999

## Fix rotation so we don't get exactly between two cardinal directions, causing errors
execute if score @s vb.dummy4 matches -135 run scoreboard players set @s vb.dummy4 -134
execute if score @s vb.dummy4 matches -45 run scoreboard players set @s vb.dummy4 -44
execute if score @s vb.dummy4 matches 45 run scoreboard players set @s vb.dummy4 -46
execute if score @s vb.dummy4 matches 135 run scoreboard players set @s vb.dummy4 136

## Other dimensions
execute unless dimension minecraft:overworld run scoreboard players set @s vb.dummy4 99999

## Display in action bar
execute if score @s vb.dummy4 matches 99999 if data entity @s SelectedItem.components.minecraft:lodestone_tracker run title @s actionbar [{text:'Lodestone X: ',color:white},{score:{name:'@s',objective:vb.dummy1},color:red},{text:' Y: ',color:white},{score:{name:'@s',objective:vb.dummy2},color:red},{text:' Z: ',color:white},{score:{name:'@s',objective:vb.dummy3},color:red}]
execute if score @s vb.dummy4 matches 99999 unless data entity @s SelectedItem.components.minecraft:lodestone_tracker run title @s actionbar [{text:'North (',color:white,obfuscated:true},{text:'AA',color:red,obfuscated:true},{text:') X: ',color:white,obfuscated:true},{text:'000',color:red,obfuscated:true},{text:' Y: ',color:white,obfuscated:true},{text:'00',color:red,obfuscated:true},{text:' Z: ',color:white,obfuscated:true},{text:'000',color:red,obfuscated:true}]
execute if score @s vb.dummy4 matches 135..99998 run title @s actionbar [{text:'North (',color:white},{text:'-Z',color:red},{text:') X: ',color:white},{score:{name:'@s',objective:vb.dummy1},color:red},{text:' Y: ',color:white},{score:{name:'@s',objective:vb.dummy2},color:red},{text:' Z: ',color:white},{score:{name:'@s',objective:vb.dummy3},color:red}]
execute if score @s vb.dummy4 matches ..-135 run title @s actionbar [{text:'North (',color:white},{text:'-Z',color:red},{text:') X: ',color:white},{score:{name:'@s',objective:vb.dummy1},color:red},{text:' Y: ',color:white},{score:{name:'@s',objective:vb.dummy2},color:red},{text:' Z: ',color:white},{score:{name:'@s',objective:vb.dummy3},color:red}]
execute if score @s vb.dummy4 matches -135..-45 run title @s actionbar [{text:'East (',color:white},{text:'+X',color:red},{text:') X: ',color:white},{score:{name:'@s',objective:vb.dummy1},color:red},{text:' Y: ',color:white},{score:{name:'@s',objective:vb.dummy2},color:red},{text:' Z: ',color:white},{score:{name:'@s',objective:vb.dummy3},color:red}]
execute if score @s vb.dummy4 matches -45..45 run title @s actionbar [{text:'South (',color:white},{text:'+Z',color:red},{text:') X: ',color:white},{score:{name:'@s',objective:vb.dummy1},color:red},{text:' Y: ',color:white},{score:{name:'@s',objective:vb.dummy2},color:red},{text:' Z: ',color:white},{score:{name:'@s',objective:vb.dummy3},color:red}]
execute if score @s vb.dummy4 matches 45..135 run title @s actionbar [{text:'West (',color:white},{text:'-X',color:red},{text:') X: ',color:white},{score:{name:'@s',objective:vb.dummy1},color:red},{text:' Y: ',color:white},{score:{name:'@s',objective:vb.dummy2},color:red},{text:' Z: ',color:white},{score:{name:'@s',objective:vb.dummy3},color:red}]

