redscript-mc 1.2.15 → 1.2.16
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/CHANGELOG.md +39 -0
- package/README.md +13 -6
- package/builtins.d.mcrs +559 -0
- package/dist/builtins/metadata.d.ts +36 -0
- package/dist/builtins/metadata.js +1022 -0
- package/dist/cli.js +16 -6
- package/dist/lowering/index.d.ts +11 -0
- package/dist/lowering/index.js +34 -0
- package/editors/vscode/builtins.d.mcrs +559 -0
- package/editors/vscode/out/extension.js +797 -80
- package/editors/vscode/src/symbols.ts +68 -0
- package/package.json +1 -1
- package/src/builtins/metadata.ts +1123 -0
- package/src/cli.ts +17 -6
- package/src/lowering/index.ts +39 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to RedScript will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.2.15] - 2026-03-13
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- All builtin functions now support macro parameters, so runtime variables can be used in any argument position
|
|
9
|
+
|
|
10
|
+
## [1.2.14] - 2026-03-13
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Automatic Minecraft 1.20.2+ function macro support
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Runtime variables now work in more command positions, including coordinates and entity types
|
|
17
|
+
|
|
18
|
+
## [1.2.13] - 2026-03-13
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- Trivial control-flow helper functions are now inlined during optimization
|
|
22
|
+
- Empty blocks are removed automatically during optimization
|
|
23
|
+
|
|
24
|
+
## [1.2.12] - 2026-03-13
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
- Dead code elimination now preserves all public functions automatically
|
|
28
|
+
- Functions whose names start with `_` are treated as private by default
|
|
29
|
+
|
|
30
|
+
## [1.2.11] - 2026-03-13
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
- Entity types now compile with the `minecraft:` namespace where required
|
|
34
|
+
- Struct method field storage and method-call state restoration
|
|
35
|
+
|
|
36
|
+
## [1.2.10] - 2026-03-13
|
|
37
|
+
|
|
38
|
+
### Added
|
|
39
|
+
- `break` and `continue` statements
|
|
40
|
+
- `match` range patterns such as `70..79`
|
|
41
|
+
- `foreach` execute context modifiers like `at @s` and `positioned`
|
|
42
|
+
- Complete support for Minecraft `execute` subcommands
|
|
43
|
+
|
|
5
44
|
## [1.2.0] - 2026-03-12
|
|
6
45
|
|
|
7
46
|
### Added
|
package/README.md
CHANGED
|
@@ -51,13 +51,13 @@ let running: bool = false;
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
fn start() {
|
|
55
55
|
running = true;
|
|
56
56
|
counter = 0;
|
|
57
57
|
say(f"Demo started!");
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
fn stop() {
|
|
61
61
|
running = false;
|
|
62
62
|
say(f"Demo stopped at {counter} ticks.");
|
|
63
63
|
}
|
|
@@ -65,11 +65,14 @@ let running: bool = false;
|
|
|
65
65
|
|
|
66
66
|
**What you get:**
|
|
67
67
|
- ✅ `let` / `const` variables (no more `scoreboard players set`)
|
|
68
|
-
- ✅ `if` / `else` / `for` / `foreach` control flow
|
|
68
|
+
- ✅ `if` / `else` / `for` / `foreach` / `break` / `continue` control flow
|
|
69
69
|
- ✅ `@tick` / `@load` / `@on(Event)` decorators
|
|
70
|
-
- ✅ `foreach (p in @a) at @s
|
|
70
|
+
- ✅ `foreach (p in @a) at @s positioned ~ ~1 ~` and full `execute` subcommand support
|
|
71
|
+
- ✅ `match` with range patterns like `70..79`
|
|
72
|
+
- ✅ Builtins accept runtime macro variables in any argument position
|
|
71
73
|
- ✅ f-strings like `f"Score: {points}"` for dynamic output
|
|
72
|
-
- ✅
|
|
74
|
+
- ✅ Public functions are preserved automatically; `_privateFn()` stays private
|
|
75
|
+
- ✅ One file -> ready-to-use datapack
|
|
73
76
|
|
|
74
77
|
---
|
|
75
78
|
|
|
@@ -81,7 +84,11 @@ let running: bool = false;
|
|
|
81
84
|
- Runtime f-strings for `say`, `title`, `actionbar`, and related output
|
|
82
85
|
- Timer OOP API with `Timer::new(...)` and instance methods
|
|
83
86
|
- `setTimeout(...)` and `setInterval(...)` scheduling helpers
|
|
84
|
-
-
|
|
87
|
+
- `break` / `continue`, match range patterns, and full `execute` subcommands
|
|
88
|
+
- `foreach` execute context modifiers like `at`, `positioned`, and `rotated`
|
|
89
|
+
- Automatic MC 1.20.2+ function macro support for runtime variables
|
|
90
|
+
- Builtins now accept macro parameters in any position
|
|
91
|
+
- Dead code elimination that preserves public functions automatically
|
|
85
92
|
- 313 Minecraft tag constants in the standard library
|
|
86
93
|
|
|
87
94
|
---
|
package/builtins.d.mcrs
ADDED
|
@@ -0,0 +1,559 @@
|
|
|
1
|
+
// builtins.d.mcrs
|
|
2
|
+
// RedScript builtin function declarations
|
|
3
|
+
// Auto-generated by: redscript generate-dts
|
|
4
|
+
// DO NOT EDIT — regenerate with: redscript generate-dts
|
|
5
|
+
|
|
6
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
7
|
+
// Chat & Display
|
|
8
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
/// Displays a message to all players in chat as the server.
|
|
11
|
+
/// 以服务器名义向所有玩家发送聊天消息。
|
|
12
|
+
/// @param message Message to broadcast to all players
|
|
13
|
+
/// @example say("Hello, world!");
|
|
14
|
+
/// @example say("Game has started!");
|
|
15
|
+
declare fn say(message: string): void;
|
|
16
|
+
|
|
17
|
+
/// Sends a private message to a player or selector using tellraw.
|
|
18
|
+
/// 使用 tellraw 向玩家或选择器发送私信。
|
|
19
|
+
/// @param target Target player or entity selector
|
|
20
|
+
/// @param message Message to send privately
|
|
21
|
+
/// @example tell(@s, "You won!");
|
|
22
|
+
/// @example tell(@a[tag=vip], "Welcome, VIP!");
|
|
23
|
+
declare fn tell(target: selector, message: string): void;
|
|
24
|
+
|
|
25
|
+
/// Alias for tell(). Sends a raw text message using tellraw.
|
|
26
|
+
/// tell() 的别名,使用 tellraw 发送原始文本消息。
|
|
27
|
+
/// @param target Target player or entity selector
|
|
28
|
+
/// @param message Message text (supports f-string interpolation)
|
|
29
|
+
/// @example tellraw(@s, "Hello!");
|
|
30
|
+
declare fn tellraw(target: selector, message: string): void;
|
|
31
|
+
|
|
32
|
+
/// Sends a message to all players in chat (@a).
|
|
33
|
+
/// 向所有玩家(@a)发送聊天消息。
|
|
34
|
+
/// @param message Message to broadcast
|
|
35
|
+
/// @example announce("Round 1 starts in 3 seconds!");
|
|
36
|
+
declare fn announce(message: string): void;
|
|
37
|
+
|
|
38
|
+
/// Shows a large title on screen for target players.
|
|
39
|
+
/// 为目标玩家在屏幕上显示大标题。
|
|
40
|
+
/// @param target Target player(s)
|
|
41
|
+
/// @param message Title text to display
|
|
42
|
+
/// @example title(@a, "Round 1");
|
|
43
|
+
/// @example title(@s, "You Win!");
|
|
44
|
+
declare fn title(target: selector, message: string): void;
|
|
45
|
+
|
|
46
|
+
/// Shows subtitle text below the main title on screen.
|
|
47
|
+
/// 在屏幕主标题下方显示副标题文字。
|
|
48
|
+
/// @param target Target player(s)
|
|
49
|
+
/// @param message Subtitle text (appears below title)
|
|
50
|
+
/// @example subtitle(@a, "Fight!");
|
|
51
|
+
declare fn subtitle(target: selector, message: string): void;
|
|
52
|
+
|
|
53
|
+
/// Displays text in the action bar (above the hotbar).
|
|
54
|
+
/// 在动作栏(快捷栏上方)显示文字。
|
|
55
|
+
/// @param target Target player(s)
|
|
56
|
+
/// @param message Action bar text (above hotbar)
|
|
57
|
+
/// @example actionbar(@a, "⏱ ${time}s remaining");
|
|
58
|
+
declare fn actionbar(target: selector, message: string): void;
|
|
59
|
+
|
|
60
|
+
/// Sets title display timing in ticks. 20 ticks = 1 second.
|
|
61
|
+
/// 设置标题显示时间(以 tick 为单位),20 tick = 1 秒。
|
|
62
|
+
/// @param target Target player(s)
|
|
63
|
+
/// @param fadeIn Fade-in duration in ticks
|
|
64
|
+
/// @param stay Stay duration in ticks
|
|
65
|
+
/// @param fadeOut Fade-out duration in ticks
|
|
66
|
+
/// @example title_times(@a, 10, 40, 10);
|
|
67
|
+
/// @example // Show for 2 seconds
|
|
68
|
+
declare fn title_times(target: selector, fadeIn: int, stay: int, fadeOut: int): void;
|
|
69
|
+
|
|
70
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
71
|
+
// Player
|
|
72
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
/// Gives item(s) to a player.
|
|
75
|
+
/// 给予玩家物品。
|
|
76
|
+
/// @param target Target player(s)
|
|
77
|
+
/// @param item Item ID (e.g. "minecraft:diamond")
|
|
78
|
+
/// @param count? Number of items to give
|
|
79
|
+
/// @param nbt? Optional NBT data for the item
|
|
80
|
+
/// @example give(@s, "minecraft:diamond", 5);
|
|
81
|
+
/// @example give(@a, "minecraft:apple");
|
|
82
|
+
/// @example give(@s, "minecraft:diamond_sword", 1, "{Enchantments:[{id:\"minecraft:sharpness\",lvl:5s}]}");
|
|
83
|
+
declare fn give(target: selector, item: string, count?: int, nbt?: string): void;
|
|
84
|
+
|
|
85
|
+
/// Kills the target entity. Defaults to the executing entity (@s).
|
|
86
|
+
/// 击杀目标实体,默认击杀当前执行实体(@s)。
|
|
87
|
+
/// @param target? Target to kill (default: @s)
|
|
88
|
+
/// @example kill(@e[type=minecraft:zombie]);
|
|
89
|
+
/// @example kill(@s);
|
|
90
|
+
/// @example kill(@e[tag=enemy]);
|
|
91
|
+
declare fn kill(target?: selector): void;
|
|
92
|
+
|
|
93
|
+
/// Applies a status effect to an entity.
|
|
94
|
+
/// 为实体应用药水状态效果。
|
|
95
|
+
/// @param target Target entity or player
|
|
96
|
+
/// @param effect Effect ID (e.g. "minecraft:speed")
|
|
97
|
+
/// @param duration? Duration in seconds
|
|
98
|
+
/// @param amplifier? Effect level (0-255, where 0 = level 1)
|
|
99
|
+
/// @example effect(@s, "minecraft:speed", 60, 1);
|
|
100
|
+
/// @example effect(@a, "minecraft:regeneration", 10);
|
|
101
|
+
/// @example effect(@e[type=minecraft:zombie], "minecraft:slowness", 20, 2);
|
|
102
|
+
declare fn effect(target: selector, effect: string, duration?: int, amplifier?: int): void;
|
|
103
|
+
|
|
104
|
+
/// Removes a status effect from an entity, or clears all effects.
|
|
105
|
+
/// 移除实体的药水效果,省略 effect 参数则清除所有效果。
|
|
106
|
+
/// @param target Target entity or player
|
|
107
|
+
/// @param effect? Effect to remove (omit to clear all)
|
|
108
|
+
/// @example effect_clear(@s, "minecraft:poison");
|
|
109
|
+
/// @example effect_clear(@a);
|
|
110
|
+
declare fn effect_clear(target: selector, effect?: string): void;
|
|
111
|
+
|
|
112
|
+
/// Removes items from a player's inventory.
|
|
113
|
+
/// 清除玩家背包中的物品。
|
|
114
|
+
/// @param target Target player
|
|
115
|
+
/// @param item? Specific item to remove (omit to clear all)
|
|
116
|
+
/// @example clear(@s, "minecraft:dirt");
|
|
117
|
+
/// @example clear(@a);
|
|
118
|
+
declare fn clear(target: selector, item?: string): void;
|
|
119
|
+
|
|
120
|
+
/// Kicks a player from the server with an optional reason.
|
|
121
|
+
/// 将玩家踢出服务器,可附加原因。
|
|
122
|
+
/// @param player Target player to kick
|
|
123
|
+
/// @param reason? Kick message shown to the player
|
|
124
|
+
/// @example kick(@s, "You lost!");
|
|
125
|
+
/// @example kick(@p, "AFK too long");
|
|
126
|
+
declare fn kick(player: selector, reason?: string): void;
|
|
127
|
+
|
|
128
|
+
/// Adds experience points or levels to a player.
|
|
129
|
+
/// 给玩家增加经验点或等级。
|
|
130
|
+
/// @param target Target player
|
|
131
|
+
/// @param amount Amount of XP to add
|
|
132
|
+
/// @param type? "points" or "levels"
|
|
133
|
+
/// @example xp_add(@s, 100);
|
|
134
|
+
/// @example xp_add(@s, 5, "levels");
|
|
135
|
+
declare fn xp_add(target: selector, amount: int, type?: string): void;
|
|
136
|
+
|
|
137
|
+
/// Sets a player's experience points or levels.
|
|
138
|
+
/// 设置玩家的经验点或等级。
|
|
139
|
+
/// @param target Target player
|
|
140
|
+
/// @param amount New XP value
|
|
141
|
+
/// @param type? "points" or "levels"
|
|
142
|
+
/// @example xp_set(@s, 0, "levels");
|
|
143
|
+
/// @example xp_set(@s, 500);
|
|
144
|
+
declare fn xp_set(target: selector, amount: int, type?: string): void;
|
|
145
|
+
|
|
146
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
147
|
+
// World & Block
|
|
148
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
149
|
+
|
|
150
|
+
/// Teleports an entity to a player or position.
|
|
151
|
+
/// 将实体传送到指定玩家或坐标。
|
|
152
|
+
/// @param target Entity to teleport
|
|
153
|
+
/// @param destination Target player or BlockPos coordinates
|
|
154
|
+
/// @example tp(@s, (0, 64, 0));
|
|
155
|
+
/// @example tp(@a, @s);
|
|
156
|
+
/// @example tp(@s, (~0, ~10, ~0));
|
|
157
|
+
declare fn tp(target: selector, destination: selector): void;
|
|
158
|
+
|
|
159
|
+
/// @deprecated Use tp() instead. Teleports an entity to a position.
|
|
160
|
+
/// @deprecated 请使用 tp()。将实体传送到指定位置。
|
|
161
|
+
/// @param target Entity to teleport
|
|
162
|
+
/// @param destination Target player or position
|
|
163
|
+
/// @example tp(@s, (0, 64, 0)); // use tp instead
|
|
164
|
+
declare fn tp_to(target: selector, destination: selector): void;
|
|
165
|
+
|
|
166
|
+
/// Places a block at the specified coordinates.
|
|
167
|
+
/// 在指定坐标放置方块。
|
|
168
|
+
/// @param pos Block position, e.g. (0, 64, 0) or (~1, ~0, ~0)
|
|
169
|
+
/// @param block Block ID (e.g. "minecraft:stone")
|
|
170
|
+
/// @example setblock((0, 64, 0), "minecraft:stone");
|
|
171
|
+
/// @example setblock((~1, ~0, ~0), "minecraft:air");
|
|
172
|
+
declare fn setblock(pos: BlockPos, block: string): void;
|
|
173
|
+
|
|
174
|
+
/// Fills a cuboid region with a specified block.
|
|
175
|
+
/// 用指定方块填充一个立方体区域。
|
|
176
|
+
/// @param from Start corner of the region
|
|
177
|
+
/// @param to End corner of the region
|
|
178
|
+
/// @param block Block to fill with
|
|
179
|
+
/// @example fill((0, 64, 0), (10, 64, 10), "minecraft:grass_block");
|
|
180
|
+
/// @example fill((~-5, ~-1, ~-5), (~5, ~-1, ~5), "minecraft:bedrock");
|
|
181
|
+
declare fn fill(from: BlockPos, to: BlockPos, block: string): void;
|
|
182
|
+
|
|
183
|
+
/// Clones a region of blocks to a new location.
|
|
184
|
+
/// 将一个区域的方块复制到新的位置。
|
|
185
|
+
/// @param from Source region start corner
|
|
186
|
+
/// @param to Source region end corner
|
|
187
|
+
/// @param dest Destination corner
|
|
188
|
+
/// @example clone((0,64,0), (10,64,10), (20,64,0));
|
|
189
|
+
declare fn clone(from: BlockPos, to: BlockPos, dest: BlockPos): void;
|
|
190
|
+
|
|
191
|
+
/// Summons an entity at the specified position.
|
|
192
|
+
/// 在指定位置生成实体。
|
|
193
|
+
/// @param type Entity type ID (e.g. "minecraft:zombie")
|
|
194
|
+
/// @param x? X coordinate (default: ~)
|
|
195
|
+
/// @param y? Y coordinate (default: ~)
|
|
196
|
+
/// @param z? Z coordinate (default: ~)
|
|
197
|
+
/// @param nbt? Optional NBT data for the entity
|
|
198
|
+
/// @example summon("minecraft:zombie", ~0, ~0, ~0);
|
|
199
|
+
/// @example summon("minecraft:armor_stand", (0, 64, 0));
|
|
200
|
+
/// @example summon("minecraft:zombie", ~0, ~0, ~0, "{CustomName:\"Boss\"}");
|
|
201
|
+
declare fn summon(type: string, x?: coord, y?: coord, z?: coord, nbt?: string): void;
|
|
202
|
+
|
|
203
|
+
/// Spawns a particle effect at the specified position.
|
|
204
|
+
/// 在指定位置生成粒子效果。
|
|
205
|
+
/// @param name Particle type ID (e.g. "minecraft:flame")
|
|
206
|
+
/// @param x? X coordinate
|
|
207
|
+
/// @param y? Y coordinate
|
|
208
|
+
/// @param z? Z coordinate
|
|
209
|
+
/// @example particle("minecraft:flame", (~0, ~1, ~0));
|
|
210
|
+
/// @example particle("minecraft:explosion", (0, 100, 0));
|
|
211
|
+
declare fn particle(name: string, x?: coord, y?: coord, z?: coord): void;
|
|
212
|
+
|
|
213
|
+
/// Plays a sound effect for target players.
|
|
214
|
+
/// 为目标玩家播放音效。
|
|
215
|
+
/// @param sound Sound event ID (e.g. "entity.experience_orb.pickup")
|
|
216
|
+
/// @param source Sound category: "master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"
|
|
217
|
+
/// @param target Target player to hear the sound
|
|
218
|
+
/// @param x? X origin position
|
|
219
|
+
/// @param y? Y origin position
|
|
220
|
+
/// @param z? Z origin position
|
|
221
|
+
/// @param volume? Volume (default: 1.0)
|
|
222
|
+
/// @param pitch? Pitch (default: 1.0)
|
|
223
|
+
/// @param minVolume? Minimum volume for distant players
|
|
224
|
+
/// @example playsound("entity.experience_orb.pickup", "player", @s);
|
|
225
|
+
/// @example playsound("ui.toast.challenge_complete", "master", @a);
|
|
226
|
+
declare fn playsound(sound: string, source: string, target: selector, x?: coord, y?: coord, z?: coord, volume?: float, pitch?: float, minVolume?: float): void;
|
|
227
|
+
|
|
228
|
+
/// Sets the weather condition.
|
|
229
|
+
/// 设置天气状态。
|
|
230
|
+
/// @param type "clear", "rain", or "thunder"
|
|
231
|
+
/// @example weather("clear");
|
|
232
|
+
/// @example weather("thunder");
|
|
233
|
+
declare fn weather(type: string): void;
|
|
234
|
+
|
|
235
|
+
/// Sets the world time.
|
|
236
|
+
/// 设置世界时间。
|
|
237
|
+
/// @param value Time in ticks, or "day"/"night"/"noon"/"midnight"
|
|
238
|
+
/// @example time_set(0); // dawn
|
|
239
|
+
/// @example time_set("midnight");
|
|
240
|
+
declare fn time_set(value: string): void;
|
|
241
|
+
|
|
242
|
+
/// Advances the world time by a number of ticks.
|
|
243
|
+
/// 将世界时间推进指定的 tick 数。
|
|
244
|
+
/// @param ticks Number of ticks to advance
|
|
245
|
+
/// @example time_add(6000); // advance by half a day
|
|
246
|
+
declare fn time_add(ticks: int): void;
|
|
247
|
+
|
|
248
|
+
/// Sets a gamerule value.
|
|
249
|
+
/// 设置游戏规则的值。
|
|
250
|
+
/// @param rule Gamerule name (e.g. "keepInventory")
|
|
251
|
+
/// @param value New value (true/false for boolean rules, integer for numeric)
|
|
252
|
+
/// @example gamerule("keepInventory", true);
|
|
253
|
+
/// @example gamerule("randomTickSpeed", 3);
|
|
254
|
+
declare fn gamerule(rule: string, value: string): void;
|
|
255
|
+
|
|
256
|
+
/// Sets the game difficulty.
|
|
257
|
+
/// 设置游戏难度。
|
|
258
|
+
/// @param level "peaceful", "easy", "normal", or "hard"
|
|
259
|
+
/// @example difficulty("hard");
|
|
260
|
+
/// @example difficulty("peaceful");
|
|
261
|
+
declare fn difficulty(level: string): void;
|
|
262
|
+
|
|
263
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
264
|
+
// Entities & Tags
|
|
265
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
266
|
+
|
|
267
|
+
/// Adds a scoreboard tag to an entity.
|
|
268
|
+
/// 为实体添加计分板标签。
|
|
269
|
+
/// @param target Target entity
|
|
270
|
+
/// @param tag Tag name to add
|
|
271
|
+
/// @example tag_add(@s, "hasKey");
|
|
272
|
+
/// @example tag_add(@e[type=minecraft:zombie], "boss");
|
|
273
|
+
declare fn tag_add(target: selector, tag: string): void;
|
|
274
|
+
|
|
275
|
+
/// Removes a scoreboard tag from an entity.
|
|
276
|
+
/// 从实体身上移除计分板标签。
|
|
277
|
+
/// @param target Target entity
|
|
278
|
+
/// @param tag Tag name to remove
|
|
279
|
+
/// @example tag_remove(@s, "hasKey");
|
|
280
|
+
declare fn tag_remove(target: selector, tag: string): void;
|
|
281
|
+
|
|
282
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
283
|
+
// Scoreboard
|
|
284
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
285
|
+
|
|
286
|
+
/// Reads a value from a vanilla MC scoreboard objective.
|
|
287
|
+
/// 从原版 MC 计分板目标读取数值。
|
|
288
|
+
/// @param target Player, entity, or fake player name (e.g. "#counter")
|
|
289
|
+
/// @param objective Scoreboard objective name
|
|
290
|
+
/// @returns int
|
|
291
|
+
/// @example let hp: int = scoreboard_get(@s, "health");
|
|
292
|
+
/// @example let kills: int = scoreboard_get(@s, "kills");
|
|
293
|
+
declare fn scoreboard_get(target: selector, objective: string): int;
|
|
294
|
+
|
|
295
|
+
/// Alias for scoreboard_get(). Reads a value from a scoreboard.
|
|
296
|
+
/// scoreboard_get() 的别名,从计分板读取数值。
|
|
297
|
+
/// @param target Player, entity, or fake player name
|
|
298
|
+
/// @param objective Scoreboard objective name
|
|
299
|
+
/// @returns int
|
|
300
|
+
/// @example let kills: int = score(@s, "kills");
|
|
301
|
+
declare fn score(target: selector, objective: string): int;
|
|
302
|
+
|
|
303
|
+
/// Sets a value in a vanilla MC scoreboard objective.
|
|
304
|
+
/// 设置原版 MC 计分板目标中的数值。
|
|
305
|
+
/// @param target Player, entity, or fake player
|
|
306
|
+
/// @param objective Objective name
|
|
307
|
+
/// @param value New score value
|
|
308
|
+
/// @example scoreboard_set("#game", "timer", 300);
|
|
309
|
+
/// @example scoreboard_set(@s, "lives", 3);
|
|
310
|
+
declare fn scoreboard_set(target: selector, objective: string, value: int): void;
|
|
311
|
+
|
|
312
|
+
/// Displays a scoreboard objective in a display slot.
|
|
313
|
+
/// 在指定显示位置展示计分板目标。
|
|
314
|
+
/// @param slot "list", "sidebar", or "belowName"
|
|
315
|
+
/// @param objective Objective name to display
|
|
316
|
+
/// @example scoreboard_display("sidebar", "kills");
|
|
317
|
+
declare fn scoreboard_display(slot: string, objective: string): void;
|
|
318
|
+
|
|
319
|
+
/// Clears the display in a scoreboard slot.
|
|
320
|
+
/// 清除计分板显示位置的内容。
|
|
321
|
+
/// @param slot "list", "sidebar", or "belowName"
|
|
322
|
+
/// @example scoreboard_hide("sidebar");
|
|
323
|
+
declare fn scoreboard_hide(slot: string): void;
|
|
324
|
+
|
|
325
|
+
/// Creates a new scoreboard objective.
|
|
326
|
+
/// 创建新的计分板目标。
|
|
327
|
+
/// @param name Objective name
|
|
328
|
+
/// @param criteria Criteria (e.g. "dummy", "playerKillCount")
|
|
329
|
+
/// @param displayName? Optional display name
|
|
330
|
+
/// @example scoreboard_add_objective("kills", "playerKillCount");
|
|
331
|
+
/// @example scoreboard_add_objective("timer", "dummy", "Game Timer");
|
|
332
|
+
declare fn scoreboard_add_objective(name: string, criteria: string, displayName?: string): void;
|
|
333
|
+
|
|
334
|
+
/// Removes a scoreboard objective.
|
|
335
|
+
/// 删除计分板目标。
|
|
336
|
+
/// @param name Objective name to remove
|
|
337
|
+
/// @example scoreboard_remove_objective("kills");
|
|
338
|
+
declare fn scoreboard_remove_objective(name: string): void;
|
|
339
|
+
|
|
340
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
341
|
+
// Random
|
|
342
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
343
|
+
|
|
344
|
+
/// Generates a random integer in range [min, max] using scoreboard arithmetic. Compatible with all MC versions.
|
|
345
|
+
/// 使用计分板运算生成 [min, max] 范围内的随机整数,兼容所有 MC 版本。
|
|
346
|
+
/// @param min Minimum value (inclusive)
|
|
347
|
+
/// @param max Maximum value (inclusive)
|
|
348
|
+
/// @returns int
|
|
349
|
+
/// @example let roll: int = random(1, 6);
|
|
350
|
+
/// @example let chance: int = random(0, 99);
|
|
351
|
+
declare fn random(min: int, max: int): int;
|
|
352
|
+
|
|
353
|
+
/// Generates a random integer using /random command (MC 1.20.3+). Faster and more reliable than random().
|
|
354
|
+
/// 使用 /random 命令(MC 1.20.3+)生成随机整数,比 random() 更快更可靠。
|
|
355
|
+
/// @param min Minimum value (inclusive)
|
|
356
|
+
/// @param max Maximum value (inclusive)
|
|
357
|
+
/// @returns int
|
|
358
|
+
/// @example let n: int = random_native(1, 100);
|
|
359
|
+
declare fn random_native(min: int, max: int): int;
|
|
360
|
+
|
|
361
|
+
/// Resets a random sequence with an optional seed (MC 1.20.3+).
|
|
362
|
+
/// 重置随机序列,可指定种子(MC 1.20.3+)。
|
|
363
|
+
/// @param sequence Sequence name (namespaced, e.g. "mypack:loot")
|
|
364
|
+
/// @param seed? Seed value
|
|
365
|
+
/// @example random_sequence("mypack:loot", 42);
|
|
366
|
+
declare fn random_sequence(sequence: string, seed?: int): void;
|
|
367
|
+
|
|
368
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
369
|
+
// Data (NBT)
|
|
370
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
371
|
+
|
|
372
|
+
/// Reads NBT data from an entity, block, or storage into an integer variable.
|
|
373
|
+
/// 从实体、方块或存储读取 NBT 数据到整型变量。
|
|
374
|
+
/// @param targetType "entity", "block", or "storage"
|
|
375
|
+
/// @param target Target selector or storage path
|
|
376
|
+
/// @param path NBT path (e.g. "Health")
|
|
377
|
+
/// @param scale? Scale factor
|
|
378
|
+
/// @returns int
|
|
379
|
+
/// @example let hp: int = data_get("entity", "@s", "Health");
|
|
380
|
+
/// @example let val: int = data_get("storage", "mypack:data", "myKey");
|
|
381
|
+
declare fn data_get(targetType: string, target: string, path: string, scale?: float): int;
|
|
382
|
+
|
|
383
|
+
/// Merges NBT data into an entity, block, or storage.
|
|
384
|
+
/// 将 NBT 数据合并到实体、方块或存储中。
|
|
385
|
+
/// @param target Target entity selector or block position
|
|
386
|
+
/// @param nbt NBT data to merge (struct literal or string)
|
|
387
|
+
/// @example data_merge(@s, { Invisible: 1b, Silent: 1b });
|
|
388
|
+
declare fn data_merge(target: selector, nbt: string): void;
|
|
389
|
+
|
|
390
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
391
|
+
// Boss Bar
|
|
392
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
393
|
+
|
|
394
|
+
/// Creates a new boss bar.
|
|
395
|
+
/// 创建新的 Boss 血条。
|
|
396
|
+
/// @param id Boss bar ID (namespaced, e.g. "minecraft:health")
|
|
397
|
+
/// @param name Display name
|
|
398
|
+
/// @example bossbar_add("mymod:timer", "Time Left");
|
|
399
|
+
declare fn bossbar_add(id: string, name: string): void;
|
|
400
|
+
|
|
401
|
+
/// Sets the current value of a boss bar.
|
|
402
|
+
/// 设置 Boss 血条的当前值。
|
|
403
|
+
/// @param id Boss bar ID
|
|
404
|
+
/// @param value Current value
|
|
405
|
+
/// @example bossbar_set_value("mymod:timer", 60);
|
|
406
|
+
declare fn bossbar_set_value(id: string, value: int): void;
|
|
407
|
+
|
|
408
|
+
/// Sets the maximum value of a boss bar.
|
|
409
|
+
/// 设置 Boss 血条的最大值。
|
|
410
|
+
/// @param id Boss bar ID
|
|
411
|
+
/// @param max Maximum value
|
|
412
|
+
/// @example bossbar_set_max("mymod:timer", 300);
|
|
413
|
+
declare fn bossbar_set_max(id: string, max: int): void;
|
|
414
|
+
|
|
415
|
+
/// Sets the color of a boss bar.
|
|
416
|
+
/// 设置 Boss 血条的颜色。
|
|
417
|
+
/// @param id Boss bar ID
|
|
418
|
+
/// @param color "blue", "green", "pink", "purple", "red", "white", or "yellow"
|
|
419
|
+
/// @example bossbar_set_color("mymod:timer", "red");
|
|
420
|
+
declare fn bossbar_set_color(id: string, color: string): void;
|
|
421
|
+
|
|
422
|
+
/// Sets the style (segmentation) of a boss bar.
|
|
423
|
+
/// 设置 Boss 血条的样式(分段方式)。
|
|
424
|
+
/// @param id Boss bar segmentation style
|
|
425
|
+
/// @param style "notched_6", "notched_10", "notched_12", "notched_20", or "progress"
|
|
426
|
+
/// @example bossbar_set_style("mymod:timer", "notched_10");
|
|
427
|
+
declare fn bossbar_set_style(id: string, style: string): void;
|
|
428
|
+
|
|
429
|
+
/// Shows or hides a boss bar.
|
|
430
|
+
/// 显示或隐藏 Boss 血条。
|
|
431
|
+
/// @param id Boss bar ID
|
|
432
|
+
/// @param visible Visibility state (true = show, false = hide)
|
|
433
|
+
/// @example bossbar_set_visible("mymod:timer", true);
|
|
434
|
+
declare fn bossbar_set_visible(id: string, visible: bool): void;
|
|
435
|
+
|
|
436
|
+
/// Sets which players can see the boss bar.
|
|
437
|
+
/// 设置哪些玩家能看到 Boss 血条。
|
|
438
|
+
/// @param id Boss bar ID
|
|
439
|
+
/// @param target Players who should see the boss bar
|
|
440
|
+
/// @example bossbar_set_players("mymod:timer", @a);
|
|
441
|
+
declare fn bossbar_set_players(id: string, target: selector): void;
|
|
442
|
+
|
|
443
|
+
/// Removes a boss bar.
|
|
444
|
+
/// 移除 Boss 血条。
|
|
445
|
+
/// @param id Boss bar ID to remove
|
|
446
|
+
/// @example bossbar_remove("mymod:timer");
|
|
447
|
+
declare fn bossbar_remove(id: string): void;
|
|
448
|
+
|
|
449
|
+
/// Gets the current value of a boss bar.
|
|
450
|
+
/// 获取 Boss 血条的当前值。
|
|
451
|
+
/// @param id Boss bar ID
|
|
452
|
+
/// @returns int
|
|
453
|
+
/// @example let v: int = bossbar_get_value("mymod:timer");
|
|
454
|
+
declare fn bossbar_get_value(id: string): int;
|
|
455
|
+
|
|
456
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
457
|
+
// Teams
|
|
458
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
459
|
+
|
|
460
|
+
/// Creates a new team.
|
|
461
|
+
/// 创建新的队伍。
|
|
462
|
+
/// @param name Team name
|
|
463
|
+
/// @param displayName? Optional display name
|
|
464
|
+
/// @example team_add("red");
|
|
465
|
+
/// @example team_add("blue", "Blue Team");
|
|
466
|
+
declare fn team_add(name: string, displayName?: string): void;
|
|
467
|
+
|
|
468
|
+
/// Removes a team.
|
|
469
|
+
/// 移除队伍。
|
|
470
|
+
/// @param name Team name to remove
|
|
471
|
+
/// @example team_remove("red");
|
|
472
|
+
declare fn team_remove(name: string): void;
|
|
473
|
+
|
|
474
|
+
/// Adds entities to a team.
|
|
475
|
+
/// 将实体加入队伍。
|
|
476
|
+
/// @param name Team name to join
|
|
477
|
+
/// @param target Entities to add to the team
|
|
478
|
+
/// @example team_join("red", @s);
|
|
479
|
+
/// @example team_join("blue", @a[tag=blue_team]);
|
|
480
|
+
declare fn team_join(name: string, target: selector): void;
|
|
481
|
+
|
|
482
|
+
/// Removes entities from their current team.
|
|
483
|
+
/// 将实体从当前队伍中移除。
|
|
484
|
+
/// @param target Entities to remove from their team
|
|
485
|
+
/// @example team_leave(@s);
|
|
486
|
+
declare fn team_leave(target: selector): void;
|
|
487
|
+
|
|
488
|
+
/// Sets a team option/property.
|
|
489
|
+
/// 设置队伍选项/属性。
|
|
490
|
+
/// @param name Team name
|
|
491
|
+
/// @param option Option name (e.g. "color", "friendlyFire", "prefix")
|
|
492
|
+
/// @param value Option value
|
|
493
|
+
/// @example team_option("red", "color", "red");
|
|
494
|
+
/// @example team_option("blue", "friendlyFire", "false");
|
|
495
|
+
declare fn team_option(name: string, option: string, value: string): void;
|
|
496
|
+
|
|
497
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
498
|
+
// Collections (Set)
|
|
499
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
500
|
+
|
|
501
|
+
/// Creates a new unique set backed by NBT storage. Returns the set ID.
|
|
502
|
+
/// 创建新的基于 NBT 存储的唯一集合,返回集合 ID。
|
|
503
|
+
/// @returns string
|
|
504
|
+
/// @example let enemies: string = set_new();
|
|
505
|
+
/// @example set_add(enemies, "@s");
|
|
506
|
+
declare fn set_new(): string;
|
|
507
|
+
|
|
508
|
+
/// Adds a value to a set (no-op if already present).
|
|
509
|
+
/// 向集合添加值(若已存在则不操作)。
|
|
510
|
+
/// @param setId Set ID returned by set_new()
|
|
511
|
+
/// @param value Value to add
|
|
512
|
+
/// @example set_add(enemies, "@s");
|
|
513
|
+
declare fn set_add(setId: string, value: string): void;
|
|
514
|
+
|
|
515
|
+
/// Returns 1 if the set contains the value, 0 otherwise.
|
|
516
|
+
/// 若集合包含该值返回 1,否则返回 0。
|
|
517
|
+
/// @param setId Set ID
|
|
518
|
+
/// @param value Value to check
|
|
519
|
+
/// @returns int
|
|
520
|
+
/// @example if set_contains(enemies, "@s") { kill(@s); }
|
|
521
|
+
declare fn set_contains(setId: string, value: string): int;
|
|
522
|
+
|
|
523
|
+
/// Removes a value from a set.
|
|
524
|
+
/// 从集合中移除一个值。
|
|
525
|
+
/// @param setId Set ID
|
|
526
|
+
/// @param value Value to remove
|
|
527
|
+
/// @example set_remove(enemies, "@s");
|
|
528
|
+
declare fn set_remove(setId: string, value: string): void;
|
|
529
|
+
|
|
530
|
+
/// Removes all values from a set.
|
|
531
|
+
/// 清空集合中的所有值。
|
|
532
|
+
/// @param setId Set ID to clear
|
|
533
|
+
/// @example set_clear(enemies);
|
|
534
|
+
declare fn set_clear(setId: string): void;
|
|
535
|
+
|
|
536
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
537
|
+
// Timers
|
|
538
|
+
// ──────────────────────────────────────────────────────────────────────
|
|
539
|
+
|
|
540
|
+
/// Executes a callback function after a delay (in ticks).
|
|
541
|
+
/// 在指定延迟(tick)后执行回调函数。
|
|
542
|
+
/// @param delay Delay in ticks before executing the callback
|
|
543
|
+
/// @param callback Lambda function to execute after delay
|
|
544
|
+
/// @example setTimeout(100, () => { say("5 seconds passed!"); });
|
|
545
|
+
declare fn setTimeout(delay: int, callback: string): void;
|
|
546
|
+
|
|
547
|
+
/// Executes a callback function repeatedly at a fixed interval. Returns an interval ID.
|
|
548
|
+
/// 以固定间隔重复执行回调函数,返回间隔 ID。
|
|
549
|
+
/// @param interval Interval in ticks between executions
|
|
550
|
+
/// @param callback Lambda function to execute repeatedly
|
|
551
|
+
/// @returns int
|
|
552
|
+
/// @example let timer: int = setInterval(20, () => { say("Every second!"); });
|
|
553
|
+
declare fn setInterval(interval: int, callback: string): int;
|
|
554
|
+
|
|
555
|
+
/// Cancels a repeating interval created by setInterval().
|
|
556
|
+
/// 取消由 setInterval() 创建的重复间隔。
|
|
557
|
+
/// @param id Interval ID returned by setInterval()
|
|
558
|
+
/// @example clearInterval(timer);
|
|
559
|
+
declare fn clearInterval(id: int): void;
|