Skip to content

Commit

Permalink
Throttle the display updates to once every 8 ticks.
Browse files Browse the repository at this point in the history
  • Loading branch information
totemo committed Oct 9, 2019
1 parent e22caea commit ec71ed3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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"}]

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <name> <objective> <value>, 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
Expand Down
49 changes: 7 additions & 42 deletions coords/src/data/io.totemo.coords/functions/coords-tick.mcfunction
Original file line number Diff line number Diff line change
@@ -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"}]

0 comments on commit ec71ed3

Please sign in to comment.