redscript-mc 1.0.0 → 1.2.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.yml +72 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +57 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +17 -25
- package/CHANGELOG.md +112 -0
- package/CONTRIBUTING.md +140 -0
- package/README.md +28 -19
- package/README.zh.md +28 -19
- package/dist/__tests__/cli.test.js +148 -10
- package/dist/__tests__/codegen.test.js +26 -1
- package/dist/__tests__/diagnostics.test.js +5 -5
- package/dist/__tests__/e2e.test.js +336 -17
- package/dist/__tests__/formatter.test.d.ts +1 -0
- package/dist/__tests__/formatter.test.js +40 -0
- package/dist/__tests__/lexer.test.js +12 -2
- package/dist/__tests__/lowering.test.js +200 -12
- package/dist/__tests__/mc-integration.test.js +370 -31
- package/dist/__tests__/mc-syntax.test.js +3 -3
- package/dist/__tests__/nbt.test.js +2 -2
- package/dist/__tests__/optimizer-advanced.test.js +5 -5
- package/dist/__tests__/parser.test.js +80 -0
- package/dist/__tests__/runtime.test.js +9 -9
- package/dist/__tests__/typechecker.test.js +158 -0
- package/dist/ast/types.d.ts +40 -3
- package/dist/cli.js +25 -7
- package/dist/codegen/mcfunction/index.d.ts +1 -1
- package/dist/codegen/mcfunction/index.js +38 -3
- package/dist/codegen/structure/index.js +32 -1
- package/dist/compile.d.ts +10 -0
- package/dist/compile.js +36 -5
- package/dist/events/types.d.ts +35 -0
- package/dist/events/types.js +59 -0
- package/dist/formatter/index.d.ts +1 -0
- package/dist/formatter/index.js +26 -0
- package/dist/index.js +3 -2
- package/dist/ir/builder.d.ts +2 -1
- package/dist/ir/types.d.ts +11 -2
- package/dist/ir/types.js +1 -1
- package/dist/lexer/index.d.ts +1 -1
- package/dist/lexer/index.js +2 -0
- package/dist/lowering/index.d.ts +34 -1
- package/dist/lowering/index.js +622 -23
- package/dist/mc-test/runner.d.ts +2 -2
- package/dist/mc-test/runner.js +3 -3
- package/dist/mc-test/setup.js +2 -2
- package/dist/parser/index.d.ts +4 -0
- package/dist/parser/index.js +153 -16
- package/dist/typechecker/index.d.ts +17 -0
- package/dist/typechecker/index.js +343 -17
- package/docs/COMPILATION_STATS.md +24 -24
- package/docs/ENTITY_TYPE_SYSTEM.md +242 -0
- package/docs/IMPLEMENTATION_GUIDE.md +1 -1
- package/docs/STRUCTURE_TARGET.md +1 -1
- package/editors/vscode/.vscodeignore +1 -0
- package/editors/vscode/CHANGELOG.md +9 -0
- package/editors/vscode/icons/mcrs.svg +7 -0
- package/editors/vscode/icons/redscript-icons.json +10 -0
- package/editors/vscode/out/extension.js +1295 -80
- package/editors/vscode/package-lock.json +2 -2
- package/editors/vscode/package.json +10 -3
- package/editors/vscode/src/hover.ts +55 -2
- package/editors/vscode/src/symbols.ts +42 -0
- package/package.json +1 -1
- package/src/__tests__/cli.test.ts +176 -10
- package/src/__tests__/codegen.test.ts +28 -1
- package/src/__tests__/diagnostics.test.ts +5 -5
- package/src/__tests__/e2e.test.ts +335 -17
- package/src/__tests__/fixtures/event-test.mcrs +13 -0
- package/src/__tests__/fixtures/impl-test.mcrs +46 -0
- package/src/__tests__/fixtures/interval-test.mcrs +11 -0
- package/src/__tests__/fixtures/is-check-test.mcrs +20 -0
- package/src/__tests__/fixtures/timeout-test.mcrs +7 -0
- package/src/__tests__/lexer.test.ts +14 -2
- package/src/__tests__/lowering.test.ts +226 -12
- package/src/__tests__/mc-integration.test.ts +421 -31
- package/src/__tests__/mc-syntax.test.ts +3 -3
- package/src/__tests__/nbt.test.ts +2 -2
- package/src/__tests__/optimizer-advanced.test.ts +5 -5
- package/src/__tests__/parser.test.ts +91 -5
- package/src/__tests__/runtime.test.ts +9 -9
- package/src/__tests__/typechecker.test.ts +171 -0
- package/src/ast/types.ts +44 -3
- package/src/cli.ts +10 -10
- package/src/codegen/mcfunction/index.ts +40 -3
- package/src/codegen/structure/index.ts +35 -1
- package/src/compile.ts +54 -6
- package/src/events/types.ts +69 -0
- package/src/examples/capture_the_flag.mcrs +208 -0
- package/src/examples/{counter.rs → counter.mcrs} +1 -1
- package/src/examples/hunger_games.mcrs +301 -0
- package/src/examples/new_features_demo.mcrs +193 -0
- package/src/examples/parkour_race.mcrs +233 -0
- package/src/examples/rpg.mcrs +13 -0
- package/src/examples/{shop.rs → shop.mcrs} +1 -1
- package/src/examples/{showcase_game.rs → showcase_game.mcrs} +3 -3
- package/src/examples/{turret.rs → turret.mcrs} +1 -1
- package/src/examples/zombie_survival.mcrs +314 -0
- package/src/index.ts +4 -3
- package/src/ir/builder.ts +3 -1
- package/src/ir/types.ts +12 -2
- package/src/lexer/index.ts +3 -1
- package/src/lowering/index.ts +684 -24
- package/src/mc-test/runner.ts +3 -3
- package/src/mc-test/setup.ts +2 -2
- package/src/parser/index.ts +170 -19
- package/src/stdlib/README.md +178 -140
- package/src/stdlib/bossbar.mcrs +68 -0
- package/src/stdlib/{cooldown.rs → cooldown.mcrs} +1 -1
- package/src/stdlib/effects.mcrs +64 -0
- package/src/stdlib/interactions.mcrs +195 -0
- package/src/stdlib/inventory.mcrs +38 -0
- package/src/stdlib/mobs.mcrs +99 -0
- package/src/stdlib/particles.mcrs +52 -0
- package/src/stdlib/sets.mcrs +20 -0
- package/src/stdlib/spawn.mcrs +41 -0
- package/src/stdlib/tags.mcrs +951 -0
- package/src/stdlib/teams.mcrs +68 -0
- package/src/stdlib/timer.mcrs +72 -0
- package/src/stdlib/world.mcrs +92 -0
- package/src/typechecker/index.ts +404 -18
- package/src/examples/rpg.rs +0 -13
- package/src/stdlib/mobs.rs +0 -99
- package/src/stdlib/timer.rs +0 -51
- /package/src/examples/{arena.rs → arena.mcrs} +0 -0
- /package/src/examples/{pvp_arena.rs → pvp_arena.mcrs} +0 -0
- /package/src/examples/{quiz.rs → quiz.mcrs} +0 -0
- /package/src/examples/{stdlib_demo.rs → stdlib_demo.mcrs} +0 -0
- /package/src/examples/{world_manager.rs → world_manager.mcrs} +0 -0
- /package/src/stdlib/{combat.rs → combat.mcrs} +0 -0
- /package/src/stdlib/{math.rs → math.mcrs} +0 -0
- /package/src/stdlib/{player.rs → player.mcrs} +0 -0
- /package/src/stdlib/{strings.rs → strings.mcrs} +0 -0
- /package/src/templates/{combat.rs → combat.mcrs} +0 -0
- /package/src/templates/{economy.rs → economy.mcrs} +0 -0
- /package/src/templates/{mini-game-framework.rs → mini-game-framework.mcrs} +0 -0
- /package/src/templates/{quest.rs → quest.mcrs} +0 -0
- /package/src/test_programs/{zombie_game.rs → zombie_game.mcrs} +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Team management helpers
|
|
2
|
+
// Usage: import "stdlib/teams.mcrs"
|
|
3
|
+
|
|
4
|
+
/// Create a team with color
|
|
5
|
+
fn create_team(name: string, color: string) {
|
|
6
|
+
team_add(name);
|
|
7
|
+
team_option(name, "color", color);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/// Create red team
|
|
11
|
+
fn create_red_team() {
|
|
12
|
+
team_add("red");
|
|
13
|
+
team_option("red", "color", "red");
|
|
14
|
+
team_option("red", "friendlyFire", "false");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/// Create blue team
|
|
18
|
+
fn create_blue_team() {
|
|
19
|
+
team_add("blue");
|
|
20
|
+
team_option("blue", "color", "blue");
|
|
21
|
+
team_option("blue", "friendlyFire", "false");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// Create green team
|
|
25
|
+
fn create_green_team() {
|
|
26
|
+
team_add("green");
|
|
27
|
+
team_option("green", "color", "green");
|
|
28
|
+
team_option("green", "friendlyFire", "false");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// Create yellow team
|
|
32
|
+
fn create_yellow_team() {
|
|
33
|
+
team_add("yellow");
|
|
34
|
+
team_option("yellow", "color", "yellow");
|
|
35
|
+
team_option("yellow", "friendlyFire", "false");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// Add player to team
|
|
39
|
+
fn add_to_team(target: selector, team_name: string) {
|
|
40
|
+
team_join(target, team_name);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Remove player from all teams
|
|
44
|
+
fn remove_from_teams(target: selector) {
|
|
45
|
+
team_leave(target);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// Setup standard 2-team game
|
|
49
|
+
fn setup_two_teams() {
|
|
50
|
+
create_red_team();
|
|
51
|
+
create_blue_team();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/// Setup 4-team game
|
|
55
|
+
fn setup_four_teams() {
|
|
56
|
+
create_red_team();
|
|
57
|
+
create_blue_team();
|
|
58
|
+
create_green_team();
|
|
59
|
+
create_yellow_team();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// Cleanup all teams
|
|
63
|
+
fn cleanup_teams() {
|
|
64
|
+
team_remove("red");
|
|
65
|
+
team_remove("blue");
|
|
66
|
+
team_remove("green");
|
|
67
|
+
team_remove("yellow");
|
|
68
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Timer utilities with an OOP-style API.
|
|
2
|
+
//
|
|
3
|
+
// Timer state is stored in scoreboard-backed runtime state. Because RedScript
|
|
4
|
+
// does not yet support dynamic scoreboard player/objective names for impl
|
|
5
|
+
// methods, this API currently uses a single shared runtime slot.
|
|
6
|
+
//
|
|
7
|
+
// The `_id` field is reserved for a future runtime-backed instance identifier.
|
|
8
|
+
// Today it remains `0`, while persistence is shared across Timer values.
|
|
9
|
+
|
|
10
|
+
struct Timer {
|
|
11
|
+
_id: int,
|
|
12
|
+
_duration: int
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
impl Timer {
|
|
16
|
+
/// Create a new timer with the given duration in ticks.
|
|
17
|
+
fn new(duration: int) -> Timer {
|
|
18
|
+
scoreboard_set("timer_ticks", #rs, 0);
|
|
19
|
+
scoreboard_set("timer_active", #rs, 0);
|
|
20
|
+
return { _id: 0, _duration: duration };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// Start or resume the timer.
|
|
24
|
+
fn start(self) {
|
|
25
|
+
scoreboard_set("timer_active", #rs, 1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// Pause the timer.
|
|
29
|
+
fn pause(self) {
|
|
30
|
+
scoreboard_set("timer_active", #rs, 0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/// Reset elapsed ticks back to zero.
|
|
34
|
+
fn reset(self) {
|
|
35
|
+
scoreboard_set("timer_ticks", #rs, 0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// Check whether the timer has reached its duration.
|
|
39
|
+
fn done(self) -> bool {
|
|
40
|
+
let ticks: int = scoreboard_get("timer_ticks", #rs);
|
|
41
|
+
return ticks >= self._duration;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// Get elapsed ticks.
|
|
45
|
+
fn elapsed(self) -> int {
|
|
46
|
+
return scoreboard_get("timer_ticks", #rs);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// Get remaining ticks, clamped at zero.
|
|
50
|
+
fn remaining(self) -> int {
|
|
51
|
+
let ticks: int = scoreboard_get("timer_ticks", #rs);
|
|
52
|
+
let left: int = self._duration - ticks;
|
|
53
|
+
|
|
54
|
+
if (left > 0) {
|
|
55
|
+
return left;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/// Manually advance the timer by one tick when active.
|
|
62
|
+
fn tick(self) {
|
|
63
|
+
let active: int = scoreboard_get("timer_active", #rs);
|
|
64
|
+
let ticks: int = scoreboard_get("timer_ticks", #rs);
|
|
65
|
+
|
|
66
|
+
if (active == 1) {
|
|
67
|
+
if (ticks < self._duration) {
|
|
68
|
+
scoreboard_set("timer_ticks", #rs, ticks + 1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// World manipulation helpers
|
|
2
|
+
|
|
3
|
+
/// Set time to day
|
|
4
|
+
fn set_day() {
|
|
5
|
+
time_set(1000);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/// Set time to night
|
|
9
|
+
fn set_night() {
|
|
10
|
+
time_set(13000);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/// Set time to noon
|
|
14
|
+
fn set_noon() {
|
|
15
|
+
time_set(6000);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// Set time to midnight
|
|
19
|
+
fn set_midnight() {
|
|
20
|
+
time_set(18000);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// Set weather to clear
|
|
24
|
+
fn weather_clear() {
|
|
25
|
+
weather("clear");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// Set weather to rain
|
|
29
|
+
fn weather_rain() {
|
|
30
|
+
weather("rain");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/// Set weather to thunder
|
|
34
|
+
fn weather_thunder() {
|
|
35
|
+
weather("thunder");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// Enable keep inventory
|
|
39
|
+
fn enable_keep_inventory() {
|
|
40
|
+
gamerule("keepInventory", "true");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Disable keep inventory
|
|
44
|
+
fn disable_keep_inventory() {
|
|
45
|
+
gamerule("keepInventory", "false");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// Disable mob griefing
|
|
49
|
+
fn disable_mob_griefing() {
|
|
50
|
+
gamerule("mobGriefing", "false");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// Disable fire spread
|
|
54
|
+
fn disable_fire_spread() {
|
|
55
|
+
gamerule("doFireTick", "false");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// Set difficulty to peaceful
|
|
59
|
+
fn set_peaceful() {
|
|
60
|
+
difficulty("peaceful");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// Set difficulty to easy
|
|
64
|
+
fn set_easy() {
|
|
65
|
+
difficulty("easy");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// Set difficulty to normal
|
|
69
|
+
fn set_normal() {
|
|
70
|
+
difficulty("normal");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// Set difficulty to hard
|
|
74
|
+
fn set_hard() {
|
|
75
|
+
difficulty("hard");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// Create barrier wall
|
|
79
|
+
fn barrier_wall(x1: int, y1: int, z1: int, x2: int, y2: int, z2: int) {
|
|
80
|
+
fill(x1, y1, z1, x2, y2, z2, "minecraft:barrier");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/// Create air (clear area)
|
|
84
|
+
fn clear_area(x1: int, y1: int, z1: int, x2: int, y2: int, z2: int) {
|
|
85
|
+
fill(x1, y1, z1, x2, y2, z2, "minecraft:air");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/// Create glass dome (hollow)
|
|
89
|
+
fn glass_box(x1: int, y1: int, z1: int, x2: int, y2: int, z2: int) {
|
|
90
|
+
fill(x1, y1, z1, x2, y2, z2, "minecraft:glass");
|
|
91
|
+
fill(x1 + 1, y1 + 1, z1 + 1, x2 - 1, y2 - 1, z2 - 1, "minecraft:air");
|
|
92
|
+
}
|