redscript-mc 1.2.8 → 1.2.10

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 (210) hide show
  1. package/README.md +35 -33
  2. package/README.zh.md +35 -33
  3. package/demo.gif +0 -0
  4. package/dist/ast/types.d.ts +6 -0
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/lexer/index.d.ts +1 -1
  8. package/dist/lexer/index.js +2 -0
  9. package/dist/lowering/index.d.ts +3 -0
  10. package/dist/lowering/index.js +60 -7
  11. package/dist/optimizer/dce.js +6 -0
  12. package/dist/parser/index.js +12 -0
  13. package/package.json +1 -1
  14. package/src/ast/types.ts +2 -0
  15. package/src/index.ts +1 -1
  16. package/src/lexer/index.ts +3 -1
  17. package/src/lowering/index.ts +64 -7
  18. package/src/optimizer/dce.ts +6 -0
  19. package/src/parser/index.ts +14 -0
  20. package/test-datapacks/README.md +67 -0
  21. package/test-datapacks/test_control_flow/data/minecraft/tags/function/load.json +5 -0
  22. package/test-datapacks/test_control_flow/data/test_control_flow/function/__load.mcfunction +41 -0
  23. package/test-datapacks/test_control_flow/data/test_control_flow/function/run_control_flow_tests.mcfunction +21 -0
  24. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/else_7.mcfunction +3 -0
  25. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/else_8.mcfunction +3 -0
  26. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/for_body_1.mcfunction +5 -0
  27. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/for_check_0.mcfunction +5 -0
  28. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/for_continue_2.mcfunction +5 -0
  29. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/for_exit_2.mcfunction +5 -0
  30. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/for_exit_3.mcfunction +5 -0
  31. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/merge_5.mcfunction +5 -0
  32. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/merge_6.mcfunction +2 -0
  33. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/merge_8.mcfunction +1 -0
  34. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/merge_9.mcfunction +1 -0
  35. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/then_3.mcfunction +3 -0
  36. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/then_4.mcfunction +3 -0
  37. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/then_6.mcfunction +3 -0
  38. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break/then_7.mcfunction +3 -0
  39. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_break.mcfunction +4 -0
  40. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/else_1.mcfunction +3 -0
  41. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/else_10.mcfunction +3 -0
  42. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/else_4.mcfunction +3 -0
  43. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/else_7.mcfunction +3 -0
  44. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/merge_11.mcfunction +1 -0
  45. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/merge_2.mcfunction +9 -0
  46. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/merge_5.mcfunction +7 -0
  47. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/merge_8.mcfunction +13 -0
  48. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/then_0.mcfunction +3 -0
  49. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/then_3.mcfunction +3 -0
  50. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/then_6.mcfunction +3 -0
  51. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions/then_9.mcfunction +3 -0
  52. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_complex_conditions.mcfunction +12 -0
  53. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/else_7.mcfunction +3 -0
  54. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/else_8.mcfunction +3 -0
  55. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/for_body_1.mcfunction +7 -0
  56. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/for_check_0.mcfunction +5 -0
  57. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/for_continue_2.mcfunction +5 -0
  58. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/for_exit_2.mcfunction +5 -0
  59. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/for_exit_3.mcfunction +5 -0
  60. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/merge_5.mcfunction +8 -0
  61. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/merge_6.mcfunction +5 -0
  62. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/merge_8.mcfunction +1 -0
  63. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/merge_9.mcfunction +1 -0
  64. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/then_3.mcfunction +2 -0
  65. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/then_4.mcfunction +2 -0
  66. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/then_6.mcfunction +3 -0
  67. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue/then_7.mcfunction +3 -0
  68. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_continue.mcfunction +4 -0
  69. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/else_13.mcfunction +3 -0
  70. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/else_16.mcfunction +3 -0
  71. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/else_4.mcfunction +3 -0
  72. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/else_5.mcfunction +3 -0
  73. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_body_1.mcfunction +5 -0
  74. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_body_10.mcfunction +8 -0
  75. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_body_12.mcfunction +5 -0
  76. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_body_7.mcfunction +3 -0
  77. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_body_8.mcfunction +3 -0
  78. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_check_0.mcfunction +5 -0
  79. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_check_11.mcfunction +5 -0
  80. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_check_6.mcfunction +5 -0
  81. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_check_7.mcfunction +5 -0
  82. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_check_9.mcfunction +5 -0
  83. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_continue_13.mcfunction +5 -0
  84. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_continue_2.mcfunction +5 -0
  85. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_continue_9.mcfunction +5 -0
  86. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_10.mcfunction +5 -0
  87. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_11.mcfunction +5 -0
  88. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_14.mcfunction +2 -0
  89. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_2.mcfunction +5 -0
  90. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_3.mcfunction +5 -0
  91. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/for_exit_8.mcfunction +5 -0
  92. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/merge_14.mcfunction +1 -0
  93. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/merge_17.mcfunction +1 -0
  94. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/merge_5.mcfunction +4 -0
  95. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/merge_6.mcfunction +4 -0
  96. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/then_12.mcfunction +3 -0
  97. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/then_15.mcfunction +3 -0
  98. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/then_3.mcfunction +3 -0
  99. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop/then_4.mcfunction +3 -0
  100. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_for_loop.mcfunction +4 -0
  101. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_at/foreach_0.mcfunction +2 -0
  102. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_at.mcfunction +5 -0
  103. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_selector/else_1.mcfunction +3 -0
  104. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_selector/foreach_0.mcfunction +4 -0
  105. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_selector/merge_2.mcfunction +2 -0
  106. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_selector/then_0.mcfunction +3 -0
  107. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_foreach_selector.mcfunction +11 -0
  108. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/else_1.mcfunction +3 -0
  109. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/else_13.mcfunction +5 -0
  110. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/else_16.mcfunction +3 -0
  111. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/else_4.mcfunction +3 -0
  112. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_11.mcfunction +2 -0
  113. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_14.mcfunction +1 -0
  114. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_17.mcfunction +2 -0
  115. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_2.mcfunction +5 -0
  116. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_5.mcfunction +5 -0
  117. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/merge_8.mcfunction +6 -0
  118. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_0.mcfunction +3 -0
  119. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_12.mcfunction +3 -0
  120. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_15.mcfunction +3 -0
  121. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_3.mcfunction +3 -0
  122. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_6.mcfunction +5 -0
  123. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else/then_9.mcfunction +3 -0
  124. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_if_else.mcfunction +6 -0
  125. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_0.mcfunction +3 -0
  126. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_1.mcfunction +3 -0
  127. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_2.mcfunction +3 -0
  128. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_3.mcfunction +2 -0
  129. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_4.mcfunction +3 -0
  130. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_5.mcfunction +3 -0
  131. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_6.mcfunction +3 -0
  132. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_7.mcfunction +3 -0
  133. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_8.mcfunction +3 -0
  134. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match/match_9.mcfunction +2 -0
  135. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_match.mcfunction +15 -0
  136. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/else_13.mcfunction +3 -0
  137. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/else_4.mcfunction +3 -0
  138. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_body_1.mcfunction +5 -0
  139. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_body_7.mcfunction +8 -0
  140. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_check_0.mcfunction +5 -0
  141. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_check_6.mcfunction +4 -0
  142. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_exit_2.mcfunction +5 -0
  143. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/loop_exit_8.mcfunction +5 -0
  144. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/merge_11.mcfunction +2 -0
  145. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/merge_14.mcfunction +1 -0
  146. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/merge_5.mcfunction +3 -0
  147. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/then_12.mcfunction +3 -0
  148. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/then_3.mcfunction +3 -0
  149. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop/then_9.mcfunction +2 -0
  150. package/test-datapacks/test_control_flow/data/test_control_flow/function/test_while_loop.mcfunction +3 -0
  151. package/test-datapacks/test_control_flow/pack.mcmeta +6 -0
  152. package/test-datapacks/test_control_flow.mcrs +242 -0
  153. package/test-datapacks/test_decorators/data/minecraft/tags/function/load.json +5 -0
  154. package/test-datapacks/test_decorators/data/minecraft/tags/function/tick.json +5 -0
  155. package/test-datapacks/test_decorators/data/test_decorators/function/__load.mcfunction +20 -0
  156. package/test-datapacks/test_decorators/data/test_decorators/function/__tick.mcfunction +3 -0
  157. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/merge_2.mcfunction +9 -0
  158. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/merge_5.mcfunction +1 -0
  159. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/then_0.mcfunction +1 -0
  160. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/then_3.mcfunction +4 -0
  161. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/tick_body.mcfunction +6 -0
  162. package/test-datapacks/test_decorators/data/test_decorators/function/every_second/tick_skip.mcfunction +1 -0
  163. package/test-datapacks/test_decorators/data/test_decorators/function/every_second.mcfunction +5 -0
  164. package/test-datapacks/test_decorators/data/test_decorators/function/on_load.mcfunction +2 -0
  165. package/test-datapacks/test_decorators/data/test_decorators/function/on_test_trigger.mcfunction +2 -0
  166. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/merge_2.mcfunction +10 -0
  167. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/merge_5.mcfunction +5 -0
  168. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/merge_8.mcfunction +1 -0
  169. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/then_0.mcfunction +1 -0
  170. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/then_3.mcfunction +3 -0
  171. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick/then_6.mcfunction +4 -0
  172. package/test-datapacks/test_decorators/data/test_decorators/function/on_tick.mcfunction +5 -0
  173. package/test-datapacks/test_decorators/data/test_decorators/function/run_decorator_tests.mcfunction +7 -0
  174. package/test-datapacks/test_decorators/data/test_decorators/function/setup_trigger_test.mcfunction +4 -0
  175. package/test-datapacks/test_decorators/data/test_decorators/function/start_slow_tick_test.mcfunction +4 -0
  176. package/test-datapacks/test_decorators/data/test_decorators/function/start_tick_test.mcfunction +4 -0
  177. package/test-datapacks/test_decorators/data/test_decorators/function/stop_tick_test.mcfunction +3 -0
  178. package/test-datapacks/test_decorators/pack.mcmeta +6 -0
  179. package/test-datapacks/test_decorators.mcrs +81 -0
  180. package/test-datapacks/test_events/data/minecraft/tags/function/load.json +5 -0
  181. package/test-datapacks/test_events/data/test_events/advancements/on_death_on_player_death.json +10 -0
  182. package/test-datapacks/test_events/data/test_events/function/__load.mcfunction +3 -0
  183. package/test-datapacks/test_events/data/test_events/function/on_player_death.mcfunction +3 -0
  184. package/test-datapacks/test_events/data/test_events/function/run_event_tests.mcfunction +5 -0
  185. package/test-datapacks/test_events/data/test_events/function/setup_events.mcfunction +3 -0
  186. package/test-datapacks/test_events/data/test_events/function/spawn_test_entity.mcfunction +3 -0
  187. package/test-datapacks/test_events/data/test_events/function/test_advancement_event.mcfunction +4 -0
  188. package/test-datapacks/test_events/pack.mcmeta +6 -0
  189. package/test-datapacks/test_events.mcrs +37 -0
  190. package/test-datapacks/test_fstrings/data/minecraft/tags/function/load.json +5 -0
  191. package/test-datapacks/test_fstrings/data/test_fstrings/function/__load.mcfunction +10 -0
  192. package/test-datapacks/test_fstrings/data/test_fstrings/function/run_fstring_tests.mcfunction +15 -0
  193. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_actionbar_fstring.mcfunction +4 -0
  194. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_announce.mcfunction +3 -0
  195. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_multi_var_fstring.mcfunction +9 -0
  196. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_say_fstring.mcfunction +4 -0
  197. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_tell.mcfunction +3 -0
  198. package/test-datapacks/test_fstrings/data/test_fstrings/function/test_title_fstring.mcfunction +4 -0
  199. package/test-datapacks/test_fstrings/pack.mcmeta +6 -0
  200. package/test-datapacks/test_fstrings.mcrs +58 -0
  201. package/test-datapacks/test_timers/data/minecraft/tags/function/load.json +5 -0
  202. package/test-datapacks/test_timers/data/test_timers/function/__interval_0.mcfunction +3 -0
  203. package/test-datapacks/test_timers/data/test_timers/function/__interval_body_0.mcfunction +5 -0
  204. package/test-datapacks/test_timers/data/test_timers/function/__load.mcfunction +5 -0
  205. package/test-datapacks/test_timers/data/test_timers/function/__timeout_0.mcfunction +2 -0
  206. package/test-datapacks/test_timers/data/test_timers/function/run_timer_tests.mcfunction +5 -0
  207. package/test-datapacks/test_timers/data/test_timers/function/test_set_interval.mcfunction +5 -0
  208. package/test-datapacks/test_timers/data/test_timers/function/test_set_timeout.mcfunction +3 -0
  209. package/test-datapacks/test_timers/pack.mcmeta +6 -0
  210. package/test-datapacks/test_timers.mcrs +35 -0
@@ -0,0 +1,2 @@
1
+ # block: entry
2
+ say [PASS] @load: fired on datapack load/reload
@@ -0,0 +1,2 @@
1
+ # block: entry
2
+ say [PASS] @on_trigger: triggered by scoreboard!
@@ -0,0 +1,10 @@
1
+ # block: merge_2
2
+ scoreboard players operation $_1 rs = $tick_counter rs
3
+ scoreboard players operation $_1 rs += $const_1 rs
4
+ scoreboard players operation $tick_counter rs = $_1 rs
5
+ scoreboard players operation $_2 rs = $_1 rs
6
+ scoreboard players operation $_2 rs %= $const_20 rs
7
+ scoreboard players set $_3 rs 0
8
+ execute if score $_2 rs = $const_0 rs run scoreboard players set $_3 rs 1
9
+ execute if score $_3 rs matches 1.. run function test_decorators:on_tick/then_3
10
+ execute if score $_3 rs matches ..0 run function test_decorators:on_tick/merge_5
@@ -0,0 +1,5 @@
1
+ # block: merge_5
2
+ scoreboard players set $_4 rs 0
3
+ execute if score $tick_counter rs >= $const_100 rs run scoreboard players set $_4 rs 1
4
+ execute if score $_4 rs matches 1.. run function test_decorators:on_tick/then_6
5
+ execute if score $_4 rs matches ..0 run function test_decorators:on_tick/merge_8
@@ -0,0 +1,3 @@
1
+ # block: then_3
2
+ tellraw @a ["",{"text":"[INFO] @tick: "},{"score":{"name":"$tick_counter","objective":"rs"}},{"text":" ticks elapsed"}]
3
+ function test_decorators:on_tick/merge_5
@@ -0,0 +1,4 @@
1
+ # block: then_6
2
+ scoreboard players set $tick_test_running rs 0
3
+ say [PASS] @tick: completed 100 ticks (5 seconds)
4
+ function test_decorators:on_tick/merge_8
@@ -0,0 +1,5 @@
1
+ # block: entry
2
+ scoreboard players set $_0 rs 0
3
+ execute if score $tick_test_running rs = $const_0 rs run scoreboard players set $_0 rs 1
4
+ execute if score $_0 rs matches 1.. run function test_decorators:on_tick/then_0
5
+ execute if score $_0 rs matches ..0 run function test_decorators:on_tick/merge_2
@@ -0,0 +1,7 @@
1
+ # block: entry
2
+ say === Decorator Tests ===
3
+ say [INFO] @load already fired on reload
4
+ say [INFO] Run tests:
5
+ say /function test_decorators:start_tick_test
6
+ say /function test_decorators:start_slow_tick_test
7
+ say /function test_decorators:setup_trigger_test
@@ -0,0 +1,4 @@
1
+ # block: entry
2
+ scoreboard objectives add test_trigger trigger
3
+ say [INFO] Trigger test setup. Run:
4
+ say /trigger test_trigger
@@ -0,0 +1,4 @@
1
+ # block: entry
2
+ scoreboard players set $slow_tick_count rs 0
3
+ scoreboard players set $slow_tick_running rs 1
4
+ say [INFO] @tick(rate=20) test started...
@@ -0,0 +1,4 @@
1
+ # block: entry
2
+ scoreboard players set $tick_counter rs 0
3
+ scoreboard players set $tick_test_running rs 1
4
+ say [INFO] @tick test started, will run for 5 seconds...
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ scoreboard players set $tick_test_running rs 0
3
+ tellraw @a ["",{"text":"[INFO] @tick test stopped at "},{"score":{"name":"$tick_counter","objective":"rs"}},{"text":" ticks"}]
@@ -0,0 +1,6 @@
1
+ {
2
+ "pack": {
3
+ "pack_format": 26,
4
+ "description": "test_decorators datapack — compiled by redscript"
5
+ }
6
+ }
@@ -0,0 +1,81 @@
1
+ // ===== Decorator Tests =====
2
+ // 测试: @tick, @load, @on_trigger, @keep
3
+
4
+ let tick_counter: int = 0;
5
+ let tick_test_running: bool = false;
6
+
7
+ // === Test 1: @load ===
8
+ @load fn on_load() {
9
+ say("[PASS] @load: fired on datapack load/reload");
10
+ }
11
+
12
+ // === Test 2: @tick ===
13
+ @tick fn on_tick() {
14
+ if (!tick_test_running) { return; }
15
+
16
+ tick_counter = tick_counter + 1;
17
+
18
+ if (tick_counter % 20 == 0) {
19
+ say(f"[INFO] @tick: {tick_counter} ticks elapsed");
20
+ }
21
+
22
+ if (tick_counter >= 100) {
23
+ tick_test_running = false;
24
+ say("[PASS] @tick: completed 100 ticks (5 seconds)");
25
+ }
26
+ }
27
+
28
+ @keep fn start_tick_test() {
29
+ tick_counter = 0;
30
+ tick_test_running = true;
31
+ say("[INFO] @tick test started, will run for 5 seconds...");
32
+ }
33
+
34
+ @keep fn stop_tick_test() {
35
+ tick_test_running = false;
36
+ say(f"[INFO] @tick test stopped at {tick_counter} ticks");
37
+ }
38
+
39
+ // === Test 3: @tick with rate ===
40
+ let slow_tick_count: int = 0;
41
+ let slow_tick_running: bool = false;
42
+
43
+ @tick(rate=20) fn every_second() {
44
+ if (!slow_tick_running) { return; }
45
+
46
+ slow_tick_count = slow_tick_count + 1;
47
+ say(f"[INFO] @tick(rate=20): second #{slow_tick_count}");
48
+
49
+ if (slow_tick_count >= 5) {
50
+ slow_tick_running = false;
51
+ say("[PASS] @tick(rate=20): completed 5 seconds");
52
+ }
53
+ }
54
+
55
+ @keep fn start_slow_tick_test() {
56
+ slow_tick_count = 0;
57
+ slow_tick_running = true;
58
+ say("[INFO] @tick(rate=20) test started...");
59
+ }
60
+
61
+ // === Test 4: @on_trigger ===
62
+ @on_trigger(#test_trigger)
63
+ fn on_test_trigger() {
64
+ say("[PASS] @on_trigger: triggered by scoreboard!");
65
+ }
66
+
67
+ @keep fn setup_trigger_test() {
68
+ raw("scoreboard objectives add test_trigger trigger");
69
+ say("[INFO] Trigger test setup. Run:");
70
+ say(" /trigger test_trigger");
71
+ }
72
+
73
+ // === Run info ===
74
+ @keep fn run_decorator_tests() {
75
+ say("=== Decorator Tests ===");
76
+ say("[INFO] @load already fired on reload");
77
+ say("[INFO] Run tests:");
78
+ say(" /function test_decorators:start_tick_test");
79
+ say(" /function test_decorators:start_slow_tick_test");
80
+ say(" /function test_decorators:setup_trigger_test");
81
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "values": [
3
+ "test_events:__load"
4
+ ]
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "criteria": {
3
+ "death": {
4
+ "trigger": "minecraft:entity_killed_player"
5
+ }
6
+ },
7
+ "rewards": {
8
+ "function": "test_events:on_player_death"
9
+ }
10
+ }
@@ -0,0 +1,3 @@
1
+ # RedScript runtime init
2
+ scoreboard objectives add rs dummy
3
+ function test_events:setup_events
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ tellraw @a ["",{"text":"[PASS] @on_death: player died!"}]
3
+ title @s title {"text":"You Died!"}
@@ -0,0 +1,5 @@
1
+ # block: entry
2
+ say === Event Tests ===
3
+ say [INFO] Events are triggered by game actions:
4
+ say @on_death: die to test (use /kill in survival)
5
+ say spawn_test_entity: spawns a pig to kill
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ say [INFO] Event tests loaded
3
+ say [INFO] Test @on_death by dying (creative -> survival, /kill)
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ summon minecraft:pig ~ ~ ~ {Tags:["test_pig"]}
3
+ say [INFO] Spawned test pig. Kill it to test entity death.
@@ -0,0 +1,4 @@
1
+ # block: entry
2
+ say [INFO] Granting test advancement...
3
+ advancement grant @s only minecraft:story/mine_stone
4
+ say [PASS] Advancement granted - check if event fired
@@ -0,0 +1,6 @@
1
+ {
2
+ "pack": {
3
+ "pack_format": 26,
4
+ "description": "test_events datapack — compiled by redscript"
5
+ }
6
+ }
@@ -0,0 +1,37 @@
1
+ // ===== Event Tests =====
2
+ // 测试: @on_death, @on_login, @on(Event)
3
+
4
+ // === Test 1: @on_death ===
5
+ @on_death fn on_player_death() {
6
+ say(f"[PASS] @on_death: player died!");
7
+ // Give respawn message
8
+ title(@s, "You Died!", "Testing @on_death");
9
+ }
10
+
11
+ // === Test 2: @on_login (if supported) ===
12
+ // Note: This may need advancement-based implementation
13
+ @load fn setup_events() {
14
+ say("[INFO] Event tests loaded");
15
+ say("[INFO] Test @on_death by dying (creative -> survival, /kill)");
16
+ }
17
+
18
+ // === Test 3: Manual advancement trigger test ===
19
+ @keep fn test_advancement_event() {
20
+ say("[INFO] Granting test advancement...");
21
+ raw("advancement grant @s only minecraft:story/mine_stone");
22
+ say("[PASS] Advancement granted - check if event fired");
23
+ }
24
+
25
+ // === Test 4: Entity death event ===
26
+ @keep fn spawn_test_entity() {
27
+ raw("summon minecraft:pig ~ ~ ~ {Tags:[\"test_pig\"]}");
28
+ say("[INFO] Spawned test pig. Kill it to test entity death.");
29
+ }
30
+
31
+ // === Info ===
32
+ @keep fn run_event_tests() {
33
+ say("=== Event Tests ===");
34
+ say("[INFO] Events are triggered by game actions:");
35
+ say(" @on_death: die to test (use /kill in survival)");
36
+ say(" spawn_test_entity: spawns a pig to kill");
37
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "values": [
3
+ "test_fstrings:__load"
4
+ ]
5
+ }
@@ -0,0 +1,10 @@
1
+ # RedScript runtime init
2
+ scoreboard objectives add rs dummy
3
+ scoreboard players set $score rs 42
4
+ scoreboard players set $name_test rs 100
5
+ scoreboard players set $const_123 rs 123
6
+ scoreboard players set $const_5 rs 5
7
+ scoreboard players set $const_20 rs 20
8
+ scoreboard players set $const_1 rs 1
9
+ scoreboard players set $const_2 rs 2
10
+ scoreboard players set $const_3 rs 3
@@ -0,0 +1,15 @@
1
+ # block: entry
2
+ say === F-String & Output Tests ===
3
+ function test_fstrings:test_say_fstring
4
+ scoreboard players operation $_2 rs = $ret rs
5
+ function test_fstrings:test_title_fstring
6
+ scoreboard players operation $_3 rs = $ret rs
7
+ function test_fstrings:test_actionbar_fstring
8
+ scoreboard players operation $_4 rs = $ret rs
9
+ function test_fstrings:test_multi_var_fstring
10
+ scoreboard players operation $_5 rs = $ret rs
11
+ function test_fstrings:test_announce
12
+ scoreboard players operation $_6 rs = $ret rs
13
+ function test_fstrings:test_tell
14
+ scoreboard players operation $_7 rs = $ret rs
15
+ say === Tests Complete ===
@@ -0,0 +1,4 @@
1
+ # block: entry
2
+ scoreboard players set $health rs 20
3
+ title @a actionbar ["",{"text":"HP: "},{"score":{"name":"$health","objective":"rs"}},{"text":" | Score: "},{"score":{"name":"$score","objective":"rs"}}]
4
+ say [PASS] actionbar: displayed to all players
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ tellraw @a {"text":"This is a test announcement!"}
3
+ say [PASS] announce: sent to all players
@@ -0,0 +1,9 @@
1
+ # block: entry
2
+ scoreboard players set $a rs 1
3
+ scoreboard players set $b rs 2
4
+ scoreboard players set $c rs 3
5
+ scoreboard players set $_0 rs 1
6
+ scoreboard players operation $_0 rs += $const_2 rs
7
+ scoreboard players operation $_1 rs = $_0 rs
8
+ scoreboard players operation $_1 rs += $const_3 rs
9
+ tellraw @a ["",{"text":"[PASS] multi-var: a="},{"score":{"name":"$a","objective":"rs"}},{"text":", b="},{"score":{"name":"$b","objective":"rs"}},{"text":", c="},{"score":{"name":"$c","objective":"rs"}},{"text":", sum="},{"score":{"name":"$_1","objective":"rs"}}]
@@ -0,0 +1,4 @@
1
+ # block: entry
2
+ scoreboard players set $value rs 123
3
+ tellraw @a ["",{"text":"[PASS] say f-string: value = "},{"score":{"name":"$value","objective":"rs"}}]
4
+ tellraw @a ["",{"text":"[PASS] say f-string: score = "},{"score":{"name":"$score","objective":"rs"}},{"text":", name_test = "},{"score":{"name":"$name_test","objective":"rs"}}]
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ tellraw @s ["",{"text":"Secret message! Your score is "},{"score":{"name":"$score","objective":"rs"}}]
3
+ say [PASS] tell: whispered to sender
@@ -0,0 +1,4 @@
1
+ # block: entry
2
+ scoreboard players set $level rs 5
3
+ title @a title ["",{"text":"Level "},{"score":{"name":"$level","objective":"rs"}}]
4
+ say [PASS] title: displayed to all players
@@ -0,0 +1,6 @@
1
+ {
2
+ "pack": {
3
+ "pack_format": 26,
4
+ "description": "test_fstrings datapack — compiled by redscript"
5
+ }
6
+ }
@@ -0,0 +1,58 @@
1
+ // ===== F-String & Output Tests =====
2
+ // 测试: f-strings, say, title, actionbar, announce
3
+
4
+ let score: int = 42;
5
+ let name_test: int = 100;
6
+
7
+ // === Test 1: say with f-string ===
8
+ @keep fn test_say_fstring() {
9
+ let value: int = 123;
10
+ say(f"[PASS] say f-string: value = {value}");
11
+ say(f"[PASS] say f-string: score = {score}, name_test = {name_test}");
12
+ }
13
+
14
+ // === Test 2: title with f-string ===
15
+ @keep fn test_title_fstring() {
16
+ let level: int = 5;
17
+ title(@a, f"Level {level}", f"Score: {score}");
18
+ say("[PASS] title: displayed to all players");
19
+ }
20
+
21
+ // === Test 3: actionbar with f-string ===
22
+ @keep fn test_actionbar_fstring() {
23
+ let health: int = 20;
24
+ actionbar(@a, f"HP: {health} | Score: {score}");
25
+ say("[PASS] actionbar: displayed to all players");
26
+ }
27
+
28
+ // === Test 4: Multiple variables in one f-string ===
29
+ @keep fn test_multi_var_fstring() {
30
+ let a: int = 1;
31
+ let b: int = 2;
32
+ let c: int = 3;
33
+ say(f"[PASS] multi-var: a={a}, b={b}, c={c}, sum={(a + b + c)}");
34
+ }
35
+
36
+ // === Test 5: announce (if supported) ===
37
+ @keep fn test_announce() {
38
+ announce("This is a test announcement!");
39
+ say("[PASS] announce: sent to all players");
40
+ }
41
+
42
+ // === Test 6: tell (whisper) ===
43
+ @keep fn test_tell() {
44
+ tell(@s, f"Secret message! Your score is {score}");
45
+ say("[PASS] tell: whispered to sender");
46
+ }
47
+
48
+ // === Run all f-string tests ===
49
+ @keep fn run_fstring_tests() {
50
+ say("=== F-String & Output Tests ===");
51
+ test_say_fstring();
52
+ test_title_fstring();
53
+ test_actionbar_fstring();
54
+ test_multi_var_fstring();
55
+ test_announce();
56
+ test_tell();
57
+ say("=== Tests Complete ===");
58
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "values": [
3
+ "test_timers:__load"
4
+ ]
5
+ }
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ function test_timers:__interval_body_0
3
+ schedule function test_timers:__interval_0 2000t
@@ -0,0 +1,5 @@
1
+ # block: entry
2
+ scoreboard players operation $_0 rs = $interval_count rs
3
+ scoreboard players operation $_0 rs += $const_1 rs
4
+ scoreboard players operation $interval_count rs = $_0 rs
5
+ tellraw @a ["",{"text":"[INFO] setInterval tick #"},{"score":{"name":"$interval_count","objective":"rs"}}]
@@ -0,0 +1,5 @@
1
+ # RedScript runtime init
2
+ scoreboard objectives add rs dummy
3
+ scoreboard players set $interval_count rs 0
4
+ scoreboard players set $const_1 rs 1
5
+ scoreboard players set $const_0 rs 0
@@ -0,0 +1,2 @@
1
+ # block: entry
2
+ say [PASS] setTimeout: callback fired after 3s!
@@ -0,0 +1,5 @@
1
+ # block: entry
2
+ say === Timer Tests ===
3
+ say [INFO] Run each test individually:
4
+ say /function test_timers:test_set_timeout
5
+ say /function test_timers:test_set_interval
@@ -0,0 +1,5 @@
1
+ # block: entry
2
+ scoreboard players set $interval_count rs 0
3
+ say [INFO] setInterval: will fire every 2 seconds...
4
+ say [INFO] Run /function test_timers:stop_interval to stop
5
+ schedule function test_timers:__interval_0 2000t
@@ -0,0 +1,3 @@
1
+ # block: entry
2
+ say [INFO] setTimeout: will fire in 3 seconds...
3
+ schedule function test_timers:__timeout_0 3000t
@@ -0,0 +1,6 @@
1
+ {
2
+ "pack": {
3
+ "pack_format": 26,
4
+ "description": "test_timers datapack — compiled by redscript"
5
+ }
6
+ }
@@ -0,0 +1,35 @@
1
+ // ===== Timer Tests =====
2
+ // 测试: setTimeout, setInterval
3
+
4
+ let interval_count: int = 0;
5
+
6
+ // === Test 1: setTimeout (3 seconds) ===
7
+ @keep fn test_set_timeout() {
8
+ say("[INFO] setTimeout: will fire in 3 seconds...");
9
+ setTimeout(3000, () => {
10
+ say("[PASS] setTimeout: callback fired after 3s!");
11
+ });
12
+ }
13
+
14
+ // === Test 2: setInterval (every 2 seconds, manual stop) ===
15
+ @keep fn test_set_interval() {
16
+ interval_count = 0;
17
+ say("[INFO] setInterval: will fire every 2 seconds...");
18
+ say("[INFO] Run /function test_timers:stop_interval to stop");
19
+
20
+ setInterval(2000, () => {
21
+ interval_count = interval_count + 1;
22
+ say(f"[INFO] setInterval tick #{interval_count}");
23
+ });
24
+ }
25
+
26
+ // Note: clearInterval needs the ID from setInterval
27
+ // This is a simplified test without auto-stop
28
+
29
+ // === Run info ===
30
+ @keep fn run_timer_tests() {
31
+ say("=== Timer Tests ===");
32
+ say("[INFO] Run each test individually:");
33
+ say(" /function test_timers:test_set_timeout");
34
+ say(" /function test_timers:test_set_interval");
35
+ }