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,80 @@
|
|
|
1
|
+
# Structure Target
|
|
2
|
+
|
|
3
|
+
`--target structure` emits a Minecraft structure file (`.nbt`) containing command blocks loaded with the compiled output. This is useful when you want to place the compiler output directly in-world with a Structure Block or `/place structure`, instead of copying loose command blocks by hand.
|
|
4
|
+
|
|
5
|
+
## Workflow
|
|
6
|
+
|
|
7
|
+
Compile a source file into a raw structure NBT:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
redscript compile --target structure src/examples/arena.rs -o arena.nbt
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Then copy the generated file into your datapack's `structures/` folder, for example:
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
world/datapacks/my_pack/structures/arena.nbt
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
After reloading the datapack, place it in-game:
|
|
20
|
+
|
|
21
|
+
```mcfunction
|
|
22
|
+
/place structure my_pack:arena ~ ~ ~
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
You can also preview and load the same file with a Structure Block.
|
|
26
|
+
|
|
27
|
+
## Layout
|
|
28
|
+
|
|
29
|
+
Each non-comment, non-blank line from each generated `.mcfunction` file becomes one command block. Blocks are laid out eastward, then wrapped row-by-row in a snake-friendly grid with a maximum width of 16.
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
Layer Y=0
|
|
33
|
+
|
|
34
|
+
[0,0,0] [1,0,0] [2,0,0] ... [15,0,0]
|
|
35
|
+
[0,0,1] [1,0,1] [2,0,1] ... [15,0,1]
|
|
36
|
+
[0,0,2] [1,0,2] [2,0,2] ... [15,0,2]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Palette usage:
|
|
40
|
+
|
|
41
|
+
- Impulse command block: first command in a non-tick function
|
|
42
|
+
- Chain command block: subsequent commands in the same function
|
|
43
|
+
- Repeating command block: first command in `__tick`, with `auto: 1b`
|
|
44
|
+
|
|
45
|
+
## Optimizations
|
|
46
|
+
|
|
47
|
+
The structure target runs an extra optimization pass after normal IR optimization. It rewrites simple control flow into native command block chaining so the placed structure can branch without extra helper functions.
|
|
48
|
+
|
|
49
|
+
Conditional chain blocks:
|
|
50
|
+
|
|
51
|
+
- A plain chain command block always runs after the previous block.
|
|
52
|
+
- A conditional chain command block runs only if the previous block succeeded.
|
|
53
|
+
- RedScript uses this to flatten small `if` / `else` bodies directly into the chain.
|
|
54
|
+
|
|
55
|
+
Before:
|
|
56
|
+
|
|
57
|
+
```mcfunction
|
|
58
|
+
execute if score $cond rs matches 1.. run function demo:test/then_0
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
After:
|
|
62
|
+
|
|
63
|
+
```mcfunction
|
|
64
|
+
execute if score $cond rs matches 1..
|
|
65
|
+
say big
|
|
66
|
+
give @s diamond
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The first command block is unconditional. The following inlined blocks are emitted as conditional chain command blocks, so they run only when the guard succeeds.
|
|
70
|
+
|
|
71
|
+
Inlining threshold:
|
|
72
|
+
|
|
73
|
+
- RedScript inlines small branch targets up to 8 commands.
|
|
74
|
+
- Larger branches still fall back to helper function calls.
|
|
75
|
+
|
|
76
|
+
## Limitations
|
|
77
|
+
|
|
78
|
+
- Minecraft structures are practical only up to roughly 32k placed blocks before they become awkward to manage.
|
|
79
|
+
- Individual command block commands are still limited to 32767 characters.
|
|
80
|
+
- The structure target serializes command blocks only; it does not gzip the output.
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# Minecraft Java Edition — Command Reference for RedScript
|
|
2
|
+
|
|
3
|
+
*Source: minecraft.wiki — Java Edition only*
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## `/scoreboard`
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
scoreboard objectives add <objective> <criteria> [<displayName>]
|
|
13
|
+
scoreboard objectives remove <objective>
|
|
14
|
+
scoreboard objectives setdisplay <slot> [<objective>]
|
|
15
|
+
scoreboard players set <targets> <objective> <score>
|
|
16
|
+
scoreboard players add <targets> <objective> <score>
|
|
17
|
+
scoreboard players remove <targets> <objective> <score>
|
|
18
|
+
scoreboard players reset <targets> [<objective>]
|
|
19
|
+
scoreboard players get <target> <objective>
|
|
20
|
+
scoreboard players operation <targets> <targetObjective> <operation> <source> <sourceObjective>
|
|
21
|
+
operations: = += -= *= /= %= < > ><
|
|
22
|
+
scoreboard players enable <targets> <objective> [for trigger objectives]
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## `/execute`
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
execute [subcommand...] run <command>
|
|
32
|
+
|
|
33
|
+
Subcommands:
|
|
34
|
+
as <entity> change executor
|
|
35
|
+
at <entity> change position/rotation/dimension to entity
|
|
36
|
+
in <dimension> change dimension
|
|
37
|
+
positioned <pos> change position
|
|
38
|
+
positioned as <entity>
|
|
39
|
+
rotated <rot>
|
|
40
|
+
rotated as <entity>
|
|
41
|
+
anchored (feet|eyes)
|
|
42
|
+
|
|
43
|
+
if/unless entity <entity> test entity existence
|
|
44
|
+
if/unless block <pos> <block> test block
|
|
45
|
+
if/unless score <target> <obj> (matches <range> | (=|<|<=|>|>=) <source> <obj2>)
|
|
46
|
+
if/unless blocks <start> <end> <dest> (all|masked)
|
|
47
|
+
if/unless data (block|entity|storage) <src> <path>
|
|
48
|
+
if/unless biome <pos> <biome>
|
|
49
|
+
if/unless predicate <predicate>
|
|
50
|
+
|
|
51
|
+
store (result|success) score <targets> <objective>
|
|
52
|
+
store (result|success) (block|entity|storage) <target> <path> <type> <scale>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## `/function`
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
function <name>
|
|
62
|
+
function <name> [<arguments>]
|
|
63
|
+
function <name> with (block <pos> | entity <entity> | storage <source>) [<path>]
|
|
64
|
+
|
|
65
|
+
<name> = resource location e.g. mypack:path/to/function
|
|
66
|
+
Calls an mcfunction file. Runs synchronously in the same tick.
|
|
67
|
+
Return value available via /return (Java 1.20+)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## `/data`
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
data get (block <targetPos> | entity <target> | storage <target>) [<path>] [<scale>]
|
|
77
|
+
data merge (block <targetPos> | entity <target> | storage <target>) <nbt>
|
|
78
|
+
data modify (block <targetPos> | entity <target> | storage <target>) <targetPath> <operation> ...
|
|
79
|
+
operations:
|
|
80
|
+
append value <value>
|
|
81
|
+
append from (block|entity|storage) <source> [<path>]
|
|
82
|
+
insert <index> value <value>
|
|
83
|
+
insert <index> from (block|entity|storage) <source> [<path>]
|
|
84
|
+
prepend value <value>
|
|
85
|
+
prepend from (block|entity|storage) <source> [<path>]
|
|
86
|
+
set value <value>
|
|
87
|
+
set from (block|entity|storage) <source> [<path>]
|
|
88
|
+
data remove (block <targetPos> | entity <target> | storage <target>) <path>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## `/schedule`
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
schedule function <function> <time> [append|replace]
|
|
98
|
+
schedule clear <function>
|
|
99
|
+
|
|
100
|
+
<time> examples: 1t (1 tick), 20t (1 second), 1s, 1d
|
|
101
|
+
append = add to queue even if already scheduled
|
|
102
|
+
replace = (default) replace existing schedule
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
## `/return`
|
|
109
|
+
|
|
110
|
+
```
|
|
111
|
+
return <value>
|
|
112
|
+
return run <command>
|
|
113
|
+
return fail
|
|
114
|
+
|
|
115
|
+
Sets the return value of the current function.
|
|
116
|
+
<value> = integer
|
|
117
|
+
Available in Java 1.20+
|
|
118
|
+
Propagates return value up the function call chain.
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
## `/tag`
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
tag <targets> add <name>
|
|
128
|
+
tag <targets> remove <name>
|
|
129
|
+
tag <targets> list
|
|
130
|
+
|
|
131
|
+
Entity tags are string labels.
|
|
132
|
+
Used in selectors: @e[tag=myTag], @e[tag=!excluded]
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## `/trigger`
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
trigger <objective>
|
|
142
|
+
trigger <objective> add <value>
|
|
143
|
+
trigger <objective> set <value>
|
|
144
|
+
|
|
145
|
+
Criterion must be "trigger" type.
|
|
146
|
+
Only works if the objective is enabled for the player: scoreboard players enable <player> <obj>
|
|
147
|
+
After triggering, automatically disabled for that player.
|
|
148
|
+
Used to allow non-operator players to interact with datapacks.
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
## `/team`
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
team add <team> [<displayName>]
|
|
158
|
+
team remove <team>
|
|
159
|
+
team join <team> [<members>]
|
|
160
|
+
team leave [<members>]
|
|
161
|
+
team list [<team>]
|
|
162
|
+
team modify <team> <option> <value>
|
|
163
|
+
options: color, displayName, prefix, suffix, friendlyFire, seeFriendlyInvisibles,
|
|
164
|
+
nametagVisibility, deathMessageVisibility, collisionRule
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
## `/title`
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
title <targets> title <title>
|
|
174
|
+
title <targets> subtitle <title>
|
|
175
|
+
title <targets> actionbar <title>
|
|
176
|
+
title <targets> clear
|
|
177
|
+
title <targets> reset
|
|
178
|
+
title <targets> times <fadeIn> <stay> <fadeOut>
|
|
179
|
+
|
|
180
|
+
<title> = JSON text component e.g. {"text":"hello","color":"red"}
|
|
181
|
+
<targets> = entity selector (usually @a or @s)
|
|
182
|
+
Times in ticks.
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
## `/tellraw`
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
tellraw <targets> <message>
|
|
192
|
+
|
|
193
|
+
<message> = JSON text component:
|
|
194
|
+
{"text": "hello"}
|
|
195
|
+
{"text": "click me", "clickEvent": {"action": "run_command", "value": "/say hi"}}
|
|
196
|
+
{"score": {"name": "@s", "objective": "kills"}}
|
|
197
|
+
["array ", "of ", {"text":"components"}]
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
## `/effect`
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
effect give <targets> <effect> [<seconds>] [<amplifier>] [<hideParticles>]
|
|
207
|
+
effect clear [<targets>] [<effect>]
|
|
208
|
+
|
|
209
|
+
<effect> = effect id e.g. minecraft:speed, minecraft:slowness
|
|
210
|
+
<amplifier> = 0-255 (0 = level 1)
|
|
211
|
+
<seconds> = duration, max 1000000
|
|
212
|
+
<hideParticles> = true|false
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
## `/give`
|
|
219
|
+
|
|
220
|
+
```
|
|
221
|
+
give <targets> <item> [<count>]
|
|
222
|
+
|
|
223
|
+
<item> = item id with optional NBT e.g. minecraft:diamond, minecraft:written_book{...}
|
|
224
|
+
<count> = 1-2147483647
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
## `/kill`
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
kill [<targets>]
|
|
234
|
+
|
|
235
|
+
<targets> = entity selector, default = @s
|
|
236
|
+
Kills the entity (sets health to 0, triggers death event).
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
## `/summon`
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
summon <entity> [<pos>] [<nbt>]
|
|
246
|
+
|
|
247
|
+
<entity> = entity type e.g. minecraft:zombie, minecraft:armor_stand
|
|
248
|
+
<pos> = x y z coordinates
|
|
249
|
+
<nbt> = NBT compound for initialization
|
|
250
|
+
|
|
251
|
+
Common armor stand trick:
|
|
252
|
+
summon minecraft:armor_stand ~ ~ ~ {Invisible:1b,Marker:1b,NoGravity:1b,Tags:["myTag"]}
|
|
253
|
+
- Invisible: no visual
|
|
254
|
+
- Marker: no hitbox, no physics
|
|
255
|
+
- Tags: for later @e[tag=myTag] selection
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
@@ -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.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# RedScript VSCode Extension
|
|
2
|
+
|
|
3
|
+
Syntax highlighting and snippets for [RedScript](https://github.com/bkmashiro/redscript) — a compiler targeting Minecraft Java Edition datapacks.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **RedScript syntax highlighting** (`.rs` files)
|
|
8
|
+
- Keywords: `fn`, `let`, `struct`, `if`, `while`, `for`, `foreach`, `as`, `at`
|
|
9
|
+
- Entity selectors: `@a`, `@e[type=zombie, distance=..5]`, etc.
|
|
10
|
+
- Range literals: `..5`, `1..`, `1..10`
|
|
11
|
+
- Decorators: `@tick`, `@tick(rate=20)`, `@on_trigger("name")`
|
|
12
|
+
- Built-in functions: `say`, `kill`, `give`, `effect`, `raw`, `random`, `spawn_object`
|
|
13
|
+
- Types: `int`, `float`, `bool`, `string`, `void`
|
|
14
|
+
|
|
15
|
+
- **mcfunction syntax highlighting** (`.mcfunction` files)
|
|
16
|
+
- Full command syntax from [MinecraftCommands/syntax-mcfunction](https://github.com/MinecraftCommands/syntax-mcfunction)
|
|
17
|
+
- Entity selectors, NBT, coordinates, resource locations
|
|
18
|
+
|
|
19
|
+
- **Code snippets**
|
|
20
|
+
- `fn` → function declaration
|
|
21
|
+
- `tickfn` → `@tick` function
|
|
22
|
+
- `tickratefn` → `@tick(rate=N)` function
|
|
23
|
+
- `trigfn` → `@on_trigger` handler
|
|
24
|
+
- `foreach` → entity foreach loop
|
|
25
|
+
- `struct` → struct declaration
|
|
26
|
+
- `for` → C-style for loop
|
|
27
|
+
- `spawn` → spawn_object call
|
|
28
|
+
- And more...
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
### From VSIX (manual)
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
cd editors/vscode
|
|
36
|
+
npm install -g @vscode/vsce
|
|
37
|
+
vsce package
|
|
38
|
+
code --install-extension redscript-vscode-0.1.0.vsix
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Note on `.rs` extension
|
|
42
|
+
|
|
43
|
+
RedScript uses `.rs` files, same as Rust. If you have the Rust extension installed, you may need to associate `.rs` files with RedScript manually:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
// settings.json
|
|
47
|
+
{
|
|
48
|
+
"files.associations": {
|
|
49
|
+
"*.rs": "redscript"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or use `.mcrs` extension (we may switch to this in future).
|
|
55
|
+
|
|
56
|
+
## Usage
|
|
57
|
+
|
|
58
|
+
Write RedScript code with full syntax highlighting:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
@tick(rate=20)
|
|
62
|
+
fn check_zombies() {
|
|
63
|
+
foreach (z in @e[type=zombie, distance=..10]) {
|
|
64
|
+
kill(z);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@on_trigger("claim_reward")
|
|
69
|
+
fn handle_claim() {
|
|
70
|
+
give(@s, "minecraft:diamond", 1);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Compile with the CLI:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
redscript compile src/main.rs -o dist/mypack/
|
|
78
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import esbuild from 'esbuild'
|
|
2
|
+
|
|
3
|
+
const watch = process.argv.includes('--watch')
|
|
4
|
+
|
|
5
|
+
/** @type {import('esbuild').BuildOptions} */
|
|
6
|
+
const config = {
|
|
7
|
+
entryPoints: ['src/extension.ts'],
|
|
8
|
+
bundle: true,
|
|
9
|
+
outfile: 'out/extension.js',
|
|
10
|
+
external: ['vscode'], // vscode is provided by the host, never bundle it
|
|
11
|
+
format: 'cjs',
|
|
12
|
+
platform: 'node',
|
|
13
|
+
target: 'node18',
|
|
14
|
+
sourcemap: false,
|
|
15
|
+
minify: false,
|
|
16
|
+
// Stub out Node builtins that the compiler might use
|
|
17
|
+
// (they're fine in the extension since it runs in Node)
|
|
18
|
+
// The compiler uses fs/path, which are available in the extension host
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (watch) {
|
|
22
|
+
const ctx = await esbuild.context(config)
|
|
23
|
+
await ctx.watch()
|
|
24
|
+
console.log('Watching for changes...')
|
|
25
|
+
} else {
|
|
26
|
+
await esbuild.build(config)
|
|
27
|
+
console.log('Built out/extension.js')
|
|
28
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"comments": {
|
|
3
|
+
// symbol used for single line comment. Remove this entry if your language does not support line comments
|
|
4
|
+
"lineComment": "#",
|
|
5
|
+
},
|
|
6
|
+
// symbols used as brackets
|
|
7
|
+
"brackets": [
|
|
8
|
+
["{", "}"],
|
|
9
|
+
["[", "]"],
|
|
10
|
+
["(", ")"]
|
|
11
|
+
],
|
|
12
|
+
// symbols that are auto closed when typing
|
|
13
|
+
"autoClosingPairs": [
|
|
14
|
+
["{", "}"],
|
|
15
|
+
["[", "]"],
|
|
16
|
+
["(", ")"],
|
|
17
|
+
["\"", "\""],
|
|
18
|
+
["'", "'"]
|
|
19
|
+
],
|
|
20
|
+
// symbols that can be used to surround a selection
|
|
21
|
+
"surroundingPairs": [
|
|
22
|
+
["{", "}"],
|
|
23
|
+
["[", "]"],
|
|
24
|
+
["(", ")"],
|
|
25
|
+
["\"", "\""],
|
|
26
|
+
["'", "'"]
|
|
27
|
+
]
|
|
28
|
+
}
|