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
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Sort
|
|
2
|
+
|
|
3
|
+
> Auto-generated from `src/stdlib/sort.mcrs` — do not edit manually.
|
|
4
|
+
|
|
5
|
+
## API
|
|
6
|
+
|
|
7
|
+
- [insertion_sort](#insertion-sort)
|
|
8
|
+
- [insertion_sort_desc](#insertion-sort-desc)
|
|
9
|
+
- [sort_merge](#sort-merge)
|
|
10
|
+
- [merge_sort_noop](#merge-sort-noop)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## `insertion_sort` <Badge type="info" text="v1.0.0" />
|
|
15
|
+
|
|
16
|
+
Sort an integer array ascending in-place using insertion sort.
|
|
17
|
+
|
|
18
|
+
```redscript
|
|
19
|
+
fn insertion_sort(arr: int[], len: int)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Parameters**
|
|
23
|
+
|
|
24
|
+
| Parameter | Description |
|
|
25
|
+
|-----------|-------------|
|
|
26
|
+
| `arr` | Integer array to sort (mutated in-place) |
|
|
27
|
+
| `len` | Number of elements to sort (arr[0..len-1]) |
|
|
28
|
+
|
|
29
|
+
**Returns:** void — arr is sorted ascending after this call
|
|
30
|
+
|
|
31
|
+
**Example**
|
|
32
|
+
|
|
33
|
+
```redscript
|
|
34
|
+
let data: int[] = [30, 10, 50, 20]
|
|
35
|
+
insertion_sort(data, 4)
|
|
36
|
+
// data is now [10, 20, 30, 50]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## `insertion_sort_desc` <Badge type="info" text="v1.0.0" />
|
|
42
|
+
|
|
43
|
+
Sort an integer array descending in-place using insertion sort.
|
|
44
|
+
|
|
45
|
+
```redscript
|
|
46
|
+
fn insertion_sort_desc(arr: int[], len: int)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Parameters**
|
|
50
|
+
|
|
51
|
+
| Parameter | Description |
|
|
52
|
+
|-----------|-------------|
|
|
53
|
+
| `arr` | Integer array to sort (mutated in-place) |
|
|
54
|
+
| `len` | Number of elements to sort (arr[0..len-1]) |
|
|
55
|
+
|
|
56
|
+
**Returns:** void — arr is sorted descending after this call
|
|
57
|
+
|
|
58
|
+
**Example**
|
|
59
|
+
|
|
60
|
+
```redscript
|
|
61
|
+
let scores: int[] = [30, 10, 50, 20]
|
|
62
|
+
insertion_sort_desc(scores, 4)
|
|
63
|
+
// scores is now [50, 30, 20, 10]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## `sort_merge` <Badge type="info" text="v1.0.0" />
|
|
69
|
+
|
|
70
|
+
Merge two sorted integer arrays into a new sorted array.
|
|
71
|
+
|
|
72
|
+
```redscript
|
|
73
|
+
fn sort_merge(a: int[], la: int, b: int[], lb: int): int[]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
**Parameters**
|
|
77
|
+
|
|
78
|
+
| Parameter | Description |
|
|
79
|
+
|-----------|-------------|
|
|
80
|
+
| `a` | First sorted array |
|
|
81
|
+
| `la` | Number of elements in a (a[0..la-1]) |
|
|
82
|
+
| `b` | Second sorted array |
|
|
83
|
+
| `lb` | Number of elements in b (b[0..lb-1]) |
|
|
84
|
+
|
|
85
|
+
**Returns:** New sorted int[] of length la+lb containing all elements of a and b
|
|
86
|
+
|
|
87
|
+
**Example**
|
|
88
|
+
|
|
89
|
+
```redscript
|
|
90
|
+
let merged: int[] = sort_merge([1, 3, 5], 3, [2, 4, 6], 3)
|
|
91
|
+
// result: [1, 2, 3, 4, 5, 6]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## `merge_sort_noop` <Badge type="info" text="v1.0.0" />
|
|
97
|
+
|
|
98
|
+
Default no-op callback for merge_sort_coro. Replace with your own handler to react when sorting completes.
|
|
99
|
+
|
|
100
|
+
```redscript
|
|
101
|
+
fn merge_sort_noop()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Spawn
|
|
2
|
+
|
|
3
|
+
> Auto-generated from `src/stdlib/spawn.mcrs` — do not edit manually.
|
|
4
|
+
|
|
5
|
+
## API
|
|
6
|
+
|
|
7
|
+
- [teleport_to](#teleport-to)
|
|
8
|
+
- [teleport_to_entity](#teleport-to-entity)
|
|
9
|
+
- [spread_players](#spread-players)
|
|
10
|
+
- [gather_all](#gather-all)
|
|
11
|
+
- [launch_up](#launch-up)
|
|
12
|
+
- [goto_lobby](#goto-lobby)
|
|
13
|
+
- [goto_arena](#goto-arena)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## `teleport_to`
|
|
18
|
+
|
|
19
|
+
Teleports the target selector to fixed world coordinates.
|
|
20
|
+
|
|
21
|
+
```redscript
|
|
22
|
+
fn teleport_to(target: selector, x: int, y: int, z: int)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Parameters**
|
|
26
|
+
|
|
27
|
+
| Parameter | Description |
|
|
28
|
+
|-----------|-------------|
|
|
29
|
+
| `target` | Target selector to move |
|
|
30
|
+
| `x` | Destination X coordinate |
|
|
31
|
+
| `y` | Destination Y coordinate |
|
|
32
|
+
| `z` | Destination Z coordinate |
|
|
33
|
+
|
|
34
|
+
**Example**
|
|
35
|
+
|
|
36
|
+
```redscript
|
|
37
|
+
teleport_to(@p, 0, 64, 0)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## `teleport_to_entity`
|
|
43
|
+
|
|
44
|
+
Teleports the target selector to another entity.
|
|
45
|
+
|
|
46
|
+
```redscript
|
|
47
|
+
fn teleport_to_entity(target: selector, dest: selector)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**Parameters**
|
|
51
|
+
|
|
52
|
+
| Parameter | Description |
|
|
53
|
+
|-----------|-------------|
|
|
54
|
+
| `target` | Selector to teleport |
|
|
55
|
+
| `dest` | Selector whose current position is used as the destination |
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## `spread_players`
|
|
60
|
+
|
|
61
|
+
Placeholder helper for spreading all players randomly in an area.
|
|
62
|
+
The raw `spreadplayers` command is noted here but not emitted yet.
|
|
63
|
+
Current behavior only broadcasts a status message.
|
|
64
|
+
|
|
65
|
+
```redscript
|
|
66
|
+
fn spread_players(x: int, z: int, radius: int)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Parameters**
|
|
70
|
+
|
|
71
|
+
| Parameter | Description |
|
|
72
|
+
|-----------|-------------|
|
|
73
|
+
| `x` | Center X coordinate |
|
|
74
|
+
| `z` | Center Z coordinate |
|
|
75
|
+
| `radius` | Maximum spread radius in blocks |
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## `gather_all`
|
|
80
|
+
|
|
81
|
+
Teleports all players to one location.
|
|
82
|
+
|
|
83
|
+
```redscript
|
|
84
|
+
fn gather_all(x: int, y: int, z: int)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Parameters**
|
|
88
|
+
|
|
89
|
+
| Parameter | Description |
|
|
90
|
+
|-----------|-------------|
|
|
91
|
+
| `x` | Destination X coordinate |
|
|
92
|
+
| `y` | Destination Y coordinate |
|
|
93
|
+
| `z` | Destination Z coordinate |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## `launch_up`
|
|
98
|
+
|
|
99
|
+
Teleports the target upward relative to its current position.
|
|
100
|
+
Useful for launch pads or scripted knock-up effects.
|
|
101
|
+
|
|
102
|
+
```redscript
|
|
103
|
+
fn launch_up(target: selector, height: int)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Parameters**
|
|
107
|
+
|
|
108
|
+
| Parameter | Description |
|
|
109
|
+
|-----------|-------------|
|
|
110
|
+
| `target` | Selector to move |
|
|
111
|
+
| `height` | Relative Y offset in blocks |
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## `goto_lobby`
|
|
116
|
+
|
|
117
|
+
Teleports the target to the hard-coded lobby position.
|
|
118
|
+
This helper also shows a welcome title and should be customized per map.
|
|
119
|
+
|
|
120
|
+
```redscript
|
|
121
|
+
fn goto_lobby(target: selector)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Parameters**
|
|
125
|
+
|
|
126
|
+
| Parameter | Description |
|
|
127
|
+
|-----------|-------------|
|
|
128
|
+
| `target` | Selector to move to the lobby |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## `goto_arena`
|
|
133
|
+
|
|
134
|
+
Teleports the target to the hard-coded arena position.
|
|
135
|
+
This helper also shows a fight title and should be customized per map.
|
|
136
|
+
|
|
137
|
+
```redscript
|
|
138
|
+
fn goto_arena(target: selector)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Parameters**
|
|
142
|
+
|
|
143
|
+
| Parameter | Description |
|
|
144
|
+
|-----------|-------------|
|
|
145
|
+
| `target` | Selector to move to the arena |
|
|
146
|
+
|
|
147
|
+
---
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# State
|
|
2
|
+
|
|
3
|
+
> Auto-generated from `src/stdlib/state.mcrs` — do not edit manually.
|
|
4
|
+
|
|
5
|
+
## API
|
|
6
|
+
|
|
7
|
+
- [get_state](#get-state)
|
|
8
|
+
- [set_state](#set-state)
|
|
9
|
+
- [is_state](#is-state)
|
|
10
|
+
- [init_state](#init-state)
|
|
11
|
+
- [transition](#transition)
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## `get_state` <Badge type="info" text="v1.0.0" />
|
|
16
|
+
|
|
17
|
+
Read the current state of an entity.
|
|
18
|
+
|
|
19
|
+
Returns `-1` if the entity has not been initialised (score is 0 = unset in
|
|
20
|
+
Minecraft, but we reserve `-1` as the sentinel for "never set via
|
|
21
|
+
`init_state`").
|
|
22
|
+
|
|
23
|
+
```redscript
|
|
24
|
+
fn get_state(entity: selector) -> int
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Parameters**
|
|
28
|
+
|
|
29
|
+
| Parameter | Description |
|
|
30
|
+
|-----------|-------------|
|
|
31
|
+
| `entity` | Selector for the target entity |
|
|
32
|
+
|
|
33
|
+
**Returns:** Current state value stored in `rs.state`, or `-1` if unset
|
|
34
|
+
|
|
35
|
+
**Example**
|
|
36
|
+
|
|
37
|
+
```redscript
|
|
38
|
+
let s: int = get_state(@s)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## `set_state` <Badge type="info" text="v1.0.0" />
|
|
44
|
+
|
|
45
|
+
Write a state value to an entity.
|
|
46
|
+
|
|
47
|
+
```redscript
|
|
48
|
+
fn set_state(entity: selector, state: int)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Parameters**
|
|
52
|
+
|
|
53
|
+
| Parameter | Description |
|
|
54
|
+
|-----------|-------------|
|
|
55
|
+
| `entity` | Selector for the target entity |
|
|
56
|
+
| `state` | Integer state constant to write |
|
|
57
|
+
|
|
58
|
+
**Example**
|
|
59
|
+
|
|
60
|
+
```redscript
|
|
61
|
+
set_state(@s, 1)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## `is_state` <Badge type="info" text="v1.0.0" />
|
|
67
|
+
|
|
68
|
+
Check whether an entity is currently in the given state.
|
|
69
|
+
|
|
70
|
+
```redscript
|
|
71
|
+
fn is_state(entity: selector, state: int) -> int
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Parameters**
|
|
75
|
+
|
|
76
|
+
| Parameter | Description |
|
|
77
|
+
|-----------|-------------|
|
|
78
|
+
| `entity` | Selector for the target entity |
|
|
79
|
+
| `state` | Integer state constant to compare against |
|
|
80
|
+
|
|
81
|
+
**Returns:** `1` if the entity is in `state`, `0` otherwise
|
|
82
|
+
|
|
83
|
+
**Example**
|
|
84
|
+
|
|
85
|
+
```redscript
|
|
86
|
+
if (is_state(@s, STATE_COMBAT) == 1) { /* per-tick combat logic */ }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## `init_state` <Badge type="info" text="v1.0.0" />
|
|
92
|
+
|
|
93
|
+
Initialise an entity's state only if it has not been set yet (score == -1).
|
|
94
|
+
|
|
95
|
+
Call once on spawn or load to avoid overwriting an in-progress state.
|
|
96
|
+
|
|
97
|
+
```redscript
|
|
98
|
+
fn init_state(entity: selector, initial: int)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Parameters**
|
|
102
|
+
|
|
103
|
+
| Parameter | Description |
|
|
104
|
+
|-----------|-------------|
|
|
105
|
+
| `entity` | Selector for the target entity |
|
|
106
|
+
| `initial` | State constant to write when the entity is uninitialised |
|
|
107
|
+
|
|
108
|
+
**Example**
|
|
109
|
+
|
|
110
|
+
```redscript
|
|
111
|
+
init_state(@s, STATE_IDLE)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## `transition` <Badge type="info" text="v1.0.0" />
|
|
117
|
+
|
|
118
|
+
Attempt a guarded transition from `from` to `to`.
|
|
119
|
+
|
|
120
|
+
Only performs the transition when the entity is currently in `from`.
|
|
121
|
+
|
|
122
|
+
```redscript
|
|
123
|
+
fn transition(entity: selector, from: int, to: int) -> int
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Parameters**
|
|
127
|
+
|
|
128
|
+
| Parameter | Description |
|
|
129
|
+
|-----------|-------------|
|
|
130
|
+
| `entity` | Selector for the target entity |
|
|
131
|
+
| `from` | Required current state |
|
|
132
|
+
| `to` | State to transition into |
|
|
133
|
+
|
|
134
|
+
**Returns:** `1` on success, `0` if the entity was not in `from`
|
|
135
|
+
|
|
136
|
+
**Example**
|
|
137
|
+
|
|
138
|
+
```redscript
|
|
139
|
+
let ok: int = transition(@s, STATE_IDLE, STATE_COMBAT)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Strings
|
|
2
|
+
|
|
3
|
+
> Auto-generated from `src/stdlib/strings.mcrs` — do not edit manually.
|
|
4
|
+
|
|
5
|
+
## API
|
|
6
|
+
|
|
7
|
+
- [str_len](#str-len)
|
|
8
|
+
- [str_concat](#str-concat)
|
|
9
|
+
- [str_contains](#str-contains)
|
|
10
|
+
- [str_slice](#str-slice)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## `str_len` <Badge type="info" text="v1.0.0" />
|
|
15
|
+
|
|
16
|
+
Returns the length of the string stored at rs:strings.{s}.
|
|
17
|
+
|
|
18
|
+
LIMITATION (MC 1.21.4): `execute store result score ... run data get storage`
|
|
19
|
+
returns 1 for any plain string NBT tag, not the character count. To get a
|
|
20
|
+
true character count, the string must be stored as an NBT list of single-char
|
|
21
|
+
strings (e.g. ["h","e","l","l","o"]), in which case data_get returns the list
|
|
22
|
+
length correctly.
|
|
23
|
+
|
|
24
|
+
For literal strings whose length is known at compile time, prefer using
|
|
25
|
+
the constant directly — the compiler will fold it.
|
|
26
|
+
|
|
27
|
+
```redscript
|
|
28
|
+
fn str_len(s: string) -> int
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Parameters**
|
|
32
|
+
|
|
33
|
+
| Parameter | Description |
|
|
34
|
+
|-----------|-------------|
|
|
35
|
+
| `s` | NBT field name in rs:strings (e.g. "A") |
|
|
36
|
+
|
|
37
|
+
**Returns:** 1 for plain string tags; list element count for char-list strings.
|
|
38
|
+
|
|
39
|
+
**Example**
|
|
40
|
+
|
|
41
|
+
```redscript
|
|
42
|
+
str_len("A") // result: 1 (plain string) or char count (char-list)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## `str_concat` <Badge type="info" text="v1.0.0" />
|
|
48
|
+
|
|
49
|
+
Concatenates two strings from rs:strings and writes the result to
|
|
50
|
+
rs:strings.Result as an NBT list [a_value, b_value].
|
|
51
|
+
|
|
52
|
+
The result list is suitable for use in tellraw JSON text components:
|
|
53
|
+
tellraw @a {"nbt":"Result","storage":"rs:strings","interpret":false}
|
|
54
|
+
|
|
55
|
+
LIMITATION (MC 1.21.4): MC has no native string concatenation command.
|
|
56
|
+
Single-string concatenation (e.g. "ab" from "a"+"b") requires a
|
|
57
|
+
recursive macro helper function; this is out of scope for a pure stdlib.
|
|
58
|
+
The NBT list representation works for display (tellraw) but cannot be
|
|
59
|
+
passed back to further string operations without conversion.
|
|
60
|
+
|
|
61
|
+
ALTERNATIVE for display: use a tellraw JSON array directly:
|
|
62
|
+
tellraw @a [{"storage":"rs:strings","nbt":"A"},{"storage":"rs:strings","nbt":"B"}]
|
|
63
|
+
|
|
64
|
+
```redscript
|
|
65
|
+
fn str_concat(a: string, b: string)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Parameters**
|
|
69
|
+
|
|
70
|
+
| Parameter | Description |
|
|
71
|
+
|-----------|-------------|
|
|
72
|
+
| `a` | NBT field name of the first string in rs:strings (e.g. "A") |
|
|
73
|
+
| `b` | NBT field name of the second string in rs:strings (e.g. "B") |
|
|
74
|
+
|
|
75
|
+
**Returns:** rs:strings.Result is set to an NBT list [valueA, valueB]
|
|
76
|
+
|
|
77
|
+
**Example**
|
|
78
|
+
|
|
79
|
+
```redscript
|
|
80
|
+
str_concat("A", "B") // rs:strings.Result = ["hello", "world"]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## `str_contains` <Badge type="info" text="v1.0.0" />
|
|
86
|
+
|
|
87
|
+
Checks whether the string at rs:strings.{s} contains the substring at
|
|
88
|
+
rs:strings.{sub}. Returns 1 if found, 0 if not found.
|
|
89
|
+
|
|
90
|
+
NOT FEASIBLE (MC 1.21.4): Minecraft datapacks do not provide a native
|
|
91
|
+
substring search command. There is no `execute if data` form that tests
|
|
92
|
+
whether one string is contained within another.
|
|
93
|
+
|
|
94
|
+
THIS FUNCTION ALWAYS RETURNS 0.
|
|
95
|
+
|
|
96
|
+
WORKAROUNDS for datapack authors:
|
|
97
|
+
1. If sub is a compile-time constant and the check position is known,
|
|
98
|
+
use str_slice to extract a window and compare via scoreboard.
|
|
99
|
+
2. Pre-process strings server-side and store a presence flag in NBT.
|
|
100
|
+
3. Use a macro function (MC 1.20.2+) that iterates over character
|
|
101
|
+
positions with `$(var)` substitution and returns early on match.
|
|
102
|
+
|
|
103
|
+
```redscript
|
|
104
|
+
fn str_contains(s: string, sub: string) -> int
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Parameters**
|
|
108
|
+
|
|
109
|
+
| Parameter | Description |
|
|
110
|
+
|-----------|-------------|
|
|
111
|
+
| `s` | NBT field name of the haystack string in rs:strings |
|
|
112
|
+
| `sub` | NBT field name of the needle string in rs:strings |
|
|
113
|
+
|
|
114
|
+
**Returns:** 0 (always — not implemented due to MC limitation)
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## `str_slice` <Badge type="info" text="v2.2.0" />
|
|
119
|
+
|
|
120
|
+
Extracts a substring from rs:strings.{s} and writes it to rs:strings.Result.
|
|
121
|
+
Uses the MC 1.20.2+ `data modify ... set string ... start end` feature.
|
|
122
|
+
|
|
123
|
+
Indices follow Java/Python slicing semantics:
|
|
124
|
+
- start is inclusive, 0-based.
|
|
125
|
+
- end is exclusive (end = start + length).
|
|
126
|
+
- Negative end counts from the end of the string (e.g. -1 = all but last char).
|
|
127
|
+
- Omitting end (use a very large positive int like 999999) copies to end of string.
|
|
128
|
+
|
|
129
|
+
Examples:
|
|
130
|
+
str_slice("A", 0, 5) → first 5 characters of rs:strings.A
|
|
131
|
+
str_slice("A", 2, -1) → all but first 2 and last 1 characters
|
|
132
|
+
|
|
133
|
+
```redscript
|
|
134
|
+
fn str_slice(s: string, start: int, end: int)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Parameters**
|
|
138
|
+
|
|
139
|
+
| Parameter | Description |
|
|
140
|
+
|-----------|-------------|
|
|
141
|
+
| `s` | NBT field name of the source string in rs:strings (e.g. "A") |
|
|
142
|
+
| `start` | Start index (inclusive, 0-based) |
|
|
143
|
+
| `end` | End index (exclusive); negative counts from string end |
|
|
144
|
+
|
|
145
|
+
**Returns:** rs:strings.Result contains the extracted substring
|
|
146
|
+
|
|
147
|
+
**Example**
|
|
148
|
+
|
|
149
|
+
```redscript
|
|
150
|
+
str_slice("A", 0, 5) // first 5 chars of rs:strings.A
|
|
151
|
+
str_slice("A", 2, -1) // drop first 2 and last 1 chars
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|