redscript-mc 3.0.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/.github/workflows/ci.yml +1 -0
  2. package/README.md +119 -313
  3. package/README.zh.md +118 -314
  4. package/ROADMAP.md +5 -5
  5. package/dist/data/impl_test/function/counter/get.mcfunction +5 -0
  6. package/dist/data/impl_test/function/counter/inc.mcfunction +7 -0
  7. package/dist/data/impl_test/function/counter/new.mcfunction +4 -0
  8. package/dist/data/impl_test/function/load.mcfunction +1 -0
  9. package/dist/data/impl_test/function/test_impl.mcfunction +10 -0
  10. package/dist/data/minecraft/tags/function/load.json +5 -0
  11. package/dist/data/playground/function/load.mcfunction +1 -0
  12. package/dist/data/playground/function/start.mcfunction +4 -0
  13. package/dist/data/playground/function/start__say_macro_t1.mcfunction +1 -0
  14. package/dist/data/playground/function/stop.mcfunction +5 -0
  15. package/dist/data/playground/function/stop__say_macro_t0.mcfunction +1 -0
  16. package/dist/data/stdlib_queue8_test/function/__queue_append_apply.mcfunction +4 -0
  17. package/dist/data/stdlib_queue8_test/function/__queue_peek_apply.mcfunction +4 -0
  18. package/dist/data/stdlib_queue8_test/function/__queue_size_raw_apply.mcfunction +4 -0
  19. package/dist/data/stdlib_queue8_test/function/load.mcfunction +1 -0
  20. package/dist/data/stdlib_queue8_test/function/queue_clear.mcfunction +6 -0
  21. package/dist/data/stdlib_queue8_test/function/queue_empty__merge_1.mcfunction +5 -0
  22. package/dist/data/stdlib_queue8_test/function/queue_empty__then_0.mcfunction +5 -0
  23. package/dist/data/stdlib_queue8_test/function/queue_peek__merge_1.mcfunction +13 -0
  24. package/dist/data/stdlib_queue8_test/function/queue_peek__then_0.mcfunction +5 -0
  25. package/dist/data/stdlib_queue8_test/function/queue_pop__merge_1.mcfunction +15 -0
  26. package/dist/data/stdlib_queue8_test/function/queue_pop__then_0.mcfunction +5 -0
  27. package/dist/data/stdlib_queue8_test/function/queue_push__const_11.mcfunction +6 -0
  28. package/dist/data/stdlib_queue8_test/function/queue_push__const_22.mcfunction +6 -0
  29. package/dist/data/stdlib_queue8_test/function/queue_size.mcfunction +13 -0
  30. package/dist/data/stdlib_queue8_test/function/test_queue_push_and_size.mcfunction +13 -0
  31. package/dist/data/test/function/load.mcfunction +1 -0
  32. package/dist/data/test/function/say_at.mcfunction +6 -0
  33. package/dist/data/test/function/test.mcfunction +4 -0
  34. package/dist/pack.mcmeta +6 -0
  35. package/dist/package.json +1 -1
  36. package/dist/src/__tests__/formatter-extra.test.d.ts +7 -0
  37. package/dist/src/__tests__/formatter-extra.test.js +123 -0
  38. package/dist/src/__tests__/global-vars.test.d.ts +13 -0
  39. package/dist/src/__tests__/global-vars.test.js +156 -0
  40. package/dist/src/__tests__/lint/new-rules.test.d.ts +9 -0
  41. package/dist/src/__tests__/lint/new-rules.test.js +402 -0
  42. package/dist/src/__tests__/lsp-rename.test.d.ts +8 -0
  43. package/dist/src/__tests__/lsp-rename.test.js +157 -0
  44. package/dist/src/__tests__/mc-integration/say-fstring.test.d.ts +11 -0
  45. package/dist/src/__tests__/mc-integration/say-fstring.test.js +220 -0
  46. package/dist/src/__tests__/mc-integration/stdlib-coverage-2.test.js +1 -1
  47. package/dist/src/__tests__/mc-integration/stdlib-coverage-3.test.js +1 -1
  48. package/dist/src/__tests__/mc-integration/stdlib-coverage-4.test.js +1 -1
  49. package/dist/src/__tests__/mc-integration/stdlib-coverage-5.test.js +1 -1
  50. package/dist/src/__tests__/mc-integration/stdlib-coverage-6.test.js +1 -1
  51. package/dist/src/__tests__/mc-integration/stdlib-coverage-7.test.js +1 -1
  52. package/dist/src/__tests__/mc-integration/stdlib-coverage-8.test.js +1 -1
  53. package/dist/src/__tests__/mc-syntax.test.js +4 -1
  54. package/dist/src/__tests__/monomorphize-coverage.test.d.ts +9 -0
  55. package/dist/src/__tests__/monomorphize-coverage.test.js +204 -0
  56. package/dist/src/__tests__/optimizer-cse.test.d.ts +7 -0
  57. package/dist/src/__tests__/optimizer-cse.test.js +226 -0
  58. package/dist/src/__tests__/parser.test.js +4 -13
  59. package/dist/src/__tests__/repl-server-extra.test.js +6 -7
  60. package/dist/src/__tests__/repl-server.test.js +5 -7
  61. package/dist/src/__tests__/stdlib/queue.test.js +6 -6
  62. package/dist/src/cli.js +0 -0
  63. package/dist/src/lexer/index.js +2 -1
  64. package/dist/src/lint/index.d.ts +12 -5
  65. package/dist/src/lint/index.js +730 -5
  66. package/dist/src/lsp/main.js +0 -0
  67. package/dist/src/mc-test/client.d.ts +21 -0
  68. package/dist/src/mc-test/client.js +34 -0
  69. package/dist/src/mir/lower.js +108 -6
  70. package/dist/src/optimizer/interprocedural.js +37 -2
  71. package/dist/src/parser/decl-parser.d.ts +19 -0
  72. package/dist/src/parser/decl-parser.js +323 -0
  73. package/dist/src/parser/expr-parser.d.ts +46 -0
  74. package/dist/src/parser/expr-parser.js +759 -0
  75. package/dist/src/parser/index.d.ts +8 -129
  76. package/dist/src/parser/index.js +13 -2262
  77. package/dist/src/parser/stmt-parser.d.ts +28 -0
  78. package/dist/src/parser/stmt-parser.js +577 -0
  79. package/dist/src/parser/type-parser.d.ts +20 -0
  80. package/dist/src/parser/type-parser.js +257 -0
  81. package/dist/src/parser/utils.d.ts +34 -0
  82. package/dist/src/parser/utils.js +141 -0
  83. package/docs/dev/README-mc-integration-tests.md +141 -0
  84. package/docs/lint-rules.md +162 -0
  85. package/docs/stdlib/bigint.md +2 -0
  86. package/editors/vscode/README.md +63 -41
  87. package/editors/vscode/out/extension.js +1881 -1776
  88. package/editors/vscode/out/lsp-server.js +4257 -3651
  89. package/editors/vscode/package-lock.json +3 -3
  90. package/editors/vscode/package.json +1 -1
  91. package/examples/loops-demo.mcrs +87 -0
  92. package/package.json +1 -1
  93. package/redscript-docs/docs/en/stdlib/advanced.md +629 -0
  94. package/redscript-docs/docs/en/stdlib/bigint.md +316 -0
  95. package/redscript-docs/docs/en/stdlib/bits.md +292 -0
  96. package/redscript-docs/docs/en/stdlib/bossbar.md +177 -0
  97. package/redscript-docs/docs/en/stdlib/calculus.md +289 -0
  98. package/redscript-docs/docs/en/stdlib/color.md +353 -0
  99. package/redscript-docs/docs/en/stdlib/combat.md +88 -0
  100. package/redscript-docs/docs/en/stdlib/cooldown.md +82 -0
  101. package/redscript-docs/docs/en/stdlib/dialog.md +155 -0
  102. package/redscript-docs/docs/en/stdlib/easing.md +558 -0
  103. package/redscript-docs/docs/en/stdlib/ecs.md +475 -0
  104. package/redscript-docs/docs/en/stdlib/effects.md +324 -0
  105. package/redscript-docs/docs/en/stdlib/events.md +3 -0
  106. package/redscript-docs/docs/en/stdlib/expr.md +45 -0
  107. package/redscript-docs/docs/en/stdlib/fft.md +141 -0
  108. package/redscript-docs/docs/en/stdlib/geometry.md +430 -0
  109. package/redscript-docs/docs/en/stdlib/graph.md +259 -0
  110. package/redscript-docs/docs/en/stdlib/heap.md +185 -0
  111. package/redscript-docs/docs/en/stdlib/interactions.md +179 -0
  112. package/redscript-docs/docs/en/stdlib/inventory.md +97 -0
  113. package/redscript-docs/docs/en/stdlib/linalg.md +557 -0
  114. package/redscript-docs/docs/en/stdlib/list.md +559 -0
  115. package/redscript-docs/docs/en/stdlib/map.md +140 -0
  116. package/redscript-docs/docs/en/stdlib/math.md +193 -0
  117. package/redscript-docs/docs/en/stdlib/math_hp.md +149 -0
  118. package/redscript-docs/docs/en/stdlib/matrix.md +403 -0
  119. package/redscript-docs/docs/en/stdlib/mobs.md +965 -0
  120. package/redscript-docs/docs/en/stdlib/noise.md +244 -0
  121. package/redscript-docs/docs/en/stdlib/ode.md +253 -0
  122. package/redscript-docs/docs/en/stdlib/parabola.md +342 -0
  123. package/redscript-docs/docs/en/stdlib/particles.md +311 -0
  124. package/redscript-docs/docs/en/stdlib/pathfind.md +255 -0
  125. package/redscript-docs/docs/en/stdlib/physics.md +493 -0
  126. package/redscript-docs/docs/en/stdlib/player.md +78 -0
  127. package/redscript-docs/docs/en/stdlib/quaternion.md +673 -0
  128. package/redscript-docs/docs/en/stdlib/queue.md +134 -0
  129. package/redscript-docs/docs/en/stdlib/random.md +223 -0
  130. package/redscript-docs/docs/en/stdlib/result.md +143 -0
  131. package/redscript-docs/docs/en/stdlib/scheduler.md +183 -0
  132. package/redscript-docs/docs/en/stdlib/set_int.md +190 -0
  133. package/redscript-docs/docs/en/stdlib/sets.md +101 -0
  134. package/redscript-docs/docs/en/stdlib/signal.md +400 -0
  135. package/redscript-docs/docs/en/stdlib/sort.md +104 -0
  136. package/redscript-docs/docs/en/stdlib/spawn.md +147 -0
  137. package/redscript-docs/docs/en/stdlib/state.md +142 -0
  138. package/redscript-docs/docs/en/stdlib/strings.md +154 -0
  139. package/redscript-docs/docs/en/stdlib/tags.md +3451 -0
  140. package/redscript-docs/docs/en/stdlib/teams.md +153 -0
  141. package/redscript-docs/docs/en/stdlib/timer.md +246 -0
  142. package/redscript-docs/docs/en/stdlib/vec.md +158 -0
  143. package/redscript-docs/docs/en/stdlib/world.md +298 -0
  144. package/redscript-docs/docs/zh/stdlib/advanced.md +615 -0
  145. package/redscript-docs/docs/zh/stdlib/bigint.md +316 -0
  146. package/redscript-docs/docs/zh/stdlib/bits.md +292 -0
  147. package/redscript-docs/docs/zh/stdlib/bossbar.md +170 -0
  148. package/redscript-docs/docs/zh/stdlib/calculus.md +287 -0
  149. package/redscript-docs/docs/zh/stdlib/color.md +353 -0
  150. package/redscript-docs/docs/zh/stdlib/combat.md +88 -0
  151. package/redscript-docs/docs/zh/stdlib/cooldown.md +84 -0
  152. package/redscript-docs/docs/zh/stdlib/dialog.md +152 -0
  153. package/redscript-docs/docs/zh/stdlib/easing.md +558 -0
  154. package/redscript-docs/docs/zh/stdlib/ecs.md +472 -0
  155. package/redscript-docs/docs/zh/stdlib/effects.md +324 -0
  156. package/redscript-docs/docs/zh/stdlib/events.md +3 -0
  157. package/redscript-docs/docs/zh/stdlib/expr.md +37 -0
  158. package/redscript-docs/docs/zh/stdlib/fft.md +128 -0
  159. package/redscript-docs/docs/zh/stdlib/geometry.md +430 -0
  160. package/redscript-docs/docs/zh/stdlib/graph.md +259 -0
  161. package/redscript-docs/docs/zh/stdlib/heap.md +185 -0
  162. package/redscript-docs/docs/zh/stdlib/interactions.md +160 -0
  163. package/redscript-docs/docs/zh/stdlib/inventory.md +94 -0
  164. package/redscript-docs/docs/zh/stdlib/linalg.md +543 -0
  165. package/redscript-docs/docs/zh/stdlib/list.md +561 -0
  166. package/redscript-docs/docs/zh/stdlib/map.md +132 -0
  167. package/redscript-docs/docs/zh/stdlib/math.md +193 -0
  168. package/redscript-docs/docs/zh/stdlib/math_hp.md +143 -0
  169. package/redscript-docs/docs/zh/stdlib/matrix.md +396 -0
  170. package/redscript-docs/docs/zh/stdlib/mobs.md +965 -0
  171. package/redscript-docs/docs/zh/stdlib/noise.md +244 -0
  172. package/redscript-docs/docs/zh/stdlib/ode.md +243 -0
  173. package/redscript-docs/docs/zh/stdlib/parabola.md +337 -0
  174. package/redscript-docs/docs/zh/stdlib/particles.md +307 -0
  175. package/redscript-docs/docs/zh/stdlib/pathfind.md +255 -0
  176. package/redscript-docs/docs/zh/stdlib/physics.md +493 -0
  177. package/redscript-docs/docs/zh/stdlib/player.md +78 -0
  178. package/redscript-docs/docs/zh/stdlib/quaternion.md +669 -0
  179. package/redscript-docs/docs/zh/stdlib/queue.md +124 -0
  180. package/redscript-docs/docs/zh/stdlib/random.md +222 -0
  181. package/redscript-docs/docs/zh/stdlib/result.md +147 -0
  182. package/redscript-docs/docs/zh/stdlib/scheduler.md +173 -0
  183. package/redscript-docs/docs/zh/stdlib/set_int.md +180 -0
  184. package/redscript-docs/docs/zh/stdlib/sets.md +107 -0
  185. package/redscript-docs/docs/zh/stdlib/signal.md +373 -0
  186. package/redscript-docs/docs/zh/stdlib/sort.md +104 -0
  187. package/redscript-docs/docs/zh/stdlib/spawn.md +142 -0
  188. package/redscript-docs/docs/zh/stdlib/state.md +134 -0
  189. package/redscript-docs/docs/zh/stdlib/strings.md +107 -0
  190. package/redscript-docs/docs/zh/stdlib/tags.md +3451 -0
  191. package/redscript-docs/docs/zh/stdlib/teams.md +150 -0
  192. package/redscript-docs/docs/zh/stdlib/timer.md +254 -0
  193. package/redscript-docs/docs/zh/stdlib/vec.md +158 -0
  194. package/redscript-docs/docs/zh/stdlib/world.md +289 -0
  195. package/src/__tests__/formatter-extra.test.ts +139 -0
  196. package/src/__tests__/global-vars.test.ts +171 -0
  197. package/src/__tests__/lint/new-rules.test.ts +437 -0
  198. package/src/__tests__/lsp-rename.test.ts +171 -0
  199. package/src/__tests__/mc-integration/say-fstring.test.ts +211 -0
  200. package/src/__tests__/mc-integration/stdlib-coverage-2.test.ts +1 -1
  201. package/src/__tests__/mc-integration/stdlib-coverage-3.test.ts +1 -1
  202. package/src/__tests__/mc-integration/stdlib-coverage-4.test.ts +1 -1
  203. package/src/__tests__/mc-integration/stdlib-coverage-5.test.ts +1 -1
  204. package/src/__tests__/mc-integration/stdlib-coverage-6.test.ts +1 -1
  205. package/src/__tests__/mc-integration/stdlib-coverage-7.test.ts +1 -1
  206. package/src/__tests__/mc-integration/stdlib-coverage-8.test.ts +1 -1
  207. package/src/__tests__/mc-syntax.test.ts +3 -0
  208. package/src/__tests__/monomorphize-coverage.test.ts +220 -0
  209. package/src/__tests__/optimizer-cse.test.ts +250 -0
  210. package/src/__tests__/parser.test.ts +4 -13
  211. package/src/__tests__/repl-server-extra.test.ts +6 -6
  212. package/src/__tests__/repl-server.test.ts +5 -6
  213. package/src/__tests__/stdlib/queue.test.ts +6 -6
  214. package/src/lexer/index.ts +2 -1
  215. package/src/lint/index.ts +713 -5
  216. package/src/mc-test/client.ts +40 -0
  217. package/src/mir/lower.ts +111 -2
  218. package/src/optimizer/interprocedural.ts +40 -2
  219. package/src/parser/decl-parser.ts +349 -0
  220. package/src/parser/expr-parser.ts +838 -0
  221. package/src/parser/index.ts +17 -2558
  222. package/src/parser/stmt-parser.ts +585 -0
  223. package/src/parser/type-parser.ts +276 -0
  224. package/src/parser/utils.ts +173 -0
  225. package/src/stdlib/queue.mcrs +19 -6
@@ -0,0 +1,134 @@
1
+ # Queue
2
+
3
+ > Auto-generated from `src/stdlib/queue.mcrs` — do not edit manually.
4
+
5
+ ## API
6
+
7
+ - [queue_push](#queue-push)
8
+ - [queue_pop](#queue-pop)
9
+ - [queue_peek](#queue-peek)
10
+ - [queue_size](#queue-size)
11
+ - [queue_empty](#queue-empty)
12
+ - [queue_clear](#queue-clear)
13
+
14
+ ---
15
+
16
+ ## `queue_push` <Badge type="info" text="v3.0.0" />
17
+
18
+ Enqueue a value into the queue.
19
+
20
+ The value is appended to the end of `storage rs:arrays Queue`.
21
+
22
+ ```redscript
23
+ fn queue_push(val: int)
24
+ ```
25
+
26
+ **Parameters**
27
+
28
+ | Parameter | Description |
29
+ |-----------|-------------|
30
+ | `val` | Value to enqueue |
31
+
32
+ **Example**
33
+
34
+ ```redscript
35
+ queue_push(42)
36
+ ```
37
+
38
+ ---
39
+
40
+ ## `queue_pop` <Badge type="info" text="v3.0.0" />
41
+
42
+ Dequeue and return the front value.
43
+
44
+ Advances the head pointer by one. If the queue is empty, returns `-1`.
45
+
46
+ ```redscript
47
+ fn queue_pop(): int
48
+ ```
49
+
50
+ **Returns:** Front value, or -1 if empty
51
+
52
+ **Example**
53
+
54
+ ```redscript
55
+ let v: int = queue_pop()
56
+ ```
57
+
58
+ ---
59
+
60
+ ## `queue_peek` <Badge type="info" text="v3.0.0" />
61
+
62
+ Peek at the front value without removing it.
63
+
64
+ If the queue is empty, returns `-1`.
65
+
66
+ ```redscript
67
+ fn queue_peek(): int
68
+ ```
69
+
70
+ **Returns:** Front value, or -1 if empty
71
+
72
+ **Example**
73
+
74
+ ```redscript
75
+ let front: int = queue_peek()
76
+ ```
77
+
78
+ ---
79
+
80
+ ## `queue_size` <Badge type="info" text="v3.0.0" />
81
+
82
+ Get the number of elements in the queue.
83
+
84
+ This is the count of un-popped elements: `raw_size - head`.
85
+
86
+ ```redscript
87
+ fn queue_size(): int
88
+ ```
89
+
90
+ **Returns:** Queue size
91
+
92
+ **Example**
93
+
94
+ ```redscript
95
+ let n: int = queue_size()
96
+ ```
97
+
98
+ ---
99
+
100
+ ## `queue_empty` <Badge type="info" text="v3.0.0" />
101
+
102
+ Check if the queue is empty.
103
+
104
+ ```redscript
105
+ fn queue_empty(): int
106
+ ```
107
+
108
+ **Returns:** 1 if empty, 0 otherwise
109
+
110
+ **Example**
111
+
112
+ ```redscript
113
+ if (queue_empty() == 1) { }
114
+ ```
115
+
116
+ ---
117
+
118
+ ## `queue_clear` <Badge type="info" text="v3.0.0" />
119
+
120
+ Clear all elements from the queue.
121
+
122
+ Resets `storage rs:arrays Queue` to an empty list and the head pointer to 0.
123
+
124
+ ```redscript
125
+ fn queue_clear()
126
+ ```
127
+
128
+ **Example**
129
+
130
+ ```redscript
131
+ queue_clear()
132
+ ```
133
+
134
+ ---
@@ -0,0 +1,223 @@
1
+ # Random
2
+
3
+ > Auto-generated from `src/stdlib/random.mcrs` — do not edit manually.
4
+
5
+ ## API
6
+
7
+ - [next_lcg](#next-lcg)
8
+ - [random_range](#random-range)
9
+ - [random_bool](#random-bool)
10
+ - [pcg_next_lo](#pcg-next-lo)
11
+ - [pcg_next_hi](#pcg-next-hi)
12
+ - [pcg_output](#pcg-output)
13
+ - [binomial_sample](#binomial-sample)
14
+ - [hypergeometric_sample](#hypergeometric-sample)
15
+
16
+ ---
17
+
18
+ ## `next_lcg` <Badge type="info" text="v1.0.0" />
19
+
20
+ Advance the LCG state by one step, returning the next pseudo-random int32.
21
+ The returned value is also the new seed for the next call.
22
+
23
+ ```redscript
24
+ fn next_lcg(seed: int): int
25
+ ```
26
+
27
+ **Parameters**
28
+
29
+ | Parameter | Description |
30
+ |-----------|-------------|
31
+ | `seed` | Current LCG state (any non-zero integer to start) |
32
+
33
+ **Returns:** Next pseudo-random int32 (also serves as next seed)
34
+
35
+ **Example**
36
+
37
+ ```redscript
38
+ let seed: int = 12345
39
+ seed = next_lcg(seed)
40
+ seed = next_lcg(seed) // advance two steps
41
+ ```
42
+
43
+ ---
44
+
45
+ ## `random_range` <Badge type="info" text="v1.0.0" />
46
+
47
+ Generate a pseudo-random integer in the range [lo, hi).
48
+
49
+ ```redscript
50
+ fn random_range(seed: int, lo: int, hi: int): int
51
+ ```
52
+
53
+ **Parameters**
54
+
55
+ | Parameter | Description |
56
+ |-----------|-------------|
57
+ | `seed` | LCG output value (result of next_lcg) |
58
+ | `lo` | Inclusive lower bound |
59
+ | `hi` | Exclusive upper bound (must be > lo) |
60
+
61
+ **Returns:** Integer in [lo, hi)
62
+
63
+ **Example**
64
+
65
+ ```redscript
66
+ seed = next_lcg(seed)
67
+ let roll: int = random_range(seed, 1, 7) // dice roll: 1-6
68
+ ```
69
+
70
+ ---
71
+
72
+ ## `random_bool` <Badge type="info" text="v1.0.0" />
73
+
74
+ Generate a pseudo-random boolean (0 or 1) with equal probability.
75
+
76
+ ```redscript
77
+ fn random_bool(seed: int): int
78
+ ```
79
+
80
+ **Parameters**
81
+
82
+ | Parameter | Description |
83
+ |-----------|-------------|
84
+ | `seed` | LCG output value (result of next_lcg) |
85
+
86
+ **Returns:** 0 or 1 with ~50% probability each
87
+
88
+ **Example**
89
+
90
+ ```redscript
91
+ seed = next_lcg(seed)
92
+ let coin: int = random_bool(seed) // 0 or 1
93
+ ```
94
+
95
+ ---
96
+
97
+ ## `pcg_next_lo` <Badge type="info" text="v1.0.0" />
98
+
99
+ Advance the PCG low-word state by one step.
100
+ Call together with pcg_next_hi; use pcg_output to extract the random value.
101
+
102
+ ```redscript
103
+ fn pcg_next_lo(state_lo: int): int
104
+ ```
105
+
106
+ **Parameters**
107
+
108
+ | Parameter | Description |
109
+ |-----------|-------------|
110
+ | `state_lo` | Current low word of PCG state |
111
+
112
+ **Returns:** New low word
113
+
114
+ **Example**
115
+
116
+ ```redscript
117
+ let lo: int = pcg_next_lo(state_lo)
118
+ ```
119
+
120
+ ---
121
+
122
+ ## `pcg_next_hi` <Badge type="info" text="v1.0.0" />
123
+
124
+ Advance the PCG high-word state by one step.
125
+
126
+ ```redscript
127
+ fn pcg_next_hi(state_hi: int, state_lo: int): int
128
+ ```
129
+
130
+ **Parameters**
131
+
132
+ | Parameter | Description |
133
+ |-----------|-------------|
134
+ | `state_hi` | Current high word of PCG state |
135
+ | `state_lo` | Current low word of PCG state (previous, before pcg_next_lo) |
136
+
137
+ **Returns:** New high word
138
+
139
+ **Example**
140
+
141
+ ```redscript
142
+ let hi: int = pcg_next_hi(state_hi, state_lo)
143
+ ```
144
+
145
+ ---
146
+
147
+ ## `pcg_output` <Badge type="info" text="v1.0.0" />
148
+
149
+ Extract an output value from the PCG low word using XSH-RR permutation.
150
+
151
+ ```redscript
152
+ fn pcg_output(state_lo: int): int
153
+ ```
154
+
155
+ **Parameters**
156
+
157
+ | Parameter | Description |
158
+ |-----------|-------------|
159
+ | `state_lo` | Current low word of PCG state (after pcg_next_lo) |
160
+
161
+ **Returns:** Pseudo-random output value (unsigned, any int)
162
+
163
+ **Example**
164
+
165
+ ```redscript
166
+ let rng: int = pcg_output(state_lo)
167
+ ```
168
+
169
+ ---
170
+
171
+ ## `binomial_sample` <Badge type="info" text="v1.0.0" />
172
+
173
+ Simulate n Bernoulli trials and count the number of successes (binomial distribution).
174
+
175
+ ```redscript
176
+ fn binomial_sample(n: int, p_x10000: int, seed: int): int
177
+ ```
178
+
179
+ **Parameters**
180
+
181
+ | Parameter | Description |
182
+ |-----------|-------------|
183
+ | `n` | Number of trials |
184
+ | `p_x10000` | Success probability ×10000 (e.g. 5000 = 50%, 3000 = 30%) |
185
+ | `seed` | LCG seed (any non-zero integer) |
186
+
187
+ **Returns:** Number of successes in [0, n]
188
+
189
+ **Example**
190
+
191
+ ```redscript
192
+ let hits: int = binomial_sample(10, 5000, 99999) // ~5 successes on average
193
+ ```
194
+
195
+ ---
196
+
197
+ ## `hypergeometric_sample` <Badge type="info" text="v1.0.0" />
198
+
199
+ Draw `draws` items without replacement from a population and count successes (hypergeometric distribution).
200
+
201
+ ```redscript
202
+ fn hypergeometric_sample(pop_size: int, success_states: int, draws: int, seed: int): int
203
+ ```
204
+
205
+ **Parameters**
206
+
207
+ | Parameter | Description |
208
+ |-----------|-------------|
209
+ | `pop_size` | Total population size |
210
+ | `success_states` | Number of "success" items in the population |
211
+ | `draws` | Number of items to draw |
212
+ | `seed` | LCG seed (any non-zero integer) |
213
+
214
+ **Returns:** Number of successes drawn, in [0, min(draws, success_states)]
215
+
216
+ **Example**
217
+
218
+ ```redscript
219
+ // 52-card deck, 4 aces, draw 5 cards
220
+ let aces: int = hypergeometric_sample(52, 4, 5, 42)
221
+ ```
222
+
223
+ ---
@@ -0,0 +1,143 @@
1
+ # Result
2
+
3
+ > Auto-generated from `src/stdlib/result.mcrs` — do not edit manually.
4
+
5
+ ## API
6
+
7
+ - [result_ok](#result-ok)
8
+ - [result_err](#result-err)
9
+ - [result_is_ok](#result-is-ok)
10
+ - [result_is_err](#result-is-err)
11
+ - [result_value](#result-value)
12
+ - [result_code](#result-code)
13
+ - [result_divide](#result-divide)
14
+
15
+ ---
16
+
17
+ ## `result_ok` <Badge type="info" text="v1.0.0" />
18
+
19
+ Construct a successful Result with the given value.
20
+
21
+ ```redscript
22
+ fn result_ok(value: int): Result
23
+ ```
24
+
25
+ **Parameters**
26
+
27
+ | Parameter | Description |
28
+ |-----------|-------------|
29
+ | `value` | The success value (any integer) |
30
+
31
+ **Returns:** Result::Ok(value)
32
+
33
+ **Example**
34
+
35
+ ```redscript
36
+ let r = result_ok(42) // Ok result carrying 42
37
+ ```
38
+
39
+ ---
40
+
41
+ ## `result_err` <Badge type="info" text="v1.0.0" />
42
+
43
+ Construct a failed Result with the given error code.
44
+
45
+ ```redscript
46
+ fn result_err(code: int): Result
47
+ ```
48
+
49
+ **Parameters**
50
+
51
+ | Parameter | Description |
52
+ |-----------|-------------|
53
+ | `code` | Error code (use negative by convention: -1 generic, -2 div/zero) |
54
+
55
+ **Returns:** Result::Err(code)
56
+
57
+ **Example**
58
+
59
+ ```redscript
60
+ let r = result_err(-2) // division-by-zero error
61
+ ```
62
+
63
+ ---
64
+
65
+ ## `result_is_ok` <Badge type="info" text="v1.0.0" />
66
+
67
+ Returns 1 if the Result is Ok, 0 otherwise.
68
+
69
+ ```redscript
70
+ fn result_is_ok(r: Result): int
71
+ ```
72
+
73
+ **Parameters**
74
+
75
+ | Parameter | Description |
76
+ |-----------|-------------|
77
+ | `r` | The Result to test |
78
+
79
+ **Returns:** 1 if Ok, 0 if Err
80
+
81
+ **Example**
82
+
83
+ ```redscript
84
+ let ok = result_is_ok(result_ok(5)) // result: 1
85
+ ```
86
+
87
+ ---
88
+
89
+ ## `result_is_err`
90
+
91
+ Returns 1 if the Result is Err, 0 otherwise.
92
+
93
+ ```redscript
94
+ fn result_is_err(r: Result): int
95
+ ```
96
+
97
+ ---
98
+
99
+ ## `result_value` <Badge type="info" text="v1.0.0" />
100
+
101
+ Extract the value from an Ok result.
102
+ Returns 0 if the Result is Err (check result_is_ok first).
103
+
104
+ ```redscript
105
+ fn result_value(r: Result): int
106
+ ```
107
+
108
+ **Parameters**
109
+
110
+ | Parameter | Description |
111
+ |-----------|-------------|
112
+ | `r` | The Result to unwrap |
113
+
114
+ **Returns:** The Ok value, or 0 if Err
115
+
116
+ **Example**
117
+
118
+ ```redscript
119
+ let v = result_value(result_ok(99)) // result: 99
120
+ ```
121
+
122
+ ---
123
+
124
+ ## `result_code`
125
+
126
+ Extract the error code from an Err result.
127
+ Returns 0 if the Result is Ok (check result_is_err first).
128
+
129
+ ```redscript
130
+ fn result_code(r: Result): int
131
+ ```
132
+
133
+ ---
134
+
135
+ ## `result_divide`
136
+
137
+ Divide a by b; returns Err(-2) on division by zero.
138
+
139
+ ```redscript
140
+ fn result_divide(a: int, b: int): Result
141
+ ```
142
+
143
+ ---
@@ -0,0 +1,183 @@
1
+ # Scheduler
2
+
3
+ > Auto-generated from `src/stdlib/scheduler.mcrs` — do not edit manually.
4
+
5
+ ## API
6
+
7
+ - [task_schedule](#task-schedule)
8
+ - [task_cancel](#task-cancel)
9
+ - [task_ready](#task-ready)
10
+ - [gtask_schedule](#gtask-schedule)
11
+ - [gtask_cancel](#gtask-cancel)
12
+ - [gtask_ready](#gtask-ready)
13
+ - [scheduler_tick](#scheduler-tick)
14
+
15
+ ---
16
+
17
+ ## `task_schedule` <Badge type="info" text="v1.0.0" />
18
+
19
+ Schedule slot `task_id` (0–7) to fire after `delay` ticks for player `p`.
20
+
21
+ ```redscript
22
+ fn task_schedule(p: selector, task_id: int, delay: int)
23
+ ```
24
+
25
+ **Parameters**
26
+
27
+ | Parameter | Description |
28
+ |-----------|-------------|
29
+ | `p` | Recipient player or entity selector |
30
+ | `task_id` | Slot index in range [0, 7] |
31
+ | `delay` | Number of ticks to wait before firing |
32
+
33
+ **Example**
34
+
35
+ ```redscript
36
+ task_schedule(@s, 0, 40)
37
+ ```
38
+
39
+ ---
40
+
41
+ ## `task_cancel` <Badge type="info" text="v1.0.0" />
42
+
43
+ Cancel slot `task_id` for player `p` (zeroes the counter).
44
+
45
+ ```redscript
46
+ fn task_cancel(p: selector, task_id: int)
47
+ ```
48
+
49
+ **Parameters**
50
+
51
+ | Parameter | Description |
52
+ |-----------|-------------|
53
+ | `p` | Recipient player or entity selector |
54
+ | `task_id` | Slot index in range [0, 7] |
55
+
56
+ **Example**
57
+
58
+ ```redscript
59
+ task_cancel(@s, 0)
60
+ ```
61
+
62
+ ---
63
+
64
+ ## `task_ready` <Badge type="info" text="v1.0.0" />
65
+
66
+ Returns `1` if slot `task_id` fired on this tick (counter reached 1), `0` otherwise.
67
+
68
+ Automatically clears the slot once it fires so subsequent calls return `0`.
69
+
70
+ ```redscript
71
+ fn task_ready(p: selector, task_id: int) -> int
72
+ ```
73
+
74
+ **Parameters**
75
+
76
+ | Parameter | Description |
77
+ |-----------|-------------|
78
+ | `p` | Player or entity selector to check |
79
+ | `task_id` | Slot index in range [0, 7] |
80
+
81
+ **Returns:** `1` when the task is ready, `0` otherwise
82
+
83
+ **Example**
84
+
85
+ ```redscript
86
+ if (task_ready(@s, 0) == 1) { /* handle event */ }
87
+ ```
88
+
89
+ ---
90
+
91
+ ## `gtask_schedule` <Badge type="info" text="v1.0.0" />
92
+
93
+ Schedule global slot `task_id` (0–7) to fire after `delay` ticks.
94
+
95
+ Global tasks are stored on the `#rs` fake-player and are not bound to any
96
+ specific player entity.
97
+
98
+ ```redscript
99
+ fn gtask_schedule(task_id: int, delay: int)
100
+ ```
101
+
102
+ **Parameters**
103
+
104
+ | Parameter | Description |
105
+ |-----------|-------------|
106
+ | `task_id` | Slot index in range [0, 7] |
107
+ | `delay` | Number of ticks to wait before firing |
108
+
109
+ **Example**
110
+
111
+ ```redscript
112
+ gtask_schedule(0, 200)
113
+ ```
114
+
115
+ ---
116
+
117
+ ## `gtask_cancel` <Badge type="info" text="v1.0.0" />
118
+
119
+ Cancel global slot `task_id` by zeroing its counter.
120
+
121
+ ```redscript
122
+ fn gtask_cancel(task_id: int)
123
+ ```
124
+
125
+ **Parameters**
126
+
127
+ | Parameter | Description |
128
+ |-----------|-------------|
129
+ | `task_id` | Slot index in range [0, 7] |
130
+
131
+ **Example**
132
+
133
+ ```redscript
134
+ gtask_cancel(0)
135
+ ```
136
+
137
+ ---
138
+
139
+ ## `gtask_ready` <Badge type="info" text="v1.0.0" />
140
+
141
+ Returns `1` if global slot `task_id` fired this tick, `0` otherwise.
142
+
143
+ Automatically clears the slot once it fires.
144
+
145
+ ```redscript
146
+ fn gtask_ready(task_id: int) -> int
147
+ ```
148
+
149
+ **Parameters**
150
+
151
+ | Parameter | Description |
152
+ |-----------|-------------|
153
+ | `task_id` | Slot index in range [0, 7] |
154
+
155
+ **Returns:** `1` when the task is ready, `0` otherwise
156
+
157
+ **Example**
158
+
159
+ ```redscript
160
+ if (gtask_ready(0) == 1) { /* handle global event */ }
161
+ ```
162
+
163
+ ---
164
+
165
+ ## `scheduler_tick` <Badge type="info" text="v1.0.0" />
166
+
167
+ Decrement all active per-player and global timers by 1 each tick.
168
+
169
+ Call this inside your `@tick` function (executed as `@a`). Counters are
170
+ clamped to 0 so they never go negative.
171
+
172
+ ```redscript
173
+ fn scheduler_tick()
174
+ ```
175
+
176
+ **Example**
177
+
178
+ ```redscript
179
+ // In your @tick mcfunction:
180
+ scheduler_tick()
181
+ ```
182
+
183
+ ---