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.
- package/.github/workflows/ci.yml +1 -0
- package/README.md +119 -313
- package/README.zh.md +118 -314
- package/ROADMAP.md +5 -5
- package/dist/data/impl_test/function/counter/get.mcfunction +5 -0
- package/dist/data/impl_test/function/counter/inc.mcfunction +7 -0
- package/dist/data/impl_test/function/counter/new.mcfunction +4 -0
- package/dist/data/impl_test/function/load.mcfunction +1 -0
- package/dist/data/impl_test/function/test_impl.mcfunction +10 -0
- package/dist/data/minecraft/tags/function/load.json +5 -0
- package/dist/data/playground/function/load.mcfunction +1 -0
- package/dist/data/playground/function/start.mcfunction +4 -0
- package/dist/data/playground/function/start__say_macro_t1.mcfunction +1 -0
- package/dist/data/playground/function/stop.mcfunction +5 -0
- package/dist/data/playground/function/stop__say_macro_t0.mcfunction +1 -0
- package/dist/data/stdlib_queue8_test/function/__queue_append_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/__queue_peek_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/__queue_size_raw_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/load.mcfunction +1 -0
- package/dist/data/stdlib_queue8_test/function/queue_clear.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_empty__merge_1.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_empty__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_peek__merge_1.mcfunction +13 -0
- package/dist/data/stdlib_queue8_test/function/queue_peek__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_pop__merge_1.mcfunction +15 -0
- package/dist/data/stdlib_queue8_test/function/queue_pop__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_push__const_11.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_push__const_22.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_size.mcfunction +13 -0
- package/dist/data/stdlib_queue8_test/function/test_queue_push_and_size.mcfunction +13 -0
- package/dist/data/test/function/load.mcfunction +1 -0
- package/dist/data/test/function/say_at.mcfunction +6 -0
- package/dist/data/test/function/test.mcfunction +4 -0
- package/dist/pack.mcmeta +6 -0
- package/dist/package.json +1 -1
- package/dist/src/__tests__/formatter-extra.test.d.ts +7 -0
- package/dist/src/__tests__/formatter-extra.test.js +123 -0
- package/dist/src/__tests__/global-vars.test.d.ts +13 -0
- package/dist/src/__tests__/global-vars.test.js +156 -0
- package/dist/src/__tests__/lint/new-rules.test.d.ts +9 -0
- package/dist/src/__tests__/lint/new-rules.test.js +402 -0
- package/dist/src/__tests__/lsp-rename.test.d.ts +8 -0
- package/dist/src/__tests__/lsp-rename.test.js +157 -0
- package/dist/src/__tests__/mc-integration/say-fstring.test.d.ts +11 -0
- package/dist/src/__tests__/mc-integration/say-fstring.test.js +220 -0
- package/dist/src/__tests__/mc-integration/stdlib-coverage-2.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-3.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-4.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-5.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-6.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-7.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-8.test.js +1 -1
- package/dist/src/__tests__/mc-syntax.test.js +4 -1
- package/dist/src/__tests__/monomorphize-coverage.test.d.ts +9 -0
- package/dist/src/__tests__/monomorphize-coverage.test.js +204 -0
- package/dist/src/__tests__/optimizer-cse.test.d.ts +7 -0
- package/dist/src/__tests__/optimizer-cse.test.js +226 -0
- package/dist/src/__tests__/parser.test.js +4 -13
- package/dist/src/__tests__/repl-server-extra.test.js +6 -7
- package/dist/src/__tests__/repl-server.test.js +5 -7
- package/dist/src/__tests__/stdlib/queue.test.js +6 -6
- package/dist/src/cli.js +0 -0
- package/dist/src/lexer/index.js +2 -1
- package/dist/src/lint/index.d.ts +12 -5
- package/dist/src/lint/index.js +730 -5
- package/dist/src/lsp/main.js +0 -0
- package/dist/src/mc-test/client.d.ts +21 -0
- package/dist/src/mc-test/client.js +34 -0
- package/dist/src/mir/lower.js +108 -6
- package/dist/src/optimizer/interprocedural.js +37 -2
- package/dist/src/parser/decl-parser.d.ts +19 -0
- package/dist/src/parser/decl-parser.js +323 -0
- package/dist/src/parser/expr-parser.d.ts +46 -0
- package/dist/src/parser/expr-parser.js +759 -0
- package/dist/src/parser/index.d.ts +8 -129
- package/dist/src/parser/index.js +13 -2262
- package/dist/src/parser/stmt-parser.d.ts +28 -0
- package/dist/src/parser/stmt-parser.js +577 -0
- package/dist/src/parser/type-parser.d.ts +20 -0
- package/dist/src/parser/type-parser.js +257 -0
- package/dist/src/parser/utils.d.ts +34 -0
- package/dist/src/parser/utils.js +141 -0
- package/docs/dev/README-mc-integration-tests.md +141 -0
- package/docs/lint-rules.md +162 -0
- package/docs/stdlib/bigint.md +2 -0
- package/editors/vscode/README.md +63 -41
- package/editors/vscode/out/extension.js +1881 -1776
- package/editors/vscode/out/lsp-server.js +4257 -3651
- package/editors/vscode/package-lock.json +3 -3
- package/editors/vscode/package.json +1 -1
- package/examples/loops-demo.mcrs +87 -0
- package/package.json +1 -1
- package/redscript-docs/docs/en/stdlib/advanced.md +629 -0
- package/redscript-docs/docs/en/stdlib/bigint.md +316 -0
- package/redscript-docs/docs/en/stdlib/bits.md +292 -0
- package/redscript-docs/docs/en/stdlib/bossbar.md +177 -0
- package/redscript-docs/docs/en/stdlib/calculus.md +289 -0
- package/redscript-docs/docs/en/stdlib/color.md +353 -0
- package/redscript-docs/docs/en/stdlib/combat.md +88 -0
- package/redscript-docs/docs/en/stdlib/cooldown.md +82 -0
- package/redscript-docs/docs/en/stdlib/dialog.md +155 -0
- package/redscript-docs/docs/en/stdlib/easing.md +558 -0
- package/redscript-docs/docs/en/stdlib/ecs.md +475 -0
- package/redscript-docs/docs/en/stdlib/effects.md +324 -0
- package/redscript-docs/docs/en/stdlib/events.md +3 -0
- package/redscript-docs/docs/en/stdlib/expr.md +45 -0
- package/redscript-docs/docs/en/stdlib/fft.md +141 -0
- package/redscript-docs/docs/en/stdlib/geometry.md +430 -0
- package/redscript-docs/docs/en/stdlib/graph.md +259 -0
- package/redscript-docs/docs/en/stdlib/heap.md +185 -0
- package/redscript-docs/docs/en/stdlib/interactions.md +179 -0
- package/redscript-docs/docs/en/stdlib/inventory.md +97 -0
- package/redscript-docs/docs/en/stdlib/linalg.md +557 -0
- package/redscript-docs/docs/en/stdlib/list.md +559 -0
- package/redscript-docs/docs/en/stdlib/map.md +140 -0
- package/redscript-docs/docs/en/stdlib/math.md +193 -0
- package/redscript-docs/docs/en/stdlib/math_hp.md +149 -0
- package/redscript-docs/docs/en/stdlib/matrix.md +403 -0
- package/redscript-docs/docs/en/stdlib/mobs.md +965 -0
- package/redscript-docs/docs/en/stdlib/noise.md +244 -0
- package/redscript-docs/docs/en/stdlib/ode.md +253 -0
- package/redscript-docs/docs/en/stdlib/parabola.md +342 -0
- package/redscript-docs/docs/en/stdlib/particles.md +311 -0
- package/redscript-docs/docs/en/stdlib/pathfind.md +255 -0
- package/redscript-docs/docs/en/stdlib/physics.md +493 -0
- package/redscript-docs/docs/en/stdlib/player.md +78 -0
- package/redscript-docs/docs/en/stdlib/quaternion.md +673 -0
- package/redscript-docs/docs/en/stdlib/queue.md +134 -0
- package/redscript-docs/docs/en/stdlib/random.md +223 -0
- package/redscript-docs/docs/en/stdlib/result.md +143 -0
- package/redscript-docs/docs/en/stdlib/scheduler.md +183 -0
- package/redscript-docs/docs/en/stdlib/set_int.md +190 -0
- package/redscript-docs/docs/en/stdlib/sets.md +101 -0
- package/redscript-docs/docs/en/stdlib/signal.md +400 -0
- package/redscript-docs/docs/en/stdlib/sort.md +104 -0
- package/redscript-docs/docs/en/stdlib/spawn.md +147 -0
- package/redscript-docs/docs/en/stdlib/state.md +142 -0
- package/redscript-docs/docs/en/stdlib/strings.md +154 -0
- package/redscript-docs/docs/en/stdlib/tags.md +3451 -0
- package/redscript-docs/docs/en/stdlib/teams.md +153 -0
- package/redscript-docs/docs/en/stdlib/timer.md +246 -0
- package/redscript-docs/docs/en/stdlib/vec.md +158 -0
- package/redscript-docs/docs/en/stdlib/world.md +298 -0
- package/redscript-docs/docs/zh/stdlib/advanced.md +615 -0
- package/redscript-docs/docs/zh/stdlib/bigint.md +316 -0
- package/redscript-docs/docs/zh/stdlib/bits.md +292 -0
- package/redscript-docs/docs/zh/stdlib/bossbar.md +170 -0
- package/redscript-docs/docs/zh/stdlib/calculus.md +287 -0
- package/redscript-docs/docs/zh/stdlib/color.md +353 -0
- package/redscript-docs/docs/zh/stdlib/combat.md +88 -0
- package/redscript-docs/docs/zh/stdlib/cooldown.md +84 -0
- package/redscript-docs/docs/zh/stdlib/dialog.md +152 -0
- package/redscript-docs/docs/zh/stdlib/easing.md +558 -0
- package/redscript-docs/docs/zh/stdlib/ecs.md +472 -0
- package/redscript-docs/docs/zh/stdlib/effects.md +324 -0
- package/redscript-docs/docs/zh/stdlib/events.md +3 -0
- package/redscript-docs/docs/zh/stdlib/expr.md +37 -0
- package/redscript-docs/docs/zh/stdlib/fft.md +128 -0
- package/redscript-docs/docs/zh/stdlib/geometry.md +430 -0
- package/redscript-docs/docs/zh/stdlib/graph.md +259 -0
- package/redscript-docs/docs/zh/stdlib/heap.md +185 -0
- package/redscript-docs/docs/zh/stdlib/interactions.md +160 -0
- package/redscript-docs/docs/zh/stdlib/inventory.md +94 -0
- package/redscript-docs/docs/zh/stdlib/linalg.md +543 -0
- package/redscript-docs/docs/zh/stdlib/list.md +561 -0
- package/redscript-docs/docs/zh/stdlib/map.md +132 -0
- package/redscript-docs/docs/zh/stdlib/math.md +193 -0
- package/redscript-docs/docs/zh/stdlib/math_hp.md +143 -0
- package/redscript-docs/docs/zh/stdlib/matrix.md +396 -0
- package/redscript-docs/docs/zh/stdlib/mobs.md +965 -0
- package/redscript-docs/docs/zh/stdlib/noise.md +244 -0
- package/redscript-docs/docs/zh/stdlib/ode.md +243 -0
- package/redscript-docs/docs/zh/stdlib/parabola.md +337 -0
- package/redscript-docs/docs/zh/stdlib/particles.md +307 -0
- package/redscript-docs/docs/zh/stdlib/pathfind.md +255 -0
- package/redscript-docs/docs/zh/stdlib/physics.md +493 -0
- package/redscript-docs/docs/zh/stdlib/player.md +78 -0
- package/redscript-docs/docs/zh/stdlib/quaternion.md +669 -0
- package/redscript-docs/docs/zh/stdlib/queue.md +124 -0
- package/redscript-docs/docs/zh/stdlib/random.md +222 -0
- package/redscript-docs/docs/zh/stdlib/result.md +147 -0
- package/redscript-docs/docs/zh/stdlib/scheduler.md +173 -0
- package/redscript-docs/docs/zh/stdlib/set_int.md +180 -0
- package/redscript-docs/docs/zh/stdlib/sets.md +107 -0
- package/redscript-docs/docs/zh/stdlib/signal.md +373 -0
- package/redscript-docs/docs/zh/stdlib/sort.md +104 -0
- package/redscript-docs/docs/zh/stdlib/spawn.md +142 -0
- package/redscript-docs/docs/zh/stdlib/state.md +134 -0
- package/redscript-docs/docs/zh/stdlib/strings.md +107 -0
- package/redscript-docs/docs/zh/stdlib/tags.md +3451 -0
- package/redscript-docs/docs/zh/stdlib/teams.md +150 -0
- package/redscript-docs/docs/zh/stdlib/timer.md +254 -0
- package/redscript-docs/docs/zh/stdlib/vec.md +158 -0
- package/redscript-docs/docs/zh/stdlib/world.md +289 -0
- package/src/__tests__/formatter-extra.test.ts +139 -0
- package/src/__tests__/global-vars.test.ts +171 -0
- package/src/__tests__/lint/new-rules.test.ts +437 -0
- package/src/__tests__/lsp-rename.test.ts +171 -0
- package/src/__tests__/mc-integration/say-fstring.test.ts +211 -0
- package/src/__tests__/mc-integration/stdlib-coverage-2.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-3.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-4.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-5.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-6.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-7.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-8.test.ts +1 -1
- package/src/__tests__/mc-syntax.test.ts +3 -0
- package/src/__tests__/monomorphize-coverage.test.ts +220 -0
- package/src/__tests__/optimizer-cse.test.ts +250 -0
- package/src/__tests__/parser.test.ts +4 -13
- package/src/__tests__/repl-server-extra.test.ts +6 -6
- package/src/__tests__/repl-server.test.ts +5 -6
- package/src/__tests__/stdlib/queue.test.ts +6 -6
- package/src/lexer/index.ts +2 -1
- package/src/lint/index.ts +713 -5
- package/src/mc-test/client.ts +40 -0
- package/src/mir/lower.ts +111 -2
- package/src/optimizer/interprocedural.ts +40 -2
- package/src/parser/decl-parser.ts +349 -0
- package/src/parser/expr-parser.ts +838 -0
- package/src/parser/index.ts +17 -2558
- package/src/parser/stmt-parser.ts +585 -0
- package/src/parser/type-parser.ts +276 -0
- package/src/parser/utils.ts +173 -0
- package/src/stdlib/queue.mcrs +19 -6
package/.github/workflows/ci.yml
CHANGED
package/README.md
CHANGED
|
@@ -2,400 +2,206 @@
|
|
|
2
2
|
|
|
3
3
|
<img src="./logo.png" alt="RedScript Logo" width="64" />
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# RedScript
|
|
6
6
|
|
|
7
|
-
**A typed
|
|
7
|
+
**A typed language that compiles to Minecraft datapacks.**
|
|
8
8
|
|
|
9
|
-
Write clean
|
|
9
|
+
Write clean code. Get vanilla datapacks. No mods required.
|
|
10
10
|
|
|
11
|
-
[](https://www.npmjs.com/package/redscript-mc)
|
|
11
|
+
[](https://www.npmjs.com/package/redscript-mc)
|
|
12
|
+
[](https://github.com/bkmashiro/redscript/actions/workflows/ci.yml)
|
|
13
|
+
[](https://github.com/bkmashiro/redscript)
|
|
15
14
|
[](https://marketplace.visualstudio.com/items?itemName=bkmashiro.redscript-vscode)
|
|
16
|
-
[](https://redscript-ide.pages.dev)
|
|
17
|
-
[](./LICENSE)
|
|
18
15
|
|
|
19
|
-
[中文版](./README.zh.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
|
-
|
|
22
|
+
## Why RedScript?
|
|
34
23
|
|
|
35
|
-
|
|
24
|
+
Minecraft datapacks are powerful but painful to write:
|
|
36
25
|
|
|
37
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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,
|
|
52
|
+
**[→ redscript-ide.pages.dev](https://redscript-ide.pages.dev)** — Write code, download datapack.
|
|
95
53
|
|
|
96
|
-
|
|
54
|
+
### Install CLI
|
|
97
55
|
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
120
|
-
|
|
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
|
-
|
|
126
|
-
redscript compile game.mcrs -o ./my-datapack
|
|
76
|
+
redscript build hello.mcrs -o ./my-datapack
|
|
127
77
|
```
|
|
128
78
|
|
|
129
|
-
|
|
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
|
-
|
|
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
|
-
|
|
166
|
-
fn greet(player: selector, msg: string = "Welcome!") {
|
|
167
|
-
tell(player, msg);
|
|
168
|
-
}
|
|
85
|
+
### Language
|
|
169
86
|
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
99
|
+
### Minecraft Integration
|
|
175
100
|
|
|
176
101
|
```rs
|
|
177
|
-
|
|
178
|
-
fn
|
|
179
|
-
|
|
180
|
-
@
|
|
181
|
-
fn
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
108
|
+
// Entity selectors work naturally
|
|
109
|
+
foreach (zombie in @e[type=zombie, distance=..10]) {
|
|
110
|
+
kill(zombie);
|
|
186
111
|
}
|
|
187
112
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
//
|
|
194
|
-
@
|
|
195
|
-
fn
|
|
196
|
-
|
|
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
|
-
|
|
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
|
-
|
|
264
|
-
|
|
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
|
-
|
|
136
|
+
## CLI Commands
|
|
271
137
|
|
|
272
|
-
```
|
|
273
|
-
redscript
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
151
|
+
## Standard Library
|
|
290
152
|
|
|
291
|
-
|
|
153
|
+
50 modules covering math, data structures, game systems, and MC-specific helpers:
|
|
292
154
|
|
|
293
155
|
```rs
|
|
294
|
-
import
|
|
295
|
-
import
|
|
296
|
-
import
|
|
297
|
-
import
|
|
298
|
-
import
|
|
299
|
-
import
|
|
300
|
-
import
|
|
301
|
-
import
|
|
302
|
-
|
|
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
|
-
|
|
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
|
-
**
|
|
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
|
-
|
|
337
|
-
|
|
338
|
-
The `examples/` directory contains ready-to-compile demos:
|
|
173
|
+
## Examples
|
|
339
174
|
|
|
340
|
-
| File |
|
|
341
|
-
|
|
342
|
-
| `
|
|
343
|
-
| `
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
-
|
|
373
|
-
-
|
|
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
|
-
##
|
|
193
|
+
## Links
|
|
390
194
|
|
|
391
|
-
|
|
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 ·
|
|
398
|
-
|
|
399
|
-
*Write less. Build more. Ship faster.*
|
|
205
|
+
MIT License · [bkmashiro](https://github.com/bkmashiro)
|
|
400
206
|
|
|
401
207
|
</div>
|