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
@@ -20,6 +20,7 @@ jobs:
20
20
  node-version: 20
21
21
  cache: npm
22
22
  - run: npm install
23
+ - run: npm install --prefix editors/vscode
23
24
  - run: npm run build
24
25
  - run: npm test
25
26
  - name: Run MC integration tests (offline - graceful skip)
package/README.md CHANGED
@@ -2,400 +2,206 @@
2
2
 
3
3
  <img src="./logo.png" alt="RedScript Logo" width="64" />
4
4
 
5
- <img src="https://img.shields.io/badge/RedScript-2.6.2-red?style=for-the-badge&logo=minecraft&logoColor=white" alt="RedScript" />
5
+ # RedScript
6
6
 
7
- **A typed scripting language that compiles to Minecraft datapacks.**
7
+ **A typed language that compiles to Minecraft datapacks.**
8
8
 
9
- Write clean game logic. RedScript handles the scoreboard spaghetti.
9
+ Write clean code. Get vanilla datapacks. No mods required.
10
10
 
11
- [![CI](https://github.com/bkmashiro/redscript/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bkmashiro/redscript/actions/workflows/ci.yml)
12
- [![Tests](https://img.shields.io/badge/tests-1901%20passing-brightgreen)](https://github.com/bkmashiro/redscript)
13
- [![npm](https://img.shields.io/npm/v/redscript-mc?color=cb3837)](https://www.npmjs.com/package/redscript-mc)
14
- [![npm downloads](https://img.shields.io/npm/dm/redscript-mc?color=cb3837)](https://www.npmjs.com/package/redscript-mc)
11
+ [![npm](https://img.shields.io/npm/v/redscript-mc?color=cb3837&label=npm)](https://www.npmjs.com/package/redscript-mc)
12
+ [![CI](https://github.com/bkmashiro/redscript/actions/workflows/ci.yml/badge.svg)](https://github.com/bkmashiro/redscript/actions/workflows/ci.yml)
13
+ [![Tests](https://img.shields.io/badge/tests-3886%20passing-brightgreen)](https://github.com/bkmashiro/redscript)
15
14
  [![VSCode](https://img.shields.io/badge/VSCode-Extension-007ACC?logo=visualstudiocode)](https://marketplace.visualstudio.com/items?itemName=bkmashiro.redscript-vscode)
16
- [![Online IDE](https://img.shields.io/badge/Try-Online%20IDE-orange)](https://redscript-ide.pages.dev)
17
- [![license](https://img.shields.io/badge/license-MIT-blue)](./LICENSE)
18
15
 
19
- [中文版](./README.zh.md) · [Quick Start](#quick-start) · [Docs](https://redscript-docs.pages.dev) · [Contributing](./CONTRIBUTING.md)
20
-
21
- ### 🚀 [Try it online — no install needed!](https://redscript-ide.pages.dev)
22
-
23
- <img src="./demo.gif" alt="RedScript Demo — math curves drawn with particles in Minecraft" width="520" />
24
-
25
- *↑ Five mathematical curves rendered in real-time with particles — 100% vanilla, no mods!*
26
- *`y = x·sin(x)` · `y = sin(x) + ½sin(2x)` · `y = e⁻ˣsin(4x)` · `y = tanh(2x)` · `r = cos(2θ)` rose curve*
27
- *Each curve is computed tick-by-tick using RedScript's fixed-point math stdlib.*
16
+ [中文版](./README.zh.md) · [Documentation](https://redscript-docs.pages.dev) · [Playground](https://redscript-ide.pages.dev)
28
17
 
29
18
  </div>
30
19
 
31
20
  ---
32
21
 
33
- ### What is RedScript?
22
+ ## Why RedScript?
34
23
 
35
- RedScript is a typed scripting language that compiles to vanilla Minecraft datapacks. Write clean code with variables, functions, loops, and events — RedScript handles the scoreboard commands and `.mcfunction` files for you.
24
+ Minecraft datapacks are powerful but painful to write:
36
25
 
37
- **The demo above?** Five math curves drawn with 64 sample points each. The core logic:
26
+ ```mcfunction
27
+ # Vanilla: Check if player has 100+ score and give reward
28
+ execute as @a[scores={points=100..}] run scoreboard players add @s rewards 1
29
+ execute as @a[scores={points=100..}] run scoreboard players set @s points 0
30
+ execute as @a[scores={points=100..}] run give @s minecraft:diamond 1
31
+ execute as @a[scores={points=100..}] run tellraw @s {"text":"Reward claimed!"}
32
+ ```
38
33
 
39
34
  ```rs
40
- import "stdlib/math"
41
-
42
- let phase: int = 0;
43
- let frame: int = 0;
44
-
45
- // 5 curves cycle every 128 ticks (~6.5 s each)
46
- @tick fn _wave_tick() {
47
- phase = (phase + 4) % 360;
48
- frame = frame + 1;
49
-
50
- let curve_id: int = (frame / 128) % 5;
51
-
52
- // Compute sin at 9 column offsets (40° apart = full sine wave span)
53
- let s0: int = sin_fixed((phase + 0) % 360);
54
- let s1: int = sin_fixed((phase + 40) % 360);
55
- // ... s2 through s8 ...
56
-
57
- // Draw bar chart: each column height = sin value
58
- // (64 fixed particle positions per curve, all respawned each tick)
59
- if (curve_id == 0) { _draw_xsinx(); }
60
- if (curve_id == 1) { _draw_harmonic(); }
61
- // ...
62
-
63
- actionbar(@a, f"§e y = x·sin(x) phase: {phase}° center: {s0}‰");
35
+ // RedScript: Same logic, readable
36
+ @tick fn check_rewards() {
37
+ foreach (p in @a) {
38
+ if (scoreboard_get(p, #points) >= 100) {
39
+ scoreboard_add(p, #rewards, 1);
40
+ scoreboard_set(p, #points, 0);
41
+ give(p, "minecraft:diamond", 1);
42
+ tell(p, "Reward claimed!");
43
+ }
44
+ }
64
45
  }
65
46
  ```
66
47
 
67
- **What you get:**
68
- - ✅ `let` / `const` variables (no more `scoreboard players set`)
69
- - ✅ `if` / `else` / `for` / `foreach` / `break` / `continue` control flow
70
- - ✅ `@tick` / `@load` / `@on(Event)` decorators
71
- - ✅ `foreach (p in @a) at @s positioned ~ ~1 ~` and full `execute` subcommand support
72
- - ✅ `match` with range patterns like `70..79`
73
- - ✅ Builtins accept runtime macro variables in any argument position
74
- - ✅ f-strings like `f"Score: {points}"` for dynamic output
75
- - ✅ Public functions are preserved automatically; `_privateFn()` stays private
76
- - ✅ `enum` types with `match` dispatch (zero-runtime overhead)
77
- - ✅ Multi-return values: `fn divmod(a: int, b: int): (int, int)`
78
- - ✅ Generics: `fn max<T>(a: T, b: T): T` (monomorphized)
79
- - ✅ `Option<T>` null safety: `Some(x)` / `None` / `if let Some(x) = opt`
80
- - ✅ `@coroutine(batch=N)` for tick-spread loops (no more maxCommandChain hits)
81
- - ✅ `@schedule(ticks=N)` to delay function execution
82
- - ✅ Module system: `module math; import math::sin;`
83
- - ✅ Multi-version targets: `--mc-version 1.20.2`
84
- - ✅ Source maps: `--source-map` for debugging
85
- - ✅ Language Server Protocol: diagnostics, hover, go-to-def, completion
86
- - ✅ One file -> ready-to-use datapack
48
+ ## Quick Start
87
49
 
88
- ---
89
-
90
- ### Quick Start
91
-
92
- #### Option 1: Online IDE (No Install)
50
+ ### Try Online (No Install)
93
51
 
94
- **[→ redscript-ide.pages.dev](https://redscript-ide.pages.dev)** — Write code, see output instantly.
52
+ **[→ redscript-ide.pages.dev](https://redscript-ide.pages.dev)** — Write code, download datapack.
95
53
 
96
- #### Option 2: VSCode Extension
54
+ ### Install CLI
97
55
 
98
- 1. Install [RedScript for VSCode](https://marketplace.visualstudio.com/items?itemName=bkmashiro.redscript-vscode)
99
- 2. Get syntax highlighting, auto-complete, hover docs, and more
100
-
101
- #### Option 3: CLI
102
-
103
- ```mcrs
104
- struct Timer { _id: int; duration: int; }
56
+ ```bash
57
+ npm install -g redscript-mc
58
+ ```
105
59
 
106
- impl Timer {
107
- fn new(duration: int): Timer {
108
- return Timer { _id: 0, duration: duration };
109
- }
110
- fn done(self): bool { return true; }
111
- }
60
+ ### Hello World
112
61
 
113
- @on(PlayerJoin)
114
- fn welcome(player: Player) {
115
- say(f"Welcome {player}!");
62
+ ```rs
63
+ // hello.mcrs
64
+ @load fn init() {
65
+ say("Hello from RedScript!");
116
66
  }
117
67
 
118
68
  @tick fn game_loop() {
119
- let timer = Timer::new(100);
120
- setTimeout(200, () => { say("Delayed!"); });
69
+ foreach (p in @a[tag=playing]) {
70
+ effect(p, "minecraft:speed", 1, 0, true);
71
+ }
121
72
  }
122
73
  ```
123
74
 
124
75
  ```bash
125
- npm install -g redscript-mc
126
- redscript compile game.mcrs -o ./my-datapack
76
+ redscript build hello.mcrs -o ./my-datapack
127
77
  ```
128
78
 
129
- #### Deploy
130
-
131
- Drop the output folder into your world's `datapacks/` directory and run `/reload`. Done.
79
+ Drop `my-datapack/` into your world's `datapacks/` folder, run `/reload`. Done.
132
80
 
133
81
  ---
134
82
 
135
- ### The Language
136
-
137
- #### Variables & Types
138
-
139
- ```rs
140
- let x: int = 42;
141
- let name: string = "Steve";
142
- let spawn: BlockPos = (0, 64, 0);
143
- let nearby: BlockPos = (~5, ~0, ~5); // relative coords
144
- const MAX: int = 100; // compile-time constant
145
- ```
146
-
147
- #### MC Names (Objectives, Tags, Teams)
148
-
149
- Use `#name` for Minecraft identifiers — no quotes needed:
150
-
151
- ```rs
152
- // Objectives, fake players, tags, teams — write without quotes
153
- let hp: int = scoreboard_get(@s, #health);
154
- scoreboard_set(#game, #timer, 300); // fake player #game, objective timer
155
- tag_add(@s, #hasKey);
156
- team_join(#red, @s);
157
- gamerule(#keepInventory, true);
158
-
159
- // String literals still work (backward compatible)
160
- scoreboard_get(@s, "health") // same output as #health
161
- ```
162
-
163
- #### Functions & Defaults
83
+ ## Features
164
84
 
165
- ```rs
166
- fn greet(player: selector, msg: string = "Welcome!") {
167
- tell(player, msg);
168
- }
85
+ ### Language
169
86
 
170
- greet(@s); // uses default message
171
- greet(@a, "Hello!"); // override
172
- ```
87
+ | Feature | Example |
88
+ |---------|---------|
89
+ | Variables | `let x: int = 42;` |
90
+ | Functions | `fn damage(target: selector, amount: int) { ... }` |
91
+ | Control flow | `if`, `else`, `for`, `while`, `foreach`, `match` |
92
+ | Structs | `struct Player { score: int, alive: bool }` |
93
+ | Enums | `enum State { Lobby, Playing, Ended }` |
94
+ | Option type | `let item: Option<int> = Some(5);` |
95
+ | Result type | `let r: Result<int, string> = Ok(42);` |
96
+ | F-strings | `say(f"Score: {points}");` |
97
+ | Modules | `import math; math::sin(45);` |
173
98
 
174
- #### Decorators
99
+ ### Minecraft Integration
175
100
 
176
101
  ```rs
177
- @tick // every tick
178
- fn heartbeat() { ... }
179
-
180
- @tick(rate=20) // every second
181
- fn every_second() { ... }
102
+ // Decorators for game events
103
+ @tick fn every_tick() { }
104
+ @tick(rate=20) fn every_second() { }
105
+ @load fn on_datapack_load() { }
106
+ @on(PlayerJoin) fn welcome(p: Player) { }
182
107
 
183
- @on_advancement("story/mine_diamond")
184
- fn on_diamond() {
185
- give(@s, "minecraft:diamond", 5);
108
+ // Entity selectors work naturally
109
+ foreach (zombie in @e[type=zombie, distance=..10]) {
110
+ kill(zombie);
186
111
  }
187
112
 
188
- @on_death
189
- fn on_death() {
190
- scoreboard_add(@s, #deaths, 1);
113
+ // Execute subcommands
114
+ foreach (p in @a) at @s positioned ~ ~2 ~ {
115
+ particle("minecraft:flame", ~0, ~0, ~0, 0.1, 0.1, 0.1, 0.01, 10);
191
116
  }
192
117
 
193
- // Delay execution by N ticks (20t = 1 second)
194
- @schedule(ticks=20)
195
- fn after_one_second(): void {
196
- title(@a, "One second later!");
197
- }
198
-
199
- // Spread a heavy loop across multiple ticks (batch=N iterations/tick)
200
- @coroutine(batch=50, onDone=all_done)
201
- fn process_all(): void {
202
- let i: int = 0;
203
- while (i < 1000) {
204
- // work spread over ~20 ticks instead of lagging one tick
205
- i = i + 1;
118
+ // Coroutines for heavy work (spread across ticks)
119
+ @coroutine(batch=100)
120
+ fn process_all() {
121
+ for (let i = 0; i < 10000; i = i + 1) {
122
+ // Won't lag — runs 100 iterations per tick
206
123
  }
207
124
  }
208
125
  ```
209
126
 
210
- #### Control Flow
211
-
212
- ```rs
213
- if (hp <= 0) {
214
- respawn();
215
- } else if (hp < 5) {
216
- warn_player();
217
- }
218
-
219
- for (let i: int = 0; i < 10; i = i + 1) {
220
- say(f"Spawning wave {i}");
221
- summon("minecraft:zombie", ~0, ~0, ~0);
222
- }
223
-
224
- foreach (player in @a) {
225
- heal(player, 2);
226
- }
227
- ```
228
-
229
- #### Structs & Enums
230
-
231
- ```rs
232
- enum Phase { Lobby, Playing, Ended }
233
-
234
- struct Player {
235
- score: int,
236
- alive: bool,
237
- }
238
-
239
- match (phase) {
240
- Phase::Lobby => { announce("Waiting..."); }
241
- Phase::Playing => { every_second(); }
242
- Phase::Ended => { show_scoreboard(); }
243
- }
244
- ```
245
-
246
- #### Lambdas
247
-
248
- ```rs
249
- fn apply(f: (int) -> int, x: int) -> int {
250
- return f(x);
251
- }
252
-
253
- let double = (x: int) -> int { return x * 2; };
254
- apply(double, 5); // 10
255
- ```
256
-
257
- #### Arrays
258
-
259
- ```rs
260
- let scores: int[] = [];
261
- push(scores, 42);
127
+ ### Tooling
262
128
 
263
- foreach (s in scores) {
264
- announce("Score: ${s}");
265
- }
266
- ```
129
+ - **15 optimizer passes** — Dead code elimination, constant folding, inlining, etc.
130
+ - **LSP** — Hover docs, go-to-definition, auto-complete, diagnostics
131
+ - **VSCode Extension** — Full syntax highlighting and snippets
132
+ - **50 stdlib modules** — Math, vectors, pathfinding, particles, and more
267
133
 
268
134
  ---
269
135
 
270
- ### CLI Reference
136
+ ## CLI Commands
271
137
 
272
- ```
273
- redscript compile <file> Compile to datapack (default) or structure
274
- -o, --output <dir> Output directory [default: ./out]
275
- --target datapack|structure Output format [default: datapack]
276
- --namespace <ns> Datapack namespace [default: filename]
277
- --mc-version <ver> Target MC version [default: 1.21]
278
- --include <dir> Extra library search path (repeatable)
279
- --source-map Emit .mcrs.map source map for debugging
280
- --no-optimize Skip optimizer passes
281
- --stats Print optimizer statistics
282
-
283
- redscript repl Interactive REPL
284
- redscript validate <file> Validate MC commands
138
+ ```bash
139
+ redscript build <file> # Compile with optimizations
140
+ redscript compile <file> # Compile without optimizations
141
+ redscript check <file> # Type check only
142
+ redscript fmt <file> # Format code
143
+ redscript lint <file> # Static analysis
144
+ redscript test <file> # Run @test functions
145
+ redscript watch <dir> # Watch mode with hot reload
146
+ redscript docs [module] # Open stdlib docs
285
147
  ```
286
148
 
287
149
  ---
288
150
 
289
- ### Stdlib
151
+ ## Standard Library
290
152
 
291
- RedScript ships a built-in standard library. Use the short form — no path needed:
153
+ 50 modules covering math, data structures, game systems, and MC-specific helpers:
292
154
 
293
155
  ```rs
294
- import "stdlib/math" // fixed-point math: ln, sqrt_fx, exp_fx, sin_fixed, cos_fixed...
295
- import "stdlib/math_hp" // high-precision trig via entity rotation (init_trig required)
296
- import "stdlib/vec" // 2D/3D vector: dot, cross, length, distance, atan2, rotate...
297
- import "stdlib/random" // LCG & PCG random number generators
298
- import "stdlib/color" // RGB/HSL color packing, blending, conversion
299
- import "stdlib/bits" // bitwise AND/OR/XOR/NOT/shift/popcount (integer-simulated)
300
- import "stdlib/list" // sort3, min/max/avg, weighted utilities
301
- import "stdlib/geometry" // AABB/sphere contains, parabola physics, angle helpers
302
- import "stdlib/signal" // normal/exponential distributions, bernoulli, weighted choice
303
- import "stdlib/bigint" // 96-bit base-10000 arithmetic (add/sub/mul/div/cmp)
304
- import "stdlib/easing" // 12 easing functions: quad/cubic/sine/bounce/back/smooth
305
- import "stdlib/noise" // value noise, fractal Brownian motion, terrain height
306
- import "stdlib/calculus" // numerical differentiation, trapezoid/Simpson integration, curve length, online statistics
307
- import "stdlib/matrix" // 2D/3D rotation, Display Entity quaternion helpers
308
- import "stdlib/combat" // damage, kill-check helpers
309
- import "stdlib/player" // health, alive check, range
310
- import "stdlib/cooldown" // per-player cooldown tracking
156
+ import math; // sin, cos, sqrt, pow, abs
157
+ import vec; // 2D/3D vectors, dot, cross, normalize
158
+ import random; // LCG/PCG random generators
159
+ import pathfind; // A* pathfinding
160
+ import particles; // Particle helpers
161
+ import inventory; // Slot manipulation
162
+ import scheduler; // Delayed execution
163
+ import ecs; // Entity-component system
164
+ // ... and 42 more
311
165
  ```
312
166
 
313
- All stdlib files use `module library;` — only the functions you actually call are compiled in.
314
-
315
- > Parts of the standard library are inspired by [kaer-3058/large_number](https://github.com/kaer-3058/large_number), a comprehensive math library for Minecraft datapacks.
316
-
317
- Custom library paths can be added with `--include <dir>` so your own modules work the same way.
167
+ Full list: [Stdlib Documentation](https://redscript-docs.pages.dev/en/stdlib/)
318
168
 
319
- **Example computing Fibonacci(50) in-game:**
320
-
321
- ```rs
322
- import "stdlib/bigint"
323
-
324
- fn show_fib() {
325
- bigint_fib(50);
326
- // F(50) = 12,586,269,025 — too big for int32, stored across 3 limbs:
327
- let l0: int = bigint_get_a(0); // 9025
328
- let l1: int = bigint_get_a(1); // 8626
329
- let l2: int = bigint_get_a(2); // 125
330
- say(f"F(50) limbs: {l2} {l1} {l0}");
331
- }
332
- ```
169
+ > **Attribution:** The `bigint` module's multi-precision arithmetic approach was inspired by [kaer-3058/large_number](https://github.com/kaer-3058/large_number).
333
170
 
334
171
  ---
335
172
 
336
- ### Examples
337
-
338
- The `examples/` directory contains ready-to-compile demos:
173
+ ## Examples
339
174
 
340
- | File | What it shows |
341
- |---|---|
342
- | `readme-demo.mcrs` | Real-time sine wave particles — `@tick`, `foreach`, f-strings, math stdlib |
343
- | `math-showcase.mcrs` | All stdlib math modules: trig, vectors, BigInt, fractals |
344
- | `showcase.mcrs` | Full feature tour: structs, enums, `match`, lambdas, `@tick`/`@load` |
345
- | `coroutine-demo.mcrs` | `@coroutine(batch=50)` — spread 1000 iterations across ~20 ticks |
346
- | `enum-demo.mcrs` | Enum state machine: NPC AI cycling Idle → Moving → Attacking with `match` |
347
- | `scheduler-demo.mcrs` | `@schedule(ticks=20)` — delayed events, chained schedules |
175
+ | File | Description |
176
+ |------|-------------|
177
+ | [`loops-demo.mcrs`](./examples/loops-demo.mcrs) | All loop constructs |
178
+ | [`showcase.mcrs`](./examples/showcase.mcrs) | Full feature tour |
348
179
 
349
- Compile any example:
350
- ```bash
351
- node dist/cli.js compile examples/coroutine-demo.mcrs -o ~/mc-server/datapacks/demo --namespace demo
352
- ```
180
+ More in the [`examples/`](./examples/) directory.
353
181
 
354
182
  ---
355
183
 
356
- ### Changelog Highlights
357
-
358
- #### v1.2.27 (2026-03-14)
359
-
360
- - **BigInt real-MC fix**: `storage_set_int` macro now uses `execute store result storage` instead of `data modify set value $(n)` — avoids a Minecraft macro substitution bug with integer values; BigInt confirmed working on Paper 1.21.4
361
- - **showcase**: `atan2_fixed` returns degrees (0–360), not millidegrees; fixed over-division in examples; `mod_pow` test cases use small safe-range moduli (no INT32 overflow)
362
-
363
- #### v1.2.26 (2026-03-14)
364
-
365
- - Full math/vector/advanced/bigint standard library (see above)
366
- - `module library;` pragma for zero-cost tree-shaking
367
- - `storage_get_int` / `storage_set_int` dynamic NBT array builtins
368
- - Compiler bug fixes: `isqrt` convergence, copy propagation, variable scoping
184
+ ## Documentation
369
185
 
370
- #### v1.2.25 (2026-03-13)
371
-
372
- - Entity type hierarchy with `W_IMPOSSIBLE_AS` warnings
373
- - Variable name mangling (`$a`, `$b`, `$c`, ...) for minimal scoreboard footprint
374
- - Automated CI/CD: npm publish + VSCode extension on every push
375
-
376
- #### v1.2.0
377
-
378
- - `impl` blocks, methods, and static constructors
379
- - `is` type narrowing for entity-safe control flow
380
- - `@on(Event)` static events and callback scheduling builtins
381
- - Runtime f-strings for output functions
382
- - Expanded stdlib with Timer OOP APIs and 313 MC tag constants
383
- - Dead code elimination
384
-
385
- See [CHANGELOG.md](./CHANGELOG.md) for the full release notes.
186
+ - **[Getting Started](https://redscript-docs.pages.dev/en/guide/)** — Installation and first project
187
+ - **[Language Reference](https://redscript-docs.pages.dev/en/reference/)** — Complete syntax guide
188
+ - **[Stdlib Reference](https://redscript-docs.pages.dev/en/stdlib/)** All 50 modules documented
189
+ - **[CLI Reference](https://redscript-docs.pages.dev/en/cli/)** Command line options
386
190
 
387
191
  ---
388
192
 
389
- ## Acknowledgements
193
+ ## Links
390
194
 
391
- Parts of the standard library are inspired by [kaer-3058/large_number](https://github.com/kaer-3058/large_number), a comprehensive math library for Minecraft datapacks. RedScript provides a higher-level, type-safe API over similar algorithms.
195
+ - [Online Playground](https://redscript-ide.pages.dev)
196
+ - [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=bkmashiro.redscript-vscode)
197
+ - [npm Package](https://www.npmjs.com/package/redscript-mc)
198
+ - [Changelog](./CHANGELOG.md)
199
+ - [Contributing](./CONTRIBUTING.md)
392
200
 
393
201
  ---
394
202
 
395
203
  <div align="center">
396
204
 
397
- MIT License · Copyright © 2026 [bkmashiro](https://github.com/bkmashiro)
398
-
399
- *Write less. Build more. Ship faster.*
205
+ MIT License · [bkmashiro](https://github.com/bkmashiro)
400
206
 
401
207
  </div>