redscript-mc 1.2.9 → 1.2.11

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 (219) hide show
  1. package/README.md +35 -33
  2. package/README.zh.md +35 -33
  3. package/demo.gif +0 -0
  4. package/dist/__tests__/mc-integration.test.js +85 -0
  5. package/dist/ast/types.d.ts +84 -2
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/lexer/index.d.ts +1 -1
  9. package/dist/lexer/index.js +2 -0
  10. package/dist/lowering/index.d.ts +3 -0
  11. package/dist/lowering/index.js +119 -11
  12. package/dist/optimizer/dce.js +6 -0
  13. package/dist/parser/index.d.ts +4 -0
  14. package/dist/parser/index.js +171 -18
  15. package/package.json +1 -1
  16. package/src/__tests__/fixtures/array-test.mcrs +30 -0
  17. package/src/__tests__/fixtures/break-continue-test.mcrs +46 -0
  18. package/src/__tests__/fixtures/enum-test.mcrs +37 -0
  19. package/src/__tests__/fixtures/foreach-at-test.mcrs +33 -0
  20. package/src/__tests__/fixtures/match-range-test.mcrs +45 -0
  21. package/src/__tests__/fixtures/struct-test.mcrs +34 -0
  22. package/src/__tests__/mc-integration.test.ts +97 -0
  23. package/src/ast/types.ts +24 -1
  24. package/src/index.ts +1 -1
  25. package/src/lexer/index.ts +3 -1
  26. package/src/lowering/index.ts +123 -11
  27. package/src/optimizer/dce.ts +6 -0
  28. package/src/parser/index.ts +159 -18
  29. package/test-datapacks/README.md +67 -0
  30. package/test-datapacks/test_control_flow/data/minecraft/tags/function/load.json +5 -0
  31. package/test-datapacks/test_control_flow/data/test_control_flow/function/__load.mcfunction +41 -0
  32. package/test-datapacks/test_control_flow/data/test_control_flow/function/run_control_flow_tests.mcfunction +21 -0
  33. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/else_7.mcfunction +3 -0
  34. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/else_8.mcfunction +3 -0
  35. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/for_body_1.mcfunction +5 -0
  36. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/for_check_0.mcfunction +5 -0
  37. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/for_continue_2.mcfunction +5 -0
  38. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/for_exit_2.mcfunction +5 -0
  39. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/for_exit_3.mcfunction +5 -0
  40. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/merge_5.mcfunction +5 -0
  41. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/merge_6.mcfunction +2 -0
  42. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/merge_8.mcfunction +1 -0
  43. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/merge_9.mcfunction +1 -0
  44. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/then_3.mcfunction +3 -0
  45. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/then_4.mcfunction +3 -0
  46. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/then_6.mcfunction +3 -0
  47. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/then_7.mcfunction +3 -0
  48. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break.mcfunction +4 -0
  49. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/else_1.mcfunction +3 -0
  50. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/else_10.mcfunction +3 -0
  51. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/else_4.mcfunction +3 -0
  52. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/else_7.mcfunction +3 -0
  53. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/merge_11.mcfunction +1 -0
  54. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/merge_2.mcfunction +9 -0
  55. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/merge_5.mcfunction +7 -0
  56. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/merge_8.mcfunction +13 -0
  57. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/then_0.mcfunction +3 -0
  58. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/then_3.mcfunction +3 -0
  59. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/then_6.mcfunction +3 -0
  60. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/then_9.mcfunction +3 -0
  61. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions.mcfunction +12 -0
  62. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/else_7.mcfunction +3 -0
  63. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/else_8.mcfunction +3 -0
  64. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/for_body_1.mcfunction +7 -0
  65. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/for_check_0.mcfunction +5 -0
  66. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/for_continue_2.mcfunction +5 -0
  67. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/for_exit_2.mcfunction +5 -0
  68. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/for_exit_3.mcfunction +5 -0
  69. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/merge_5.mcfunction +8 -0
  70. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/merge_6.mcfunction +5 -0
  71. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/merge_8.mcfunction +1 -0
  72. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/merge_9.mcfunction +1 -0
  73. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/then_3.mcfunction +2 -0
  74. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/then_4.mcfunction +2 -0
  75. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/then_6.mcfunction +3 -0
  76. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/then_7.mcfunction +3 -0
  77. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue.mcfunction +4 -0
  78. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/else_13.mcfunction +3 -0
  79. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/else_16.mcfunction +3 -0
  80. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/else_4.mcfunction +3 -0
  81. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/else_5.mcfunction +3 -0
  82. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_body_1.mcfunction +5 -0
  83. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_body_10.mcfunction +8 -0
  84. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_body_12.mcfunction +5 -0
  85. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_body_7.mcfunction +3 -0
  86. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_body_8.mcfunction +3 -0
  87. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_check_0.mcfunction +5 -0
  88. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_check_11.mcfunction +5 -0
  89. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_check_6.mcfunction +5 -0
  90. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_check_7.mcfunction +5 -0
  91. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_check_9.mcfunction +5 -0
  92. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_continue_13.mcfunction +5 -0
  93. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_continue_2.mcfunction +5 -0
  94. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_continue_9.mcfunction +5 -0
  95. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_10.mcfunction +5 -0
  96. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_11.mcfunction +5 -0
  97. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_14.mcfunction +2 -0
  98. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_2.mcfunction +5 -0
  99. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_3.mcfunction +5 -0
  100. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_8.mcfunction +5 -0
  101. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/merge_14.mcfunction +1 -0
  102. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/merge_17.mcfunction +1 -0
  103. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/merge_5.mcfunction +4 -0
  104. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/merge_6.mcfunction +4 -0
  105. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/then_12.mcfunction +3 -0
  106. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/then_15.mcfunction +3 -0
  107. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/then_3.mcfunction +3 -0
  108. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/then_4.mcfunction +3 -0
  109. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop.mcfunction +4 -0
  110. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_at/foreach_0.mcfunction +2 -0
  111. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_at.mcfunction +5 -0
  112. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_selector/else_1.mcfunction +3 -0
  113. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_selector/foreach_0.mcfunction +4 -0
  114. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_selector/merge_2.mcfunction +2 -0
  115. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_selector/then_0.mcfunction +3 -0
  116. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_selector.mcfunction +11 -0
  117. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/else_1.mcfunction +3 -0
  118. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/else_13.mcfunction +5 -0
  119. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/else_16.mcfunction +3 -0
  120. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/else_4.mcfunction +3 -0
  121. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_11.mcfunction +2 -0
  122. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_14.mcfunction +1 -0
  123. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_17.mcfunction +2 -0
  124. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_2.mcfunction +5 -0
  125. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_5.mcfunction +5 -0
  126. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_8.mcfunction +6 -0
  127. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_0.mcfunction +3 -0
  128. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_12.mcfunction +3 -0
  129. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_15.mcfunction +3 -0
  130. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_3.mcfunction +3 -0
  131. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_6.mcfunction +5 -0
  132. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_9.mcfunction +3 -0
  133. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else.mcfunction +6 -0
  134. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_0.mcfunction +3 -0
  135. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_1.mcfunction +3 -0
  136. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_2.mcfunction +3 -0
  137. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_3.mcfunction +2 -0
  138. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_4.mcfunction +3 -0
  139. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_5.mcfunction +3 -0
  140. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_6.mcfunction +3 -0
  141. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_7.mcfunction +3 -0
  142. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_8.mcfunction +3 -0
  143. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_9.mcfunction +2 -0
  144. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match.mcfunction +15 -0
  145. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/else_13.mcfunction +3 -0
  146. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/else_4.mcfunction +3 -0
  147. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_body_1.mcfunction +5 -0
  148. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_body_7.mcfunction +8 -0
  149. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_check_0.mcfunction +5 -0
  150. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_check_6.mcfunction +4 -0
  151. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_exit_2.mcfunction +5 -0
  152. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_exit_8.mcfunction +5 -0
  153. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/merge_11.mcfunction +2 -0
  154. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/merge_14.mcfunction +1 -0
  155. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/merge_5.mcfunction +3 -0
  156. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/then_12.mcfunction +3 -0
  157. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/then_3.mcfunction +3 -0
  158. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/then_9.mcfunction +2 -0
  159. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop.mcfunction +3 -0
  160. package/test-datapacks/test_control_flow/pack.mcmeta +6 -0
  161. package/test-datapacks/test_control_flow.mcrs +242 -0
  162. package/test-datapacks/test_decorators/data/minecraft/tags/function/load.json +5 -0
  163. package/test-datapacks/test_decorators/data/minecraft/tags/function/tick.json +5 -0
  164. package/test-datapacks/test_decorators/data/test_decorators/function/__load.mcfunction +20 -0
  165. package/test-datapacks/test_decorators/data/test_decorators/function/__tick.mcfunction +3 -0
  166. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/merge_2.mcfunction +9 -0
  167. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/merge_5.mcfunction +1 -0
  168. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/then_0.mcfunction +1 -0
  169. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/then_3.mcfunction +4 -0
  170. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/tick_body.mcfunction +6 -0
  171. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/tick_skip.mcfunction +1 -0
  172. package/test-datapacks/test_decorators/data/test_decorators/function/every_second.mcfunction +5 -0
  173. package/test-datapacks/test_decorators/data/test_decorators/function/on_load.mcfunction +2 -0
  174. package/test-datapacks/test_decorators/data/test_decorators/function/on_test_trigger.mcfunction +2 -0
  175. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/merge_2.mcfunction +10 -0
  176. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/merge_5.mcfunction +5 -0
  177. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/merge_8.mcfunction +1 -0
  178. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/then_0.mcfunction +1 -0
  179. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/then_3.mcfunction +3 -0
  180. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/then_6.mcfunction +4 -0
  181. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick.mcfunction +5 -0
  182. package/test-datapacks/test_decorators/data/test_decorators/function/run_decorator_tests.mcfunction +7 -0
  183. package/test-datapacks/test_decorators/data/test_decorators/function/setup_trigger_test.mcfunction +4 -0
  184. package/test-datapacks/test_decorators/data/test_decorators/function/start_slow_tick_test.mcfunction +4 -0
  185. package/test-datapacks/test_decorators/data/test_decorators/function/start_tick_test.mcfunction +4 -0
  186. package/test-datapacks/test_decorators/data/test_decorators/function/stop_tick_test.mcfunction +3 -0
  187. package/test-datapacks/test_decorators/pack.mcmeta +6 -0
  188. package/test-datapacks/test_decorators.mcrs +81 -0
  189. package/test-datapacks/test_events/data/minecraft/tags/function/load.json +5 -0
  190. package/test-datapacks/test_events/data/test_events/advancements/on_death_on_player_death.json +10 -0
  191. package/test-datapacks/test_events/data/test_events/function/__load.mcfunction +3 -0
  192. package/test-datapacks/test_events/data/test_events/function/on_player_death.mcfunction +3 -0
  193. package/test-datapacks/test_events/data/test_events/function/run_event_tests.mcfunction +5 -0
  194. package/test-datapacks/test_events/data/test_events/function/setup_events.mcfunction +3 -0
  195. package/test-datapacks/test_events/data/test_events/function/spawn_test_entity.mcfunction +3 -0
  196. package/test-datapacks/test_events/data/test_events/function/test_advancement_event.mcfunction +4 -0
  197. package/test-datapacks/test_events/pack.mcmeta +6 -0
  198. package/test-datapacks/test_events.mcrs +37 -0
  199. package/test-datapacks/test_fstrings/data/minecraft/tags/function/load.json +5 -0
  200. package/test-datapacks/test_fstrings/data/test_fstrings/function/__load.mcfunction +10 -0
  201. package/test-datapacks/test_fstrings/data/test_fstrings/function/run_fstring_tests.mcfunction +15 -0
  202. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_actionbar_fstring.mcfunction +4 -0
  203. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_announce.mcfunction +3 -0
  204. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_multi_var_fstring.mcfunction +9 -0
  205. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_say_fstring.mcfunction +4 -0
  206. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_tell.mcfunction +3 -0
  207. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_title_fstring.mcfunction +4 -0
  208. package/test-datapacks/test_fstrings/pack.mcmeta +6 -0
  209. package/test-datapacks/test_fstrings.mcrs +58 -0
  210. package/test-datapacks/test_timers/data/minecraft/tags/function/load.json +5 -0
  211. package/test-datapacks/test_timers/data/test_timers/function/__interval_0.mcfunction +3 -0
  212. package/test-datapacks/test_timers/data/test_timers/function/__interval_body_0.mcfunction +5 -0
  213. package/test-datapacks/test_timers/data/test_timers/function/__load.mcfunction +5 -0
  214. package/test-datapacks/test_timers/data/test_timers/function/__timeout_0.mcfunction +2 -0
  215. package/test-datapacks/test_timers/data/test_timers/function/run_timer_tests.mcfunction +5 -0
  216. package/test-datapacks/test_timers/data/test_timers/function/test_set_interval.mcfunction +5 -0
  217. package/test-datapacks/test_timers/data/test_timers/function/test_set_timeout.mcfunction +3 -0
  218. package/test-datapacks/test_timers/pack.mcmeta +6 -0
  219. package/test-datapacks/test_timers.mcrs +35 -0
@@ -0,0 +1,4 @@
1
+ # block: entry
2
+ scoreboard players set $sum rs 0
3
+ scoreboard players set $i rs 1
4
+ function test_control_flow:test_for_loop/for_check_0
@@ -0,0 +1,2 @@
1
+ # block: entry
2
+ particle minecraft:heart ~ ~ ~ 0 0 0 0 1
@@ -0,0 +1,5 @@
1
+ # block: entry
2
+ summon minecraft:marker ~ ~1 ~ {Tags:["pos_test"]}
3
+ execute as @e[type=minecraft:marker,tag=pos_test] at @s run function test_control_flow:test_foreach_at/foreach_0
4
+ say [PASS] foreach at @s: executed at entity position
5
+ kill @e[type=marker,tag=pos_test]
@@ -0,0 +1,3 @@
1
+ # block: else_1
2
+ say [INFO] foreach selector: found markers (count varies)
3
+ function test_control_flow:test_foreach_selector/merge_2
@@ -0,0 +1,4 @@
1
+ # block: entry
2
+ scoreboard players operation $_23 rs = $marker_count rs
3
+ scoreboard players operation $_23 rs += $const_1 rs
4
+ scoreboard players operation $marker_count rs = $_23 rs
@@ -0,0 +1,2 @@
1
+ # block: merge_2
2
+ kill @e[type=marker,tag=test_marker]
@@ -0,0 +1,3 @@
1
+ # block: then_0
2
+ say [PASS] foreach selector: found 3 markers
3
+ function test_control_flow:test_foreach_selector/merge_2
@@ -0,0 +1,11 @@
1
+ # block: entry
2
+ say [INFO] foreach selector test - spawning markers
3
+ summon minecraft:marker ~ ~ ~ {Tags:["test_marker"]}
4
+ summon minecraft:marker ~ ~ ~ {Tags:["test_marker"]}
5
+ summon minecraft:marker ~ ~ ~ {Tags:["test_marker"]}
6
+ scoreboard players set $marker_count rs 0
7
+ execute as @e[type=minecraft:marker,tag=test_marker] run function test_control_flow:test_foreach_selector/foreach_0
8
+ scoreboard players set $_24 rs 0
9
+ execute if score $const_0 rs = $const_3 rs run scoreboard players set $_24 rs 1
10
+ execute if score $_24 rs matches 1.. run function test_control_flow:test_foreach_selector/then_0
11
+ execute if score $_24 rs matches ..0 run function test_control_flow:test_foreach_selector/else_1
@@ -0,0 +1,3 @@
1
+ # block: else_1
2
+ say [FAIL] if: x > 5 should be true
3
+ function test_control_flow:test_if_else/merge_2
@@ -0,0 +1,5 @@
1
+ # block: else_13
2
+ scoreboard players set $_5 rs 0
3
+ execute if score $y rs < $const_75 rs run scoreboard players set $_5 rs 1
4
+ execute if score $_5 rs matches 1.. run function test_control_flow:test_if_else/then_15
5
+ execute if score $_5 rs matches ..0 run function test_control_flow:test_if_else/else_16
@@ -0,0 +1,3 @@
1
+ # block: else_16
2
+ say [FAIL] else-if: should not reach final else
3
+ function test_control_flow:test_if_else/merge_17
@@ -0,0 +1,3 @@
1
+ # block: else_4
2
+ say [PASS] else: x < 5 correctly went to else
3
+ function test_control_flow:test_if_else/merge_5
@@ -0,0 +1,2 @@
1
+ # block: merge_11
2
+ function test_control_flow:test_if_else/merge_8
@@ -0,0 +1,2 @@
1
+ # block: merge_17
2
+ function test_control_flow:test_if_else/merge_14
@@ -0,0 +1,5 @@
1
+ # block: merge_2
2
+ scoreboard players set $_1 rs 0
3
+ execute if score $x rs < $const_5 rs run scoreboard players set $_1 rs 1
4
+ execute if score $_1 rs matches 1.. run function test_control_flow:test_if_else/then_3
5
+ execute if score $_1 rs matches ..0 run function test_control_flow:test_if_else/else_4
@@ -0,0 +1,5 @@
1
+ # block: merge_5
2
+ scoreboard players set $_2 rs 0
3
+ execute if score $x rs > $const_0 rs run scoreboard players set $_2 rs 1
4
+ execute if score $_2 rs matches 1.. run function test_control_flow:test_if_else/then_6
5
+ execute if score $_2 rs matches ..0 run function test_control_flow:test_if_else/merge_8
@@ -0,0 +1,6 @@
1
+ # block: merge_8
2
+ scoreboard players set $y rs 50
3
+ scoreboard players set $_4 rs 0
4
+ execute if score $const_50 rs < $const_25 rs run scoreboard players set $_4 rs 1
5
+ execute if score $_4 rs matches 1.. run function test_control_flow:test_if_else/then_12
6
+ execute if score $_4 rs matches ..0 run function test_control_flow:test_if_else/else_13
@@ -0,0 +1,3 @@
1
+ # block: then_0
2
+ say [PASS] if: x > 5 works
3
+ function test_control_flow:test_if_else/merge_2
@@ -0,0 +1,3 @@
1
+ # block: then_12
2
+ say [FAIL] else-if: y < 25 should be false
3
+ function test_control_flow:test_if_else/merge_14
@@ -0,0 +1,3 @@
1
+ # block: then_15
2
+ say [PASS] else-if: 25 <= y < 75
3
+ function test_control_flow:test_if_else/merge_17
@@ -0,0 +1,3 @@
1
+ # block: then_3
2
+ say [FAIL] else: x < 5 should be false
3
+ function test_control_flow:test_if_else/merge_5
@@ -0,0 +1,5 @@
1
+ # block: then_6
2
+ scoreboard players set $_3 rs 0
3
+ execute if score $x rs < $const_20 rs run scoreboard players set $_3 rs 1
4
+ execute if score $_3 rs matches 1.. run function test_control_flow:test_if_else/then_9
5
+ execute if score $_3 rs matches ..0 run function test_control_flow:test_if_else/merge_11
@@ -0,0 +1,3 @@
1
+ # block: then_9
2
+ say [PASS] nested if: 0 < x < 20
3
+ function test_control_flow:test_if_else/merge_11
@@ -0,0 +1,6 @@
1
+ # block: entry
2
+ scoreboard players set $x rs 10
3
+ scoreboard players set $_0 rs 0
4
+ execute if score $const_10 rs > $const_5 rs run scoreboard players set $_0 rs 1
5
+ execute if score $_0 rs matches 1.. run function test_control_flow:test_if_else/then_0
6
+ execute if score $_0 rs matches ..0 run function test_control_flow:test_if_else/else_1
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ scoreboard players set $_48 rs 1
3
+ say [FAIL] match: should not be 0
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ scoreboard players set $_48 rs 1
3
+ say [FAIL] match: should not be 1
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ scoreboard players set $_48 rs 1
3
+ say [PASS] match: correctly matched 2
@@ -0,0 +1,2 @@
1
+ # block: entry
2
+ say [FAIL] match: should not be default
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ scoreboard players set $_49 rs 1
3
+ say [FAIL] match range: should not be F
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ scoreboard players set $_49 rs 1
3
+ say [FAIL] match range: should not be D
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ scoreboard players set $_49 rs 1
3
+ say [PASS] match range: C (70-79)
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ scoreboard players set $_49 rs 1
3
+ say [FAIL] match range: should not be B
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ scoreboard players set $_49 rs 1
3
+ say [FAIL] match range: should not be A
@@ -0,0 +1,2 @@
1
+ # block: entry
2
+ say [FAIL] match range: out of range
@@ -0,0 +1,15 @@
1
+ # block: entry
2
+ scoreboard players set $status rs 2
3
+ scoreboard players set $_48 rs 0
4
+ execute if score $_48 rs matches ..0 if score $status rs matches 0 run function test_control_flow:test_match/match_0
5
+ execute if score $_48 rs matches ..0 if score $status rs matches 1 run function test_control_flow:test_match/match_1
6
+ execute if score $_48 rs matches ..0 if score $status rs matches 2 run function test_control_flow:test_match/match_2
7
+ execute if score $_48 rs matches ..0 run function test_control_flow:test_match/match_3
8
+ scoreboard players set $score rs 75
9
+ scoreboard players set $_49 rs 0
10
+ execute if score $_49 rs matches ..0 if score $score rs matches 0..59 run function test_control_flow:test_match/match_4
11
+ execute if score $_49 rs matches ..0 if score $score rs matches 60..69 run function test_control_flow:test_match/match_5
12
+ execute if score $_49 rs matches ..0 if score $score rs matches 70..79 run function test_control_flow:test_match/match_6
13
+ execute if score $_49 rs matches ..0 if score $score rs matches 80..89 run function test_control_flow:test_match/match_7
14
+ execute if score $_49 rs matches ..0 if score $score rs matches 90..100 run function test_control_flow:test_match/match_8
15
+ execute if score $_49 rs matches ..0 run function test_control_flow:test_match/match_9
@@ -0,0 +1,3 @@
1
+ # block: else_13
2
+ say [FAIL] while+break: expected 5
3
+ function test_control_flow:test_while_loop/merge_14
@@ -0,0 +1,3 @@
1
+ # block: else_4
2
+ say [FAIL] while loop: expected 3
3
+ function test_control_flow:test_while_loop/merge_5
@@ -0,0 +1,5 @@
1
+ # block: loop_body_1
2
+ scoreboard players operation $_17 rs = $count rs
3
+ scoreboard players operation $_17 rs += $const_1 rs
4
+ scoreboard players operation $count rs = $_17 rs
5
+ function test_control_flow:test_while_loop/loop_check_0
@@ -0,0 +1,8 @@
1
+ # block: loop_body_7
2
+ scoreboard players operation $_20 rs = $n rs
3
+ scoreboard players operation $_20 rs += $const_1 rs
4
+ scoreboard players operation $n rs = $_20 rs
5
+ scoreboard players set $_21 rs 0
6
+ execute if score $_20 rs >= $const_5 rs run scoreboard players set $_21 rs 1
7
+ execute if score $_21 rs matches 1.. run function test_control_flow:test_while_loop/then_9
8
+ execute if score $_21 rs matches ..0 run function test_control_flow:test_while_loop/merge_11
@@ -0,0 +1,5 @@
1
+ # block: loop_check_0
2
+ scoreboard players set $_16 rs 0
3
+ execute if score $count rs < $const_3 rs run scoreboard players set $_16 rs 1
4
+ execute if score $_16 rs matches 1.. run function test_control_flow:test_while_loop/loop_body_1
5
+ execute if score $_16 rs matches ..0 run function test_control_flow:test_while_loop/loop_exit_2
@@ -0,0 +1,4 @@
1
+ # block: loop_check_6
2
+ scoreboard players set $_19 rs 1
3
+ execute if score $_19 rs matches 1.. run function test_control_flow:test_while_loop/loop_body_7
4
+ execute if score $_19 rs matches ..0 run function test_control_flow:test_while_loop/loop_exit_8
@@ -0,0 +1,5 @@
1
+ # block: loop_exit_2
2
+ scoreboard players set $_18 rs 0
3
+ execute if score $count rs = $const_3 rs run scoreboard players set $_18 rs 1
4
+ execute if score $_18 rs matches 1.. run function test_control_flow:test_while_loop/then_3
5
+ execute if score $_18 rs matches ..0 run function test_control_flow:test_while_loop/else_4
@@ -0,0 +1,5 @@
1
+ # block: loop_exit_8
2
+ scoreboard players set $_22 rs 0
3
+ execute if score $n rs = $const_5 rs run scoreboard players set $_22 rs 1
4
+ execute if score $_22 rs matches 1.. run function test_control_flow:test_while_loop/then_12
5
+ execute if score $_22 rs matches ..0 run function test_control_flow:test_while_loop/else_13
@@ -0,0 +1,2 @@
1
+ # block: merge_11
2
+ function test_control_flow:test_while_loop/loop_check_6
@@ -0,0 +1,3 @@
1
+ # block: merge_5
2
+ scoreboard players set $n rs 0
3
+ function test_control_flow:test_while_loop/loop_check_6
@@ -0,0 +1,3 @@
1
+ # block: then_12
2
+ say [PASS] while+break: n = 5
3
+ function test_control_flow:test_while_loop/merge_14
@@ -0,0 +1,3 @@
1
+ # block: then_3
2
+ say [PASS] while loop: count = 3
3
+ function test_control_flow:test_while_loop/merge_5
@@ -0,0 +1,2 @@
1
+ # block: then_9
2
+ function test_control_flow:test_while_loop/loop_exit_8
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ scoreboard players set $count rs 0
3
+ function test_control_flow:test_while_loop/loop_check_0
@@ -0,0 +1,6 @@
1
+ {
2
+ "pack": {
3
+ "pack_format": 26,
4
+ "description": "test_control_flow datapack — compiled by redscript"
5
+ }
6
+ }
@@ -0,0 +1,242 @@
1
+ // ===== Control Flow Tests =====
2
+ // 测试: if/else, for, foreach, while, match, break, continue
3
+
4
+ let test_counter: int = 0;
5
+
6
+ // === Test 1: if/else 基础 ===
7
+ @keep fn test_if_else() {
8
+ let x: int = 10;
9
+
10
+ if (x > 5) {
11
+ raw("say [PASS] if: x > 5 works");
12
+ } else {
13
+ raw("say [FAIL] if: x > 5 should be true");
14
+ }
15
+
16
+ if (x < 5) {
17
+ raw("say [FAIL] else: x < 5 should be false");
18
+ } else {
19
+ raw("say [PASS] else: x < 5 correctly went to else");
20
+ }
21
+
22
+ // Nested if
23
+ if (x > 0) {
24
+ if (x < 20) {
25
+ raw("say [PASS] nested if: 0 < x < 20");
26
+ }
27
+ }
28
+
29
+ // else if chain
30
+ let y: int = 50;
31
+ if (y < 25) {
32
+ raw("say [FAIL] else-if: y < 25 should be false");
33
+ } else if (y < 75) {
34
+ raw("say [PASS] else-if: 25 <= y < 75");
35
+ } else {
36
+ raw("say [FAIL] else-if: should not reach final else");
37
+ }
38
+ }
39
+
40
+ // === Test 2: for loop 基础 ===
41
+ @keep fn test_for_loop() {
42
+ let sum: int = 0;
43
+
44
+ for (let i: int = 1; i <= 5; i = i + 1) {
45
+ sum = sum + i;
46
+ }
47
+
48
+ if (sum == 15) {
49
+ raw("say [PASS] for loop: sum 1..5 = 15");
50
+ } else {
51
+ raw("say [FAIL] for loop: expected 15");
52
+ }
53
+
54
+ // Nested for
55
+ let product: int = 0;
56
+ for (let a: int = 1; a <= 2; a = a + 1) {
57
+ for (let b: int = 1; b <= 3; b = b + 1) {
58
+ product = product + 1;
59
+ }
60
+ }
61
+
62
+ if (product == 6) {
63
+ raw("say [PASS] nested for: 2*3 iterations = 6");
64
+ } else {
65
+ raw("say [FAIL] nested for: expected 6");
66
+ }
67
+ }
68
+
69
+ // === Test 3: while loop ===
70
+ @keep fn test_while_loop() {
71
+ let count: int = 0;
72
+
73
+ while (count < 3) {
74
+ count = count + 1;
75
+ }
76
+
77
+ if (count == 3) {
78
+ raw("say [PASS] while loop: count = 3");
79
+ } else {
80
+ raw("say [FAIL] while loop: expected 3");
81
+ }
82
+
83
+ // While with break condition
84
+ let n: int = 0;
85
+ while (true) {
86
+ n = n + 1;
87
+ if (n >= 5) {
88
+ break;
89
+ }
90
+ }
91
+
92
+ if (n == 5) {
93
+ raw("say [PASS] while+break: n = 5");
94
+ } else {
95
+ raw("say [FAIL] while+break: expected 5");
96
+ }
97
+ }
98
+
99
+ // === Test 4: foreach with selector ===
100
+ @keep fn test_foreach_selector() {
101
+ raw("say [INFO] foreach selector test - spawning markers");
102
+ raw("summon minecraft:marker ~ ~ ~ {Tags:[\"test_marker\"]}");
103
+ raw("summon minecraft:marker ~ ~ ~ {Tags:[\"test_marker\"]}");
104
+ raw("summon minecraft:marker ~ ~ ~ {Tags:[\"test_marker\"]}");
105
+
106
+ let marker_count: int = 0;
107
+ foreach (m in @e[type=marker,tag=test_marker]) {
108
+ marker_count = marker_count + 1;
109
+ }
110
+
111
+ if (marker_count == 3) {
112
+ raw("say [PASS] foreach selector: found 3 markers");
113
+ } else {
114
+ raw("say [INFO] foreach selector: found markers (count varies)");
115
+ }
116
+
117
+ // Cleanup
118
+ raw("kill @e[type=marker,tag=test_marker]");
119
+ }
120
+
121
+ // === Test 5: foreach with at @s ===
122
+ @keep fn test_foreach_at() {
123
+ raw("summon minecraft:marker ~ ~1 ~ {Tags:[\"pos_test\"]}");
124
+
125
+ foreach (e in @e[type=marker,tag=pos_test]) at @s {
126
+ raw("particle minecraft:heart ~ ~ ~ 0 0 0 0 1");
127
+ }
128
+ raw("say [PASS] foreach at @s: executed at entity position");
129
+
130
+ raw("kill @e[type=marker,tag=pos_test]");
131
+ }
132
+
133
+ // === Test 6: break statement ===
134
+ @keep fn test_break() {
135
+ let found: int = 0;
136
+
137
+ for (let i: int = 0; i < 10; i = i + 1) {
138
+ if (i == 5) {
139
+ found = i;
140
+ break;
141
+ }
142
+ }
143
+
144
+ if (found == 5) {
145
+ raw("say [PASS] break: exited at i=5");
146
+ } else {
147
+ raw("say [FAIL] break: expected 5");
148
+ }
149
+ }
150
+
151
+ // === Test 7: continue statement ===
152
+ @keep fn test_continue() {
153
+ let sum: int = 0;
154
+
155
+ // Sum only even numbers 0-9
156
+ for (let i: int = 0; i < 10; i = i + 1) {
157
+ if (i % 2 != 0) {
158
+ continue;
159
+ }
160
+ sum = sum + i;
161
+ }
162
+
163
+ // 0+2+4+6+8 = 20
164
+ if (sum == 20) {
165
+ raw("say [PASS] continue: sum of evens = 20");
166
+ } else {
167
+ raw("say [FAIL] continue: expected 20");
168
+ }
169
+ }
170
+
171
+ // === Test 8: 复杂条件 ===
172
+ @keep fn test_complex_conditions() {
173
+ let a: int = 5;
174
+ let b: int = 10;
175
+ let c: int = 15;
176
+
177
+ // AND condition
178
+ if (a < b && b < c) {
179
+ raw("say [PASS] AND: a < b && b < c");
180
+ } else {
181
+ raw("say [FAIL] AND: should be true");
182
+ }
183
+
184
+ // OR condition
185
+ if (a > 100 || b == 10) {
186
+ raw("say [PASS] OR: a > 100 || b == 10");
187
+ } else {
188
+ raw("say [FAIL] OR: should be true");
189
+ }
190
+
191
+ // NOT condition
192
+ if (!(a > b)) {
193
+ raw("say [PASS] NOT: !(a > b)");
194
+ } else {
195
+ raw("say [FAIL] NOT: should be true");
196
+ }
197
+
198
+ // Complex nested
199
+ if ((a < b && b < c) || (a > c)) {
200
+ raw("say [PASS] complex: (a<b && b<c) || (a>c)");
201
+ } else {
202
+ raw("say [FAIL] complex: should be true");
203
+ }
204
+ }
205
+
206
+ // === Test 9: match statement ===
207
+ @keep fn test_match() {
208
+ let status: int = 2;
209
+
210
+ match (status) {
211
+ 0 => { raw("say [FAIL] match: should not be 0"); }
212
+ 1 => { raw("say [FAIL] match: should not be 1"); }
213
+ 2 => { raw("say [PASS] match: correctly matched 2"); }
214
+ _ => { raw("say [FAIL] match: should not be default"); }
215
+ }
216
+
217
+ // Match with range
218
+ let score: int = 75;
219
+ match (score) {
220
+ 0..59 => { raw("say [FAIL] match range: should not be F"); }
221
+ 60..69 => { raw("say [FAIL] match range: should not be D"); }
222
+ 70..79 => { raw("say [PASS] match range: C (70-79)"); }
223
+ 80..89 => { raw("say [FAIL] match range: should not be B"); }
224
+ 90..100 => { raw("say [FAIL] match range: should not be A"); }
225
+ _ => { raw("say [FAIL] match range: out of range"); }
226
+ }
227
+ }
228
+
229
+ // === Run all tests ===
230
+ @keep fn run_control_flow_tests() {
231
+ raw("say === Control Flow Tests ===");
232
+ test_if_else();
233
+ test_for_loop();
234
+ test_while_loop();
235
+ test_foreach_selector();
236
+ test_foreach_at();
237
+ test_break();
238
+ test_continue();
239
+ test_complex_conditions();
240
+ test_match();
241
+ raw("say === Tests Complete ===");
242
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "values": [
3
+ "test_decorators:__load"
4
+ ]
5
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "values": [
3
+ "test_decorators:__tick"
4
+ ]
5
+ }
@@ -0,0 +1,20 @@
1
+ # RedScript runtime init
2
+ scoreboard objectives add rs dummy
3
+ scoreboard players set $tick_counter rs 0
4
+ scoreboard players set $tick_test_running rs 0
5
+ scoreboard players set $slow_tick_count rs 0
6
+ scoreboard players set $slow_tick_running rs 0
7
+ scoreboard players set $__tick_every_second rs 0
8
+ scoreboard players set $const_0 rs 0
9
+ scoreboard players set $const_1 rs 1
10
+ scoreboard players set $const_20 rs 20
11
+ scoreboard players set $const_100 rs 100
12
+ scoreboard players set $const_0 rs 0
13
+ scoreboard players set $const_1 rs 1
14
+ scoreboard players set $const_0 rs 0
15
+ scoreboard players set $const_1 rs 1
16
+ scoreboard players set $const_5 rs 5
17
+ scoreboard players set $const_0 rs 0
18
+ scoreboard players set $const_0 rs 0
19
+ scoreboard players set $const_1 rs 1
20
+ function test_decorators:on_load
@@ -0,0 +1,3 @@
1
+ # RedScript tick dispatcher
2
+ function test_decorators:on_tick
3
+ function test_decorators:every_second
@@ -0,0 +1,9 @@
1
+ # block: merge_2
2
+ scoreboard players operation $_6 rs = $slow_tick_count rs
3
+ scoreboard players operation $_6 rs += $const_1 rs
4
+ scoreboard players operation $slow_tick_count rs = $_6 rs
5
+ tellraw @a ["",{"text":"[INFO] @tick(rate=20): second #"},{"score":{"name":"$slow_tick_count","objective":"rs"}}]
6
+ scoreboard players set $_7 rs 0
7
+ execute if score $_6 rs >= $const_5 rs run scoreboard players set $_7 rs 1
8
+ execute if score $_7 rs matches 1.. run function test_decorators:every_second/then_3
9
+ execute if score $_7 rs matches ..0 run function test_decorators:every_second/merge_5
@@ -0,0 +1,4 @@
1
+ # block: then_3
2
+ scoreboard players set $slow_tick_running rs 0
3
+ say [PASS] @tick(rate=20): completed 5 seconds
4
+ function test_decorators:every_second/merge_5
@@ -0,0 +1,6 @@
1
+ # block: tick_body
2
+ scoreboard players set $__tick_every_second rs 0
3
+ scoreboard players set $_5 rs 0
4
+ execute if score $slow_tick_running rs = $const_0 rs run scoreboard players set $_5 rs 1
5
+ execute if score $_5 rs matches 1.. run function test_decorators:every_second/then_0
6
+ execute if score $_5 rs matches ..0 run function test_decorators:every_second/merge_2
@@ -0,0 +1,5 @@
1
+ # block: entry
2
+ scoreboard players add $__tick_every_second rs 1
3
+ execute store success score $__tick_every_second_check rs if score $__tick_every_second rs matches 20..
4
+ execute if score $__tick_every_second_check rs matches 1.. run function test_decorators:every_second/tick_body
5
+ execute if score $__tick_every_second_check rs matches ..0 run function test_decorators:every_second/tick_skip