diff --git a/coords/src/data/io.totemo.coords/functions/coords-display.mcfunction b/coords/src/data/io.totemo.coords/functions/coords-display.mcfunction new file mode 100644 index 0000000..7d6c948 --- /dev/null +++ b/coords/src/data/io.totemo.coords/functions/coords-display.mcfunction @@ -0,0 +1,46 @@ +# Get player X, Y, Z and Yaw angle. Store as X, Y, Z, Bearing objectives. +execute as @a store result score @s X run data get entity @s Pos[0] 1.0 +execute as @a store result score @s Y run data get entity @s Pos[1] 1.0 +execute as @a store result score @s Z run data get entity @s Pos[2] 1.0 +execute as @a store result score @s Bearing run data get entity @s Rotation[0] + +# Adjust bearing to compass convention. +scoreboard players operation @a Bearing += 540 const +scoreboard players operation @a Bearing %= 360 const + +# Set Octant to 0..7: +# First set Octant = Bearing, longhand. +execute as @a store result score @s Octant run scoreboard players get @s Bearing +scoreboard players operation @a Octant *= 2 const +scoreboard players operation @a Octant += 45 const +scoreboard players operation @a Octant /= 90 const +scoreboard players operation @a Octant %= 8 const + +# Debugging Bearing and Octant: +#title @a title {"text":""} +#title @a subtitle [{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"},{"text":" B ","color":"gray"},{"score":{"name":"*","objective":"Bearing"},"color":"white"},{"text":" O ","color":"gray"},{"score":{"name":"*","objective":"Octant"},"color":"white"}] + +# N: Octant = 0 +title @a[scores={Octant=0,CoordsHidden=0}] actionbar [{"text":"N ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] + +# NE: Octant = 1 +title @a[scores={Octant=1,CoordsHidden=0}] actionbar [{"text":"NE ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] + +# E: Octant = 2 +title @a[scores={Octant=2,CoordsHidden=0}] actionbar [{"text":"E ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] + +# SE: Octant = 3 +title @a[scores={Octant=3,CoordsHidden=0}] actionbar [{"text":"SE ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] + +# S: Octant = 4 +title @a[scores={Octant=4,CoordsHidden=0}] actionbar [{"text":"S ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] + +# SW: Octant = 5 +title @a[scores={Octant=5,CoordsHidden=0}] actionbar [{"text":"SW ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] + +# W: Octant = 6 +title @a[scores={Octant=6,CoordsHidden=0}] actionbar [{"text":"W ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] + +# NW: Octant = 7 +title @a[scores={Octant=7,CoordsHidden=0}] actionbar [{"text":"NW ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] + diff --git a/coords/src/data/io.totemo.coords/functions/coords-load.mcfunction b/coords/src/data/io.totemo.coords/functions/coords-load.mcfunction index 0c4c030..9ec954b 100644 --- a/coords/src/data/io.totemo.coords/functions/coords-load.mcfunction +++ b/coords/src/data/io.totemo.coords/functions/coords-load.mcfunction @@ -1,3 +1,4 @@ +# TODO: I should prefix all my objectives to avoid name clashes. scoreboard objectives add X dummy scoreboard objectives add Y dummy scoreboard objectives add Z dummy @@ -8,10 +9,12 @@ scoreboard objectives add Octant dummy # CoordsHidden = 1 for hidden, 0 for visible. scoreboard objectives add CoordsHidden dummy -scoreboard objectives add const dummy +# Per-player count used to avoid updating titles every tick. +scoreboard objectives add itc.Tick dummy # Represent constants as , with the objective "const". # Scoreboard values are always integers. +scoreboard objectives add const dummy scoreboard players set 0 const 0 scoreboard players set 1 const 1 scoreboard players set 2 const 2 diff --git a/coords/src/data/io.totemo.coords/functions/coords-tick.mcfunction b/coords/src/data/io.totemo.coords/functions/coords-tick.mcfunction index bcecf52..edd73db 100644 --- a/coords/src/data/io.totemo.coords/functions/coords-tick.mcfunction +++ b/coords/src/data/io.totemo.coords/functions/coords-tick.mcfunction @@ -1,49 +1,14 @@ # Initialise CoordsHidden to 0 when unset. scoreboard players add @a CoordsHidden 0 -# Get player X, Y, Z and Yaw angle. Store as X, Y, Z, Bearing objectives. -execute as @a store result score @s X run data get entity @s Pos[0] 1.0 -execute as @a store result score @s Y run data get entity @s Pos[1] 1.0 -execute as @a store result score @s Z run data get entity @s Pos[2] 1.0 -execute as @a store result score @s Bearing run data get entity @s Rotation[0] +# If not initialised, itc.Tick = 0. +scoreboard players add @a itc.Tick 0 -# Adjust bearing to compass convention. -scoreboard players operation @a Bearing += 540 const -scoreboard players operation @a Bearing %= 360 const +# itc.Tick = (itcTick + 1) % 8 +scoreboard players operation @a itc.Tick += 1 const +scoreboard players operation @a itc.Tick %= 8 const -# Set Octant to 0..7: -# First set Octant = Bearing, longhand. -execute as @a store result score @s Octant run scoreboard players get @s Bearing -scoreboard players operation @a Octant *= 2 const -scoreboard players operation @a Octant += 45 const -scoreboard players operation @a Octant /= 90 const -scoreboard players operation @a Octant %= 8 const +# Update display when itc.Tick is 0. +execute as @a[scores={itc.Tick=0}] run function io.totemo.coords:coords-display -# Debugging Bearing and Octant: -#title @a title {"text":""} -#title @a subtitle [{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"},{"text":" B ","color":"gray"},{"score":{"name":"*","objective":"Bearing"},"color":"white"},{"text":" O ","color":"gray"},{"score":{"name":"*","objective":"Octant"},"color":"white"}] - -# N: Octant = 0 -title @a[scores={Octant=0,CoordsHidden=0}] actionbar [{"text":"N ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] - -# NE: Octant = 1 -title @a[scores={Octant=1,CoordsHidden=0}] actionbar [{"text":"NE ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] - -# E: Octant = 2 -title @a[scores={Octant=2,CoordsHidden=0}] actionbar [{"text":"E ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] - -# SE: Octant = 3 -title @a[scores={Octant=3,CoordsHidden=0}] actionbar [{"text":"SE ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] - -# S: Octant = 4 -title @a[scores={Octant=4,CoordsHidden=0}] actionbar [{"text":"S ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] - -# SW: Octant = 5 -title @a[scores={Octant=5,CoordsHidden=0}] actionbar [{"text":"SW ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] - -# W: Octant = 6 -title @a[scores={Octant=6,CoordsHidden=0}] actionbar [{"text":"W ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}] - -# NW: Octant = 7 -title @a[scores={Octant=7,CoordsHidden=0}] actionbar [{"text":"NW ","color":"white"},{"text":"X ","color":"gray"},{"score":{"name":"*","objective":"X"},"color":"white"},{"text":" Y ","color":"gray"},{"score":{"name":"*","objective":"Y"},"color":"white"},{"text":" Z ","color":"gray"},{"score":{"name":"*","objective":"Z"},"color":"white"}]