redscript-mc 1.0.0
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/ISSUE_TEMPLATE/bug_report.md +40 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +31 -0
- package/.github/ISSUE_TEMPLATE/wrong_output.md +33 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +34 -0
- package/.github/workflows/ci.yml +29 -0
- package/.github/workflows/publish-extension.yml +35 -0
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/README.zh.md +261 -0
- package/dist/__tests__/cli.test.d.ts +1 -0
- package/dist/__tests__/cli.test.js +140 -0
- package/dist/__tests__/codegen.test.d.ts +1 -0
- package/dist/__tests__/codegen.test.js +121 -0
- package/dist/__tests__/diagnostics.test.d.ts +4 -0
- package/dist/__tests__/diagnostics.test.js +149 -0
- package/dist/__tests__/e2e.test.d.ts +6 -0
- package/dist/__tests__/e2e.test.js +1528 -0
- package/dist/__tests__/lexer.test.d.ts +1 -0
- package/dist/__tests__/lexer.test.js +316 -0
- package/dist/__tests__/lowering.test.d.ts +1 -0
- package/dist/__tests__/lowering.test.js +819 -0
- package/dist/__tests__/mc-integration.test.d.ts +12 -0
- package/dist/__tests__/mc-integration.test.js +395 -0
- package/dist/__tests__/mc-syntax.test.d.ts +1 -0
- package/dist/__tests__/mc-syntax.test.js +112 -0
- package/dist/__tests__/nbt.test.d.ts +1 -0
- package/dist/__tests__/nbt.test.js +82 -0
- package/dist/__tests__/optimizer-advanced.test.d.ts +1 -0
- package/dist/__tests__/optimizer-advanced.test.js +124 -0
- package/dist/__tests__/optimizer.test.d.ts +1 -0
- package/dist/__tests__/optimizer.test.js +118 -0
- package/dist/__tests__/parser.test.d.ts +1 -0
- package/dist/__tests__/parser.test.js +717 -0
- package/dist/__tests__/repl.test.d.ts +1 -0
- package/dist/__tests__/repl.test.js +27 -0
- package/dist/__tests__/runtime.test.d.ts +1 -0
- package/dist/__tests__/runtime.test.js +276 -0
- package/dist/__tests__/structure-optimizer.test.d.ts +1 -0
- package/dist/__tests__/structure-optimizer.test.js +33 -0
- package/dist/__tests__/typechecker.test.d.ts +1 -0
- package/dist/__tests__/typechecker.test.js +364 -0
- package/dist/ast/types.d.ts +357 -0
- package/dist/ast/types.js +9 -0
- package/dist/cli.d.ts +11 -0
- package/dist/cli.js +407 -0
- package/dist/codegen/cmdblock/index.d.ts +26 -0
- package/dist/codegen/cmdblock/index.js +45 -0
- package/dist/codegen/mcfunction/index.d.ts +34 -0
- package/dist/codegen/mcfunction/index.js +413 -0
- package/dist/codegen/structure/index.d.ts +18 -0
- package/dist/codegen/structure/index.js +249 -0
- package/dist/compile.d.ts +30 -0
- package/dist/compile.js +152 -0
- package/dist/data/arena/function/__load.mcfunction +6 -0
- package/dist/data/arena/function/__tick.mcfunction +2 -0
- package/dist/data/arena/function/announce_leaders/else_1.mcfunction +3 -0
- package/dist/data/arena/function/announce_leaders/foreach_0/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/foreach_0/then_0.mcfunction +3 -0
- package/dist/data/arena/function/announce_leaders/foreach_0.mcfunction +7 -0
- package/dist/data/arena/function/announce_leaders/foreach_1/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/foreach_1/then_0.mcfunction +4 -0
- package/dist/data/arena/function/announce_leaders/foreach_1.mcfunction +6 -0
- package/dist/data/arena/function/announce_leaders/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/announce_leaders/then_0.mcfunction +4 -0
- package/dist/data/arena/function/announce_leaders.mcfunction +6 -0
- package/dist/data/arena/function/arena_tick/merge_2.mcfunction +1 -0
- package/dist/data/arena/function/arena_tick/then_0.mcfunction +4 -0
- package/dist/data/arena/function/arena_tick.mcfunction +11 -0
- package/dist/data/counter/function/__load.mcfunction +5 -0
- package/dist/data/counter/function/__tick.mcfunction +2 -0
- package/dist/data/counter/function/counter_tick/merge_2.mcfunction +1 -0
- package/dist/data/counter/function/counter_tick/then_0.mcfunction +3 -0
- package/dist/data/counter/function/counter_tick.mcfunction +11 -0
- package/dist/data/minecraft/tags/function/load.json +5 -0
- package/dist/data/minecraft/tags/function/tick.json +5 -0
- package/dist/data/quiz/function/__load.mcfunction +16 -0
- package/dist/data/quiz/function/__tick.mcfunction +6 -0
- package/dist/data/quiz/function/__trigger_quiz_a_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_b_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_c_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/__trigger_quiz_start_dispatch.mcfunction +4 -0
- package/dist/data/quiz/function/answer_a.mcfunction +4 -0
- package/dist/data/quiz/function/answer_b.mcfunction +4 -0
- package/dist/data/quiz/function/answer_c.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/else_1.mcfunction +5 -0
- package/dist/data/quiz/function/ask_question/else_4.mcfunction +5 -0
- package/dist/data/quiz/function/ask_question/else_7.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/merge_2.mcfunction +1 -0
- package/dist/data/quiz/function/ask_question/merge_5.mcfunction +2 -0
- package/dist/data/quiz/function/ask_question/merge_8.mcfunction +2 -0
- package/dist/data/quiz/function/ask_question/then_0.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/then_3.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question/then_6.mcfunction +4 -0
- package/dist/data/quiz/function/ask_question.mcfunction +7 -0
- package/dist/data/quiz/function/finish_quiz.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/else_1.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/else_10.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_16.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_4.mcfunction +3 -0
- package/dist/data/quiz/function/handle_answer/else_7.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/merge_11.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_14.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_17.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_2.mcfunction +8 -0
- package/dist/data/quiz/function/handle_answer/merge_5.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/merge_8.mcfunction +2 -0
- package/dist/data/quiz/function/handle_answer/then_0.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_12.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_15.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/then_3.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer/then_6.mcfunction +5 -0
- package/dist/data/quiz/function/handle_answer/then_9.mcfunction +6 -0
- package/dist/data/quiz/function/handle_answer.mcfunction +11 -0
- package/dist/data/quiz/function/start_quiz.mcfunction +5 -0
- package/dist/data/shop/function/__load.mcfunction +7 -0
- package/dist/data/shop/function/__tick.mcfunction +3 -0
- package/dist/data/shop/function/__trigger_shop_buy_dispatch.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/else_1.mcfunction +5 -0
- package/dist/data/shop/function/complete_purchase/else_4.mcfunction +5 -0
- package/dist/data/shop/function/complete_purchase/else_7.mcfunction +3 -0
- package/dist/data/shop/function/complete_purchase/merge_2.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/merge_5.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/merge_8.mcfunction +2 -0
- package/dist/data/shop/function/complete_purchase/then_0.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/then_3.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase/then_6.mcfunction +4 -0
- package/dist/data/shop/function/complete_purchase.mcfunction +7 -0
- package/dist/data/shop/function/handle_shop_trigger.mcfunction +3 -0
- package/dist/data/turret/function/__load.mcfunction +5 -0
- package/dist/data/turret/function/__tick.mcfunction +4 -0
- package/dist/data/turret/function/__trigger_deploy_turret_dispatch.mcfunction +4 -0
- package/dist/data/turret/function/deploy_turret.mcfunction +8 -0
- package/dist/data/turret/function/turret_tick/at_1.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/foreach_0.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/foreach_2.mcfunction +2 -0
- package/dist/data/turret/function/turret_tick/tick_body.mcfunction +3 -0
- package/dist/data/turret/function/turret_tick/tick_skip.mcfunction +1 -0
- package/dist/data/turret/function/turret_tick.mcfunction +5 -0
- package/dist/diagnostics/index.d.ts +44 -0
- package/dist/diagnostics/index.js +140 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +126 -0
- package/dist/ir/builder.d.ts +32 -0
- package/dist/ir/builder.js +99 -0
- package/dist/ir/types.d.ts +117 -0
- package/dist/ir/types.js +15 -0
- package/dist/lexer/index.d.ts +36 -0
- package/dist/lexer/index.js +458 -0
- package/dist/lowering/index.d.ts +106 -0
- package/dist/lowering/index.js +2041 -0
- package/dist/mc-test/client.d.ts +128 -0
- package/dist/mc-test/client.js +174 -0
- package/dist/mc-test/runner.d.ts +28 -0
- package/dist/mc-test/runner.js +150 -0
- package/dist/mc-test/setup.d.ts +11 -0
- package/dist/mc-test/setup.js +98 -0
- package/dist/mc-validator/index.d.ts +17 -0
- package/dist/mc-validator/index.js +322 -0
- package/dist/nbt/index.d.ts +86 -0
- package/dist/nbt/index.js +250 -0
- package/dist/optimizer/commands.d.ts +36 -0
- package/dist/optimizer/commands.js +349 -0
- package/dist/optimizer/passes.d.ts +34 -0
- package/dist/optimizer/passes.js +227 -0
- package/dist/optimizer/structure.d.ts +8 -0
- package/dist/optimizer/structure.js +344 -0
- package/dist/pack.mcmeta +6 -0
- package/dist/parser/index.d.ts +76 -0
- package/dist/parser/index.js +1193 -0
- package/dist/repl.d.ts +16 -0
- package/dist/repl.js +165 -0
- package/dist/runtime/index.d.ts +101 -0
- package/dist/runtime/index.js +1288 -0
- package/dist/typechecker/index.d.ts +42 -0
- package/dist/typechecker/index.js +629 -0
- package/docs/COMPILATION_STATS.md +142 -0
- package/docs/IMPLEMENTATION_GUIDE.md +512 -0
- package/docs/LANGUAGE_REFERENCE.md +415 -0
- package/docs/MC_MAPPING.md +280 -0
- package/docs/STRUCTURE_TARGET.md +80 -0
- package/docs/mc-reference/commands.md +259 -0
- package/editors/vscode/.vscodeignore +10 -0
- package/editors/vscode/LICENSE +21 -0
- package/editors/vscode/README.md +78 -0
- package/editors/vscode/build.mjs +28 -0
- package/editors/vscode/icon.png +0 -0
- package/editors/vscode/mcfunction-language-configuration.json +28 -0
- package/editors/vscode/out/extension.js +7236 -0
- package/editors/vscode/package-lock.json +566 -0
- package/editors/vscode/package.json +137 -0
- package/editors/vscode/redscript-language-configuration.json +28 -0
- package/editors/vscode/snippets/redscript.json +114 -0
- package/editors/vscode/src/codeactions.ts +89 -0
- package/editors/vscode/src/completion.ts +130 -0
- package/editors/vscode/src/extension.ts +239 -0
- package/editors/vscode/src/hover.ts +1120 -0
- package/editors/vscode/src/symbols.ts +207 -0
- package/editors/vscode/syntaxes/mcfunction.tmLanguage.json +740 -0
- package/editors/vscode/syntaxes/redscript.tmLanguage.json +357 -0
- package/editors/vscode/tsconfig.json +13 -0
- package/jest.config.js +5 -0
- package/package.json +38 -0
- package/src/__tests__/cli.test.ts +130 -0
- package/src/__tests__/codegen.test.ts +128 -0
- package/src/__tests__/diagnostics.test.ts +195 -0
- package/src/__tests__/e2e.test.ts +1721 -0
- package/src/__tests__/fixtures/mc-commands-1.21.4.json +18734 -0
- package/src/__tests__/formatter.test.ts +46 -0
- package/src/__tests__/lexer.test.ts +356 -0
- package/src/__tests__/lowering.test.ts +962 -0
- package/src/__tests__/mc-integration.test.ts +409 -0
- package/src/__tests__/mc-syntax.test.ts +96 -0
- package/src/__tests__/nbt.test.ts +58 -0
- package/src/__tests__/optimizer-advanced.test.ts +144 -0
- package/src/__tests__/optimizer.test.ts +129 -0
- package/src/__tests__/parser.test.ts +800 -0
- package/src/__tests__/repl.test.ts +33 -0
- package/src/__tests__/runtime.test.ts +289 -0
- package/src/__tests__/structure-optimizer.test.ts +38 -0
- package/src/__tests__/typechecker.test.ts +395 -0
- package/src/ast/types.ts +248 -0
- package/src/cli.ts +445 -0
- package/src/codegen/cmdblock/index.ts +63 -0
- package/src/codegen/mcfunction/index.ts +471 -0
- package/src/codegen/structure/index.ts +305 -0
- package/src/compile.ts +188 -0
- package/src/diagnostics/index.ts +186 -0
- package/src/examples/README.md +77 -0
- package/src/examples/SHOWCASE_GAME.md +43 -0
- package/src/examples/arena.rs +44 -0
- package/src/examples/counter.rs +12 -0
- package/src/examples/pvp_arena.rs +131 -0
- package/src/examples/quiz.rs +90 -0
- package/src/examples/rpg.rs +13 -0
- package/src/examples/shop.rs +30 -0
- package/src/examples/showcase_game.rs +552 -0
- package/src/examples/stdlib_demo.rs +181 -0
- package/src/examples/turret.rs +27 -0
- package/src/examples/world_manager.rs +23 -0
- package/src/formatter/index.ts +22 -0
- package/src/index.ts +161 -0
- package/src/ir/builder.ts +114 -0
- package/src/ir/types.ts +119 -0
- package/src/lexer/index.ts +555 -0
- package/src/lowering/index.ts +2406 -0
- package/src/mc-test/client.ts +259 -0
- package/src/mc-test/runner.ts +140 -0
- package/src/mc-test/setup.ts +70 -0
- package/src/mc-validator/index.ts +367 -0
- package/src/nbt/index.ts +321 -0
- package/src/optimizer/commands.ts +416 -0
- package/src/optimizer/passes.ts +233 -0
- package/src/optimizer/structure.ts +441 -0
- package/src/parser/index.ts +1437 -0
- package/src/repl.ts +165 -0
- package/src/runtime/index.ts +1403 -0
- package/src/stdlib/README.md +156 -0
- package/src/stdlib/combat.rs +20 -0
- package/src/stdlib/cooldown.rs +45 -0
- package/src/stdlib/math.rs +49 -0
- package/src/stdlib/mobs.rs +99 -0
- package/src/stdlib/player.rs +29 -0
- package/src/stdlib/strings.rs +7 -0
- package/src/stdlib/timer.rs +51 -0
- package/src/templates/README.md +126 -0
- package/src/templates/combat.rs +96 -0
- package/src/templates/economy.rs +40 -0
- package/src/templates/mini-game-framework.rs +117 -0
- package/src/templates/quest.rs +78 -0
- package/src/test_programs/zombie_game.rs +25 -0
- package/src/typechecker/index.ts +737 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug Report
|
|
3
|
+
about: Something isn't compiling right or producing wrong output
|
|
4
|
+
title: '[Bug] '
|
|
5
|
+
labels: bug
|
|
6
|
+
assignees: ''
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Describe the bug
|
|
10
|
+
|
|
11
|
+
<!-- A clear description of what went wrong -->
|
|
12
|
+
|
|
13
|
+
## Source file (minimal repro)
|
|
14
|
+
|
|
15
|
+
```rs
|
|
16
|
+
// Paste the smallest .rs file that reproduces the issue
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Expected output
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
# What MC commands / datapack structure did you expect?
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Actual output / error
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
# Paste the compiler error or wrong mcfunction output
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Environment
|
|
32
|
+
|
|
33
|
+
- RedScript version: <!-- run `redscript --version` -->
|
|
34
|
+
- Node.js version:
|
|
35
|
+
- OS:
|
|
36
|
+
- Target: `datapack` / `structure`
|
|
37
|
+
|
|
38
|
+
## Additional context
|
|
39
|
+
|
|
40
|
+
<!-- Anything else: MC version, optimizer on/off, etc. -->
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature Request
|
|
3
|
+
about: New language feature, builtin, or tooling idea
|
|
4
|
+
title: '[Feature] '
|
|
5
|
+
labels: enhancement
|
|
6
|
+
assignees: ''
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What do you want to do?
|
|
10
|
+
|
|
11
|
+
<!-- Describe the game logic or workflow you're trying to build -->
|
|
12
|
+
|
|
13
|
+
## What would the syntax look like?
|
|
14
|
+
|
|
15
|
+
```rs
|
|
16
|
+
// Show what you wish you could write in RedScript
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## What MC commands should it compile to?
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
# Expected mcfunction output (approximate is fine)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Why is this useful?
|
|
26
|
+
|
|
27
|
+
<!-- What games or use cases does this enable? -->
|
|
28
|
+
|
|
29
|
+
## Alternatives considered
|
|
30
|
+
|
|
31
|
+
<!-- Any workarounds you've tried? -->
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Wrong MC Output
|
|
3
|
+
about: Compiler produces syntactically valid but semantically wrong commands
|
|
4
|
+
title: '[Output] '
|
|
5
|
+
labels: wrong-output
|
|
6
|
+
assignees: ''
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Source
|
|
10
|
+
|
|
11
|
+
```rs
|
|
12
|
+
// The RedScript code
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Compiled output (actual)
|
|
16
|
+
|
|
17
|
+
```mcfunction
|
|
18
|
+
# What the compiler produced
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Expected output
|
|
22
|
+
|
|
23
|
+
```mcfunction
|
|
24
|
+
# What you expected
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## MC version
|
|
28
|
+
|
|
29
|
+
<!-- 1.21.4 / 1.21 / etc. -->
|
|
30
|
+
|
|
31
|
+
## Notes
|
|
32
|
+
|
|
33
|
+
<!-- Does it happen with --no-optimize? Which builtins/features are involved? -->
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
## What does this PR do?
|
|
2
|
+
|
|
3
|
+
<!-- Brief description -->
|
|
4
|
+
|
|
5
|
+
## Type of change
|
|
6
|
+
|
|
7
|
+
- [ ] Bug fix
|
|
8
|
+
- [ ] New language feature
|
|
9
|
+
- [ ] New builtin / stdlib
|
|
10
|
+
- [ ] Optimizer improvement
|
|
11
|
+
- [ ] Tooling / CLI
|
|
12
|
+
- [ ] Docs
|
|
13
|
+
|
|
14
|
+
## Checklist
|
|
15
|
+
|
|
16
|
+
- [ ] `npm run build` passes
|
|
17
|
+
- [ ] `npm test` passes (all existing tests green)
|
|
18
|
+
- [ ] New tests added for new behavior
|
|
19
|
+
- [ ] If adding a builtin: added to `docs/LANGUAGE_REFERENCE.md` and wiki Builtins page
|
|
20
|
+
- [ ] If changing syntax: updated `docs/LANGUAGE_REFERENCE.md`
|
|
21
|
+
|
|
22
|
+
## Test coverage
|
|
23
|
+
|
|
24
|
+
<!-- Which test file(s) cover this change? -->
|
|
25
|
+
|
|
26
|
+
## Example
|
|
27
|
+
|
|
28
|
+
```rs
|
|
29
|
+
// Show a RedScript snippet demonstrating the new feature
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```mcfunction
|
|
33
|
+
# Show the expected compiled output
|
|
34
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
branches: [main]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-node@v4
|
|
14
|
+
with:
|
|
15
|
+
node-version: 20
|
|
16
|
+
cache: npm
|
|
17
|
+
- run: npm install
|
|
18
|
+
- run: npm test
|
|
19
|
+
|
|
20
|
+
build:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
- uses: actions/setup-node@v4
|
|
25
|
+
with:
|
|
26
|
+
node-version: 20
|
|
27
|
+
cache: npm
|
|
28
|
+
- run: npm install
|
|
29
|
+
- run: npm run build
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Publish VSCode Extension
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'vscode-v*' # trigger on tags like vscode-v0.2.0
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
|
|
14
|
+
- uses: actions/setup-node@v4
|
|
15
|
+
with:
|
|
16
|
+
node-version: '20'
|
|
17
|
+
|
|
18
|
+
- name: Install vsce & ovsx
|
|
19
|
+
run: npm install -g @vscode/vsce ovsx
|
|
20
|
+
|
|
21
|
+
- name: Package extension
|
|
22
|
+
working-directory: editors/vscode
|
|
23
|
+
run: vsce package --no-dependencies
|
|
24
|
+
|
|
25
|
+
- name: Publish to VS Marketplace
|
|
26
|
+
working-directory: editors/vscode
|
|
27
|
+
env:
|
|
28
|
+
VSCE_PAT: ${{ secrets.VSCE_PAT }}
|
|
29
|
+
run: vsce publish --no-dependencies -p "$VSCE_PAT"
|
|
30
|
+
|
|
31
|
+
- name: Publish to Open VSX
|
|
32
|
+
working-directory: editors/vscode
|
|
33
|
+
env:
|
|
34
|
+
OVSX_PAT: ${{ secrets.OVSX_PAT }}
|
|
35
|
+
run: ovsx publish *.vsix -p "$OVSX_PAT"
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bkmashiro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="https://img.shields.io/badge/RedScript-1.0-red?style=for-the-badge&logo=minecraft&logoColor=white" alt="RedScript" />
|
|
4
|
+
|
|
5
|
+
**A typed scripting language that compiles to Minecraft datapacks.**
|
|
6
|
+
|
|
7
|
+
Write clean game logic. RedScript handles the scoreboard spaghetti.
|
|
8
|
+
|
|
9
|
+
[](https://github.com/bkmashiro/redscript/actions/workflows/ci.yml)
|
|
10
|
+
[](https://www.npmjs.com/package/redscript-mc)
|
|
11
|
+
[](./LICENSE)
|
|
12
|
+
[](./src/__tests__)
|
|
13
|
+
|
|
14
|
+
[中文版](./README.zh.md) · [Wiki](https://github.com/bkmashiro/redscript/wiki) · [Quick Start](#quick-start)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
### What is RedScript?
|
|
21
|
+
|
|
22
|
+
You want to make a Minecraft mini-game. You need a countdown timer, kill counter, respawn logic, and a scoreboard display. In vanilla MC, that's 40+ `.mcfunction` files, hundreds of `execute if score` commands, and a weekend of debugging.
|
|
23
|
+
|
|
24
|
+
With RedScript, it's this:
|
|
25
|
+
|
|
26
|
+
```rs
|
|
27
|
+
// pvp_game.rs
|
|
28
|
+
import "stdlib/player.rs"
|
|
29
|
+
|
|
30
|
+
const GAME_TIME: int = 300;
|
|
31
|
+
|
|
32
|
+
@tick(rate=20)
|
|
33
|
+
fn every_second() {
|
|
34
|
+
let time: int = scoreboard_get(#game, #timer);
|
|
35
|
+
|
|
36
|
+
if (time <= 0) {
|
|
37
|
+
end_game();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
scoreboard_set(#game, #timer, time - 1);
|
|
42
|
+
actionbar(@a, "⏱ ${time}s remaining");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
fn start_game() {
|
|
46
|
+
scoreboard_set(#game, #timer, GAME_TIME);
|
|
47
|
+
scoreboard_set(#game, #running, 1);
|
|
48
|
+
title(@a, "Fight!", "Game started");
|
|
49
|
+
tp(@a, (0, 64, 0));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fn end_game() {
|
|
53
|
+
scoreboard_set(#game, #running, 0);
|
|
54
|
+
title(@a, "Game Over!");
|
|
55
|
+
announce("Thanks for playing!");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@on_death
|
|
59
|
+
fn on_kill() {
|
|
60
|
+
scoreboard_add(@s, #kills, 1);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
One file. Compiles to a ready-to-use datapack in seconds.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### Quick Start
|
|
69
|
+
|
|
70
|
+
#### Install
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm install -g redscript
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### Compile
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
redscript compile pvp_game.rs -o ./my-datapack
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
✓ Compiled pvp_game.rs
|
|
84
|
+
Namespace : pvp_game
|
|
85
|
+
Functions : 7
|
|
86
|
+
Commands : 34 → 28 (optimizer: −18%)
|
|
87
|
+
Output : ./my-datapack/
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Deploy
|
|
91
|
+
|
|
92
|
+
Drop the output folder into your world's `datapacks/` directory and run `/reload`. Done.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
### The Language
|
|
97
|
+
|
|
98
|
+
#### Variables & Types
|
|
99
|
+
|
|
100
|
+
```rs
|
|
101
|
+
let x: int = 42;
|
|
102
|
+
let name: string = "Steve";
|
|
103
|
+
let spawn: BlockPos = (0, 64, 0);
|
|
104
|
+
let nearby: BlockPos = (~5, ~0, ~5); // relative coords
|
|
105
|
+
const MAX: int = 100; // compile-time constant
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### MC Names (Objectives, Tags, Teams)
|
|
109
|
+
|
|
110
|
+
Use `#name` for Minecraft identifiers — no quotes needed:
|
|
111
|
+
|
|
112
|
+
```rs
|
|
113
|
+
// Objectives, fake players, tags, teams — write without quotes
|
|
114
|
+
let hp: int = scoreboard_get(@s, #health);
|
|
115
|
+
scoreboard_set(#game, #timer, 300); // fake player #game, objective timer
|
|
116
|
+
tag_add(@s, #hasKey);
|
|
117
|
+
team_join(#red, @s);
|
|
118
|
+
gamerule(#keepInventory, true);
|
|
119
|
+
|
|
120
|
+
// String literals still work (backward compatible)
|
|
121
|
+
scoreboard_get(@s, "health") // same output as #health
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
#### Functions & Defaults
|
|
125
|
+
|
|
126
|
+
```rs
|
|
127
|
+
fn greet(player: selector, msg: string = "Welcome!") {
|
|
128
|
+
tell(player, msg);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
greet(@s); // uses default message
|
|
132
|
+
greet(@a, "Hello!"); // override
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### Decorators
|
|
136
|
+
|
|
137
|
+
```rs
|
|
138
|
+
@tick // every tick
|
|
139
|
+
fn heartbeat() { ... }
|
|
140
|
+
|
|
141
|
+
@tick(rate=20) // every second
|
|
142
|
+
fn every_second() { ... }
|
|
143
|
+
|
|
144
|
+
@on_advancement("story/mine_diamond")
|
|
145
|
+
fn on_diamond() {
|
|
146
|
+
give(@s, "minecraft:diamond", 5);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@on_death
|
|
150
|
+
fn on_death() {
|
|
151
|
+
scoreboard_add(@s, #deaths, 1);
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### Control Flow
|
|
156
|
+
|
|
157
|
+
```rs
|
|
158
|
+
if (hp <= 0) {
|
|
159
|
+
respawn();
|
|
160
|
+
} else if (hp < 5) {
|
|
161
|
+
warn_player();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
for (let i: int = 0; i < 10; i = i + 1) {
|
|
165
|
+
summon("minecraft:zombie", (i, 64, 0));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
foreach (player in @a) {
|
|
169
|
+
heal(player, 2);
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### Structs & Enums
|
|
174
|
+
|
|
175
|
+
```rs
|
|
176
|
+
enum Phase { Lobby, Playing, Ended }
|
|
177
|
+
|
|
178
|
+
struct Player {
|
|
179
|
+
score: int,
|
|
180
|
+
alive: bool,
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
match (phase) {
|
|
184
|
+
Phase::Lobby => { announce("Waiting..."); }
|
|
185
|
+
Phase::Playing => { every_second(); }
|
|
186
|
+
Phase::Ended => { show_scoreboard(); }
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### Lambdas
|
|
191
|
+
|
|
192
|
+
```rs
|
|
193
|
+
fn apply(f: (int) -> int, x: int) -> int {
|
|
194
|
+
return f(x);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let double = (x: int) -> int { return x * 2; };
|
|
198
|
+
apply(double, 5); // 10
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
#### Arrays
|
|
202
|
+
|
|
203
|
+
```rs
|
|
204
|
+
let scores: int[] = [];
|
|
205
|
+
push(scores, 42);
|
|
206
|
+
|
|
207
|
+
foreach (s in scores) {
|
|
208
|
+
announce("Score: ${s}");
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
### CLI Reference
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
redscript compile <file> Compile to datapack (default) or structure
|
|
218
|
+
-o, --output <dir> Output directory [default: ./out]
|
|
219
|
+
--target datapack|structure Output format [default: datapack]
|
|
220
|
+
--namespace <ns> Datapack namespace [default: filename]
|
|
221
|
+
--no-optimize Skip optimizer passes
|
|
222
|
+
--stats Print optimizer statistics
|
|
223
|
+
|
|
224
|
+
redscript repl Interactive REPL
|
|
225
|
+
redscript validate <file> Validate MC commands
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
### Standard Library
|
|
231
|
+
|
|
232
|
+
```rs
|
|
233
|
+
import "stdlib/math.rs" // abs, min, max, clamp
|
|
234
|
+
import "stdlib/player.rs" // is_alive, in_range, get_health
|
|
235
|
+
import "stdlib/timer.rs" // start_timer, tick_timer, has_elapsed
|
|
236
|
+
import "stdlib/cooldown.rs" // set_cooldown, check_cooldown
|
|
237
|
+
import "stdlib/mobs.rs" // ZOMBIE, SKELETON, CREEPER, ... (60+ constants)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
### Further Reading
|
|
243
|
+
|
|
244
|
+
| | |
|
|
245
|
+
|---|---|
|
|
246
|
+
| 📖 [Language Reference](docs/LANGUAGE_REFERENCE.md) | Full syntax & type system |
|
|
247
|
+
| 🔧 [Builtins](https://github.com/bkmashiro/redscript/wiki/Builtins) | All 34+ MC builtin functions |
|
|
248
|
+
| ⚡ [Optimizer](https://github.com/bkmashiro/redscript/wiki/Optimizer) | How the optimizer works |
|
|
249
|
+
| 🧱 [Structure Target](docs/STRUCTURE_TARGET.md) | Compile to NBT command block structures |
|
|
250
|
+
| 🧪 [Integration Testing](https://github.com/bkmashiro/redscript/wiki/Integration-Testing) | Test against a real Paper server |
|
|
251
|
+
| 🏗 [Implementation Guide](docs/IMPLEMENTATION_GUIDE.md) | Compiler internals |
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
<div align="center">
|
|
256
|
+
|
|
257
|
+
MIT License · Copyright © 2026 [bkmashiro](https://github.com/bkmashiro)
|
|
258
|
+
|
|
259
|
+
*Write less. Build more. Ship faster.*
|
|
260
|
+
|
|
261
|
+
</div>
|