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.
Files changed (136) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +72 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.yml +57 -0
  3. package/.github/PULL_REQUEST_TEMPLATE.md +17 -25
  4. package/CHANGELOG.md +112 -0
  5. package/CONTRIBUTING.md +140 -0
  6. package/README.md +28 -19
  7. package/README.zh.md +28 -19
  8. package/dist/__tests__/cli.test.js +148 -10
  9. package/dist/__tests__/codegen.test.js +26 -1
  10. package/dist/__tests__/diagnostics.test.js +5 -5
  11. package/dist/__tests__/e2e.test.js +336 -17
  12. package/dist/__tests__/formatter.test.d.ts +1 -0
  13. package/dist/__tests__/formatter.test.js +40 -0
  14. package/dist/__tests__/lexer.test.js +12 -2
  15. package/dist/__tests__/lowering.test.js +200 -12
  16. package/dist/__tests__/mc-integration.test.js +370 -31
  17. package/dist/__tests__/mc-syntax.test.js +3 -3
  18. package/dist/__tests__/nbt.test.js +2 -2
  19. package/dist/__tests__/optimizer-advanced.test.js +5 -5
  20. package/dist/__tests__/parser.test.js +80 -0
  21. package/dist/__tests__/runtime.test.js +9 -9
  22. package/dist/__tests__/typechecker.test.js +158 -0
  23. package/dist/ast/types.d.ts +40 -3
  24. package/dist/cli.js +25 -7
  25. package/dist/codegen/mcfunction/index.d.ts +1 -1
  26. package/dist/codegen/mcfunction/index.js +38 -3
  27. package/dist/codegen/structure/index.js +32 -1
  28. package/dist/compile.d.ts +10 -0
  29. package/dist/compile.js +36 -5
  30. package/dist/events/types.d.ts +35 -0
  31. package/dist/events/types.js +59 -0
  32. package/dist/formatter/index.d.ts +1 -0
  33. package/dist/formatter/index.js +26 -0
  34. package/dist/index.js +3 -2
  35. package/dist/ir/builder.d.ts +2 -1
  36. package/dist/ir/types.d.ts +11 -2
  37. package/dist/ir/types.js +1 -1
  38. package/dist/lexer/index.d.ts +1 -1
  39. package/dist/lexer/index.js +2 -0
  40. package/dist/lowering/index.d.ts +34 -1
  41. package/dist/lowering/index.js +622 -23
  42. package/dist/mc-test/runner.d.ts +2 -2
  43. package/dist/mc-test/runner.js +3 -3
  44. package/dist/mc-test/setup.js +2 -2
  45. package/dist/parser/index.d.ts +4 -0
  46. package/dist/parser/index.js +153 -16
  47. package/dist/typechecker/index.d.ts +17 -0
  48. package/dist/typechecker/index.js +343 -17
  49. package/docs/COMPILATION_STATS.md +24 -24
  50. package/docs/ENTITY_TYPE_SYSTEM.md +242 -0
  51. package/docs/IMPLEMENTATION_GUIDE.md +1 -1
  52. package/docs/STRUCTURE_TARGET.md +1 -1
  53. package/editors/vscode/.vscodeignore +1 -0
  54. package/editors/vscode/CHANGELOG.md +9 -0
  55. package/editors/vscode/icons/mcrs.svg +7 -0
  56. package/editors/vscode/icons/redscript-icons.json +10 -0
  57. package/editors/vscode/out/extension.js +1295 -80
  58. package/editors/vscode/package-lock.json +2 -2
  59. package/editors/vscode/package.json +10 -3
  60. package/editors/vscode/src/hover.ts +55 -2
  61. package/editors/vscode/src/symbols.ts +42 -0
  62. package/package.json +1 -1
  63. package/src/__tests__/cli.test.ts +176 -10
  64. package/src/__tests__/codegen.test.ts +28 -1
  65. package/src/__tests__/diagnostics.test.ts +5 -5
  66. package/src/__tests__/e2e.test.ts +335 -17
  67. package/src/__tests__/fixtures/event-test.mcrs +13 -0
  68. package/src/__tests__/fixtures/impl-test.mcrs +46 -0
  69. package/src/__tests__/fixtures/interval-test.mcrs +11 -0
  70. package/src/__tests__/fixtures/is-check-test.mcrs +20 -0
  71. package/src/__tests__/fixtures/timeout-test.mcrs +7 -0
  72. package/src/__tests__/lexer.test.ts +14 -2
  73. package/src/__tests__/lowering.test.ts +226 -12
  74. package/src/__tests__/mc-integration.test.ts +421 -31
  75. package/src/__tests__/mc-syntax.test.ts +3 -3
  76. package/src/__tests__/nbt.test.ts +2 -2
  77. package/src/__tests__/optimizer-advanced.test.ts +5 -5
  78. package/src/__tests__/parser.test.ts +91 -5
  79. package/src/__tests__/runtime.test.ts +9 -9
  80. package/src/__tests__/typechecker.test.ts +171 -0
  81. package/src/ast/types.ts +44 -3
  82. package/src/cli.ts +10 -10
  83. package/src/codegen/mcfunction/index.ts +40 -3
  84. package/src/codegen/structure/index.ts +35 -1
  85. package/src/compile.ts +54 -6
  86. package/src/events/types.ts +69 -0
  87. package/src/examples/capture_the_flag.mcrs +208 -0
  88. package/src/examples/{counter.rs → counter.mcrs} +1 -1
  89. package/src/examples/hunger_games.mcrs +301 -0
  90. package/src/examples/new_features_demo.mcrs +193 -0
  91. package/src/examples/parkour_race.mcrs +233 -0
  92. package/src/examples/rpg.mcrs +13 -0
  93. package/src/examples/{shop.rs → shop.mcrs} +1 -1
  94. package/src/examples/{showcase_game.rs → showcase_game.mcrs} +3 -3
  95. package/src/examples/{turret.rs → turret.mcrs} +1 -1
  96. package/src/examples/zombie_survival.mcrs +314 -0
  97. package/src/index.ts +4 -3
  98. package/src/ir/builder.ts +3 -1
  99. package/src/ir/types.ts +12 -2
  100. package/src/lexer/index.ts +3 -1
  101. package/src/lowering/index.ts +684 -24
  102. package/src/mc-test/runner.ts +3 -3
  103. package/src/mc-test/setup.ts +2 -2
  104. package/src/parser/index.ts +170 -19
  105. package/src/stdlib/README.md +178 -140
  106. package/src/stdlib/bossbar.mcrs +68 -0
  107. package/src/stdlib/{cooldown.rs → cooldown.mcrs} +1 -1
  108. package/src/stdlib/effects.mcrs +64 -0
  109. package/src/stdlib/interactions.mcrs +195 -0
  110. package/src/stdlib/inventory.mcrs +38 -0
  111. package/src/stdlib/mobs.mcrs +99 -0
  112. package/src/stdlib/particles.mcrs +52 -0
  113. package/src/stdlib/sets.mcrs +20 -0
  114. package/src/stdlib/spawn.mcrs +41 -0
  115. package/src/stdlib/tags.mcrs +951 -0
  116. package/src/stdlib/teams.mcrs +68 -0
  117. package/src/stdlib/timer.mcrs +72 -0
  118. package/src/stdlib/world.mcrs +92 -0
  119. package/src/typechecker/index.ts +404 -18
  120. package/src/examples/rpg.rs +0 -13
  121. package/src/stdlib/mobs.rs +0 -99
  122. package/src/stdlib/timer.rs +0 -51
  123. /package/src/examples/{arena.rs → arena.mcrs} +0 -0
  124. /package/src/examples/{pvp_arena.rs → pvp_arena.mcrs} +0 -0
  125. /package/src/examples/{quiz.rs → quiz.mcrs} +0 -0
  126. /package/src/examples/{stdlib_demo.rs → stdlib_demo.mcrs} +0 -0
  127. /package/src/examples/{world_manager.rs → world_manager.mcrs} +0 -0
  128. /package/src/stdlib/{combat.rs → combat.mcrs} +0 -0
  129. /package/src/stdlib/{math.rs → math.mcrs} +0 -0
  130. /package/src/stdlib/{player.rs → player.mcrs} +0 -0
  131. /package/src/stdlib/{strings.rs → strings.mcrs} +0 -0
  132. /package/src/templates/{combat.rs → combat.mcrs} +0 -0
  133. /package/src/templates/{economy.rs → economy.mcrs} +0 -0
  134. /package/src/templates/{mini-game-framework.rs → mini-game-framework.mcrs} +0 -0
  135. /package/src/templates/{quest.rs → quest.mcrs} +0 -0
  136. /package/src/test_programs/{zombie_game.rs → zombie_game.mcrs} +0 -0
@@ -0,0 +1,38 @@
1
+ // Inventory management helpers
2
+
3
+ /// Clear all items from a player's inventory
4
+ fn clear_inventory(target: selector) {
5
+ clear(target);
6
+ }
7
+
8
+ /// Give a kit of items to a player
9
+ fn give_kit_warrior(target: selector) {
10
+ give(target, "minecraft:iron_sword", 1);
11
+ give(target, "minecraft:iron_chestplate", 1);
12
+ give(target, "minecraft:iron_leggings", 1);
13
+ give(target, "minecraft:iron_boots", 1);
14
+ give(target, "minecraft:shield", 1);
15
+ give(target, "minecraft:cooked_beef", 16);
16
+ }
17
+
18
+ fn give_kit_archer(target: selector) {
19
+ give(target, "minecraft:bow", 1);
20
+ give(target, "minecraft:arrow", 64);
21
+ give(target, "minecraft:leather_chestplate", 1);
22
+ give(target, "minecraft:leather_leggings", 1);
23
+ give(target, "minecraft:leather_boots", 1);
24
+ give(target, "minecraft:cooked_beef", 16);
25
+ }
26
+
27
+ fn give_kit_mage(target: selector) {
28
+ give(target, "minecraft:wooden_sword", 1);
29
+ give(target, "minecraft:golden_apple", 8);
30
+ give(target, "minecraft:ender_pearl", 16);
31
+ give(target, "minecraft:splash_potion{Potion:\"minecraft:harming\"}", 8);
32
+ give(target, "minecraft:cooked_beef", 16);
33
+ }
34
+
35
+ /// Remove a specific item from player
36
+ fn remove_item(target: selector, item: string) {
37
+ clear(target, item);
38
+ }
@@ -0,0 +1,99 @@
1
+ // Vanilla Minecraft Java Edition entity type constants.
2
+ // Copy the names you need into your own project until RedScript gets imports.
3
+
4
+ // Hostile mobs
5
+ const ZOMBIE ="minecraft:zombie"
6
+ const SKELETON ="minecraft:skeleton"
7
+ const CREEPER ="minecraft:creeper"
8
+ const SPIDER ="minecraft:spider"
9
+ const CAVE_SPIDER ="minecraft:cave_spider"
10
+ const ENDERMAN ="minecraft:enderman"
11
+ const WITCH ="minecraft:witch"
12
+ const PHANTOM ="minecraft:phantom"
13
+ const DROWNED ="minecraft:drowned"
14
+ const HUSK ="minecraft:husk"
15
+ const STRAY ="minecraft:stray"
16
+ const WARDEN ="minecraft:warden"
17
+ const PILLAGER ="minecraft:pillager"
18
+ const RAVAGER ="minecraft:ravager"
19
+ const VINDICATOR ="minecraft:vindicator"
20
+ const EVOKER ="minecraft:evoker"
21
+ const VEXE ="minecraft:vex"
22
+ const ZOMBIE_VILLAGER ="minecraft:zombie_villager"
23
+ const BLAZE ="minecraft:blaze"
24
+ const GHAST ="minecraft:ghast"
25
+ const MAGMA_CUBE ="minecraft:magma_cube"
26
+ const SLIME ="minecraft:slime"
27
+ const PIGLIN_BRUTE ="minecraft:piglin_brute"
28
+ const HOGLIN ="minecraft:hoglin"
29
+ const ZOGLIN ="minecraft:zoglin"
30
+ const ENDERMITE ="minecraft:endermite"
31
+ const SILVERFISH ="minecraft:silverfish"
32
+ const SHULKER ="minecraft:shulker"
33
+ const GUARDIAN ="minecraft:guardian"
34
+ const ELDER_GUARDIAN ="minecraft:elder_guardian"
35
+ const BOGGED ="minecraft:bogged"
36
+ const BREEZE ="minecraft:breeze"
37
+
38
+ // Passive mobs
39
+ const PIG ="minecraft:pig"
40
+ const COW ="minecraft:cow"
41
+ const SHEEP ="minecraft:sheep"
42
+ const CHICKEN ="minecraft:chicken"
43
+ const HORSE ="minecraft:horse"
44
+ const DONKEY ="minecraft:donkey"
45
+ const MULE ="minecraft:mule"
46
+ const RABBIT ="minecraft:rabbit"
47
+ const COD ="minecraft:cod"
48
+ const SALMON ="minecraft:salmon"
49
+ const TROPICAL_FISH ="minecraft:tropical_fish"
50
+ const PUFFERFISH ="minecraft:pufferfish"
51
+ const SQUID ="minecraft:squid"
52
+ const GLOW_SQUID ="minecraft:glow_squid"
53
+ const BAT ="minecraft:bat"
54
+ const VILLAGER ="minecraft:villager"
55
+ const WANDERING_TRADER ="minecraft:wandering_trader"
56
+ const SNOW_GOLEM ="minecraft:snow_golem"
57
+ const STRIDER ="minecraft:strider"
58
+ const AXOLOTL ="minecraft:axolotl"
59
+ const FROG ="minecraft:frog"
60
+ const TADPOLE ="minecraft:tadpole"
61
+ const ALLAY ="minecraft:allay"
62
+ const SNIFFER ="minecraft:sniffer"
63
+ const ARMADILLO ="minecraft:armadillo"
64
+ const TURTLE ="minecraft:turtle"
65
+
66
+ // Neutral mobs
67
+ const WOLF ="minecraft:wolf"
68
+ const BEE ="minecraft:bee"
69
+ const POLAR_BEAR ="minecraft:polar_bear"
70
+ const DOLPHIN ="minecraft:dolphin"
71
+ const IRON_GOLEM ="minecraft:iron_golem"
72
+ const PIGLIN ="minecraft:piglin"
73
+ const ZOMBIFIED_PIGLIN ="minecraft:zombified_piglin"
74
+ const PANDA ="minecraft:panda"
75
+ const LLAMA ="minecraft:llama"
76
+ const TRADER_LLAMA ="minecraft:trader_llama"
77
+ const CAT ="minecraft:cat"
78
+ const OCELOT ="minecraft:ocelot"
79
+ const FOX ="minecraft:fox"
80
+ const GOAT ="minecraft:goat"
81
+ const CAMEL ="minecraft:camel"
82
+
83
+ // Bosses
84
+ const ENDER_DRAGON ="minecraft:ender_dragon"
85
+ const WITHER ="minecraft:wither"
86
+
87
+ // Special / misc
88
+ const ARMOR_STAND ="minecraft:armor_stand"
89
+ const ITEM_FRAME ="minecraft:item_frame"
90
+ const GLOW_ITEM_FRAME ="minecraft:glow_item_frame"
91
+ const PAINTING ="minecraft:painting"
92
+ const BOAT ="minecraft:boat"
93
+ const MINECART ="minecraft:minecart"
94
+ const TNT ="minecraft:tnt"
95
+ const FALLING_BLOCK ="minecraft:falling_block"
96
+ const ITEM ="minecraft:item"
97
+ const XP_ORB ="minecraft:experience_orb"
98
+ const FIREBALL ="minecraft:fireball"
99
+ const PLAYER ="minecraft:player"
@@ -0,0 +1,52 @@
1
+ // Particle effect helpers
2
+ // Usage: import "stdlib/particles.mcrs"
3
+
4
+ /// Spawn heart particles at position
5
+ fn hearts_at(x: int, y: int, z: int) {
6
+ particle("heart", x, y, z);
7
+ }
8
+
9
+ /// Spawn flame particles at position
10
+ fn flames(x: int, y: int, z: int) {
11
+ particle("flame", x, y, z);
12
+ }
13
+
14
+ /// Spawn smoke effect
15
+ fn smoke(x: int, y: int, z: int) {
16
+ particle("large_smoke", x, y, z);
17
+ }
18
+
19
+ /// Spawn explosion effect
20
+ fn explosion_effect(x: int, y: int, z: int) {
21
+ particle("explosion", x, y, z);
22
+ }
23
+
24
+ /// Spawn magic sparkles at position
25
+ fn sparkles_at(x: int, y: int, z: int) {
26
+ particle("enchant", x, y, z);
27
+ }
28
+
29
+ /// Spawn angry villager particles
30
+ fn angry_at(x: int, y: int, z: int) {
31
+ particle("angry_villager", x, y, z);
32
+ }
33
+
34
+ /// Spawn happy villager particles
35
+ fn happy_at(x: int, y: int, z: int) {
36
+ particle("happy_villager", x, y, z);
37
+ }
38
+
39
+ /// Spawn portal effect
40
+ fn portal_effect(x: int, y: int, z: int) {
41
+ particle("portal", x, y, z);
42
+ }
43
+
44
+ /// Spawn totem particles at position
45
+ fn totem_at(x: int, y: int, z: int) {
46
+ particle("totem_of_undying", x, y, z);
47
+ }
48
+
49
+ /// Spawn end rod sparkles
50
+ fn end_sparkles_at(x: int, y: int, z: int) {
51
+ particle("end_rod", x, y, z);
52
+ }
@@ -0,0 +1,20 @@
1
+ // Runtime Set implementation using NBT storage.
2
+ // Sets are stored as NBT arrays with uniqueness enforced on add.
3
+ //
4
+ // Note: This is reference documentation for the builtins.
5
+ // Actual implementation is in the compiler.
6
+ //
7
+ // fn set_new() -> string
8
+ // Creates a new empty set. Returns a unique set ID.
9
+ //
10
+ // fn set_add(set: string, value: string)
11
+ // Adds a value to the set if it is not already present.
12
+ //
13
+ // fn set_contains(set: string, value: string) -> int
14
+ // Returns 1 if the value exists in the set, 0 otherwise.
15
+ //
16
+ // fn set_remove(set: string, value: string)
17
+ // Removes a value from the set.
18
+ //
19
+ // fn set_clear(set: string)
20
+ // Removes all values from the set.
@@ -0,0 +1,41 @@
1
+ // Spawn point and teleport helpers
2
+ // Usage: import "stdlib/spawn.mcrs"
3
+
4
+ /// Teleport player to coordinates
5
+ fn teleport_to(target: selector, x: int, y: int, z: int) {
6
+ tp(target, x, y, z);
7
+ }
8
+
9
+ /// Teleport player to another entity
10
+ fn teleport_to_entity(target: selector, dest: selector) {
11
+ tp(target, dest);
12
+ }
13
+
14
+ /// Spread players randomly in area
15
+ fn spread_players(x: int, z: int, radius: int) {
16
+ // Use raw command for spreadplayers
17
+ // spreadplayers(x, z, 0, radius, false, @a);
18
+ say("Spreading players...");
19
+ }
20
+
21
+ /// Teleport all players to one location
22
+ fn gather_all(x: int, y: int, z: int) {
23
+ tp(@a, x, y, z);
24
+ }
25
+
26
+ /// Teleport player up (for launching)
27
+ fn launch_up(target: selector, height: int) {
28
+ tp(target, ~0, ~height, ~0);
29
+ }
30
+
31
+ /// Teleport to lobby (customize coordinates)
32
+ fn goto_lobby(target: selector) {
33
+ tp(target, 0, 64, 0);
34
+ title(target, "Welcome to Lobby!");
35
+ }
36
+
37
+ /// Teleport to arena (customize coordinates)
38
+ fn goto_arena(target: selector) {
39
+ tp(target, 100, 64, 100);
40
+ title(target, "Fight!");
41
+ }