Skip to content

Commit 8aa5618

Browse files
committed
Add usages
1 parent d751f07 commit 8aa5618

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

README.md

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,48 @@
55
66
Calculates the current value of the JVM's high-resolution time source in milliseconds (`(System.nanoTime() / 1000000L) & 0x0000ffffffffffff`).
77

8-
## Example usage
8+
## Basic usage
99

1010
```mcfunction
11-
# Initialize once.
12-
function get_millis:init
13-
14-
# Get the millis. The execution position must be loaded to place the template.
15-
execute positioned 0 0 0 run function get_millis:
16-
17-
# The result is split into high 32 bits (#millis[63:32] get_millis)
18-
# and low 32 bits (#millis[31:00] get_millis).
19-
tellraw @s [ \
20-
{"score": {"name": "#millis[63:32]", "objective": "get_millis"}}, \
21-
", ", \
22-
{"score": {"name": "#millis[31:00]", "objective": "get_millis"}} \
11+
scoreboard objectives add example dummy
12+
13+
execute store result score #start example run function get_millis:api/get_and_resolve
14+
reload
15+
reload
16+
reload
17+
execute store result score #end example run function get_millis:api/get_and_resolve
18+
19+
scoreboard players operation #end example -= #start example
20+
tellraw @a ["Elapsed time: ", {score: {name: "#end", objective: "example"}, color: "gold"}, " ms"]
21+
```
22+
23+
## Advanced usage
24+
25+
```mcfunction
26+
scoreboard objectives add example dummy
27+
28+
data modify storage example: times set value []
29+
function get_millis:api/get {target: "storage example: times", op: "append"}
30+
reload
31+
function get_millis:api/get {target: "storage example: times", op: "append"}
32+
reload
33+
function get_millis:api/get {target: "storage example: times", op: "append"}
34+
reload
35+
function get_millis:api/get {target: "storage example: times", op: "append"}
36+
37+
execute store result score #1 example run function get_millis:api/resolve {target: "storage example: times[0]"}
38+
execute store result score #2 example run function get_millis:api/resolve {target: "storage example: times[1]"}
39+
execute store result score #3 example run function get_millis:api/resolve {target: "storage example: times[2]"}
40+
execute store result score #4 example run function get_millis:api/resolve {target: "storage example: times[3]"}
41+
42+
scoreboard players operation #4 example -= #3 example
43+
scoreboard players operation #3 example -= #2 example
44+
scoreboard players operation #2 example -= #1 example
45+
46+
tellraw @a [ \
47+
"Times: \n", \
48+
"1: ", {score: {name: "#2", objective: "example"}, color: "gold"}, " ms\n", \
49+
"2: ", {score: {name: "#3", objective: "example"}, color: "gold"}, " ms\n", \
50+
"3: ", {score: {name: "#4", objective: "example"}, color: "gold"}, " ms\n", \
2351
]
2452
```

0 commit comments

Comments
 (0)