redscript-mc 3.0.1 → 3.0.2

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 (225) hide show
  1. package/.github/workflows/ci.yml +1 -0
  2. package/README.md +119 -313
  3. package/README.zh.md +118 -314
  4. package/ROADMAP.md +5 -5
  5. package/dist/data/impl_test/function/counter/get.mcfunction +5 -0
  6. package/dist/data/impl_test/function/counter/inc.mcfunction +7 -0
  7. package/dist/data/impl_test/function/counter/new.mcfunction +4 -0
  8. package/dist/data/impl_test/function/load.mcfunction +1 -0
  9. package/dist/data/impl_test/function/test_impl.mcfunction +10 -0
  10. package/dist/data/minecraft/tags/function/load.json +5 -0
  11. package/dist/data/playground/function/load.mcfunction +1 -0
  12. package/dist/data/playground/function/start.mcfunction +4 -0
  13. package/dist/data/playground/function/start__say_macro_t1.mcfunction +1 -0
  14. package/dist/data/playground/function/stop.mcfunction +5 -0
  15. package/dist/data/playground/function/stop__say_macro_t0.mcfunction +1 -0
  16. package/dist/data/stdlib_queue8_test/function/__queue_append_apply.mcfunction +4 -0
  17. package/dist/data/stdlib_queue8_test/function/__queue_peek_apply.mcfunction +4 -0
  18. package/dist/data/stdlib_queue8_test/function/__queue_size_raw_apply.mcfunction +4 -0
  19. package/dist/data/stdlib_queue8_test/function/load.mcfunction +1 -0
  20. package/dist/data/stdlib_queue8_test/function/queue_clear.mcfunction +6 -0
  21. package/dist/data/stdlib_queue8_test/function/queue_empty__merge_1.mcfunction +5 -0
  22. package/dist/data/stdlib_queue8_test/function/queue_empty__then_0.mcfunction +5 -0
  23. package/dist/data/stdlib_queue8_test/function/queue_peek__merge_1.mcfunction +13 -0
  24. package/dist/data/stdlib_queue8_test/function/queue_peek__then_0.mcfunction +5 -0
  25. package/dist/data/stdlib_queue8_test/function/queue_pop__merge_1.mcfunction +15 -0
  26. package/dist/data/stdlib_queue8_test/function/queue_pop__then_0.mcfunction +5 -0
  27. package/dist/data/stdlib_queue8_test/function/queue_push__const_11.mcfunction +6 -0
  28. package/dist/data/stdlib_queue8_test/function/queue_push__const_22.mcfunction +6 -0
  29. package/dist/data/stdlib_queue8_test/function/queue_size.mcfunction +13 -0
  30. package/dist/data/stdlib_queue8_test/function/test_queue_push_and_size.mcfunction +13 -0
  31. package/dist/data/test/function/load.mcfunction +1 -0
  32. package/dist/data/test/function/say_at.mcfunction +6 -0
  33. package/dist/data/test/function/test.mcfunction +4 -0
  34. package/dist/pack.mcmeta +6 -0
  35. package/dist/package.json +1 -1
  36. package/dist/src/__tests__/formatter-extra.test.d.ts +7 -0
  37. package/dist/src/__tests__/formatter-extra.test.js +123 -0
  38. package/dist/src/__tests__/global-vars.test.d.ts +13 -0
  39. package/dist/src/__tests__/global-vars.test.js +156 -0
  40. package/dist/src/__tests__/lint/new-rules.test.d.ts +9 -0
  41. package/dist/src/__tests__/lint/new-rules.test.js +402 -0
  42. package/dist/src/__tests__/lsp-rename.test.d.ts +8 -0
  43. package/dist/src/__tests__/lsp-rename.test.js +157 -0
  44. package/dist/src/__tests__/mc-integration/say-fstring.test.d.ts +11 -0
  45. package/dist/src/__tests__/mc-integration/say-fstring.test.js +220 -0
  46. package/dist/src/__tests__/mc-integration/stdlib-coverage-2.test.js +1 -1
  47. package/dist/src/__tests__/mc-integration/stdlib-coverage-3.test.js +1 -1
  48. package/dist/src/__tests__/mc-integration/stdlib-coverage-4.test.js +1 -1
  49. package/dist/src/__tests__/mc-integration/stdlib-coverage-5.test.js +1 -1
  50. package/dist/src/__tests__/mc-integration/stdlib-coverage-6.test.js +1 -1
  51. package/dist/src/__tests__/mc-integration/stdlib-coverage-7.test.js +1 -1
  52. package/dist/src/__tests__/mc-integration/stdlib-coverage-8.test.js +1 -1
  53. package/dist/src/__tests__/mc-syntax.test.js +4 -1
  54. package/dist/src/__tests__/monomorphize-coverage.test.d.ts +9 -0
  55. package/dist/src/__tests__/monomorphize-coverage.test.js +204 -0
  56. package/dist/src/__tests__/optimizer-cse.test.d.ts +7 -0
  57. package/dist/src/__tests__/optimizer-cse.test.js +226 -0
  58. package/dist/src/__tests__/parser.test.js +4 -13
  59. package/dist/src/__tests__/repl-server-extra.test.js +6 -7
  60. package/dist/src/__tests__/repl-server.test.js +5 -7
  61. package/dist/src/__tests__/stdlib/queue.test.js +6 -6
  62. package/dist/src/cli.js +0 -0
  63. package/dist/src/lexer/index.js +2 -1
  64. package/dist/src/lint/index.d.ts +12 -5
  65. package/dist/src/lint/index.js +730 -5
  66. package/dist/src/lsp/main.js +0 -0
  67. package/dist/src/mc-test/client.d.ts +21 -0
  68. package/dist/src/mc-test/client.js +34 -0
  69. package/dist/src/mir/lower.js +108 -6
  70. package/dist/src/optimizer/interprocedural.js +37 -2
  71. package/dist/src/parser/decl-parser.d.ts +19 -0
  72. package/dist/src/parser/decl-parser.js +323 -0
  73. package/dist/src/parser/expr-parser.d.ts +46 -0
  74. package/dist/src/parser/expr-parser.js +759 -0
  75. package/dist/src/parser/index.d.ts +8 -129
  76. package/dist/src/parser/index.js +13 -2262
  77. package/dist/src/parser/stmt-parser.d.ts +28 -0
  78. package/dist/src/parser/stmt-parser.js +577 -0
  79. package/dist/src/parser/type-parser.d.ts +20 -0
  80. package/dist/src/parser/type-parser.js +257 -0
  81. package/dist/src/parser/utils.d.ts +34 -0
  82. package/dist/src/parser/utils.js +141 -0
  83. package/docs/dev/README-mc-integration-tests.md +141 -0
  84. package/docs/lint-rules.md +162 -0
  85. package/docs/stdlib/bigint.md +2 -0
  86. package/editors/vscode/README.md +63 -41
  87. package/editors/vscode/out/extension.js +1881 -1776
  88. package/editors/vscode/out/lsp-server.js +4257 -3651
  89. package/editors/vscode/package-lock.json +3 -3
  90. package/editors/vscode/package.json +1 -1
  91. package/examples/loops-demo.mcrs +87 -0
  92. package/package.json +1 -1
  93. package/redscript-docs/docs/en/stdlib/advanced.md +629 -0
  94. package/redscript-docs/docs/en/stdlib/bigint.md +316 -0
  95. package/redscript-docs/docs/en/stdlib/bits.md +292 -0
  96. package/redscript-docs/docs/en/stdlib/bossbar.md +177 -0
  97. package/redscript-docs/docs/en/stdlib/calculus.md +289 -0
  98. package/redscript-docs/docs/en/stdlib/color.md +353 -0
  99. package/redscript-docs/docs/en/stdlib/combat.md +88 -0
  100. package/redscript-docs/docs/en/stdlib/cooldown.md +82 -0
  101. package/redscript-docs/docs/en/stdlib/dialog.md +155 -0
  102. package/redscript-docs/docs/en/stdlib/easing.md +558 -0
  103. package/redscript-docs/docs/en/stdlib/ecs.md +475 -0
  104. package/redscript-docs/docs/en/stdlib/effects.md +324 -0
  105. package/redscript-docs/docs/en/stdlib/events.md +3 -0
  106. package/redscript-docs/docs/en/stdlib/expr.md +45 -0
  107. package/redscript-docs/docs/en/stdlib/fft.md +141 -0
  108. package/redscript-docs/docs/en/stdlib/geometry.md +430 -0
  109. package/redscript-docs/docs/en/stdlib/graph.md +259 -0
  110. package/redscript-docs/docs/en/stdlib/heap.md +185 -0
  111. package/redscript-docs/docs/en/stdlib/interactions.md +179 -0
  112. package/redscript-docs/docs/en/stdlib/inventory.md +97 -0
  113. package/redscript-docs/docs/en/stdlib/linalg.md +557 -0
  114. package/redscript-docs/docs/en/stdlib/list.md +559 -0
  115. package/redscript-docs/docs/en/stdlib/map.md +140 -0
  116. package/redscript-docs/docs/en/stdlib/math.md +193 -0
  117. package/redscript-docs/docs/en/stdlib/math_hp.md +149 -0
  118. package/redscript-docs/docs/en/stdlib/matrix.md +403 -0
  119. package/redscript-docs/docs/en/stdlib/mobs.md +965 -0
  120. package/redscript-docs/docs/en/stdlib/noise.md +244 -0
  121. package/redscript-docs/docs/en/stdlib/ode.md +253 -0
  122. package/redscript-docs/docs/en/stdlib/parabola.md +342 -0
  123. package/redscript-docs/docs/en/stdlib/particles.md +311 -0
  124. package/redscript-docs/docs/en/stdlib/pathfind.md +255 -0
  125. package/redscript-docs/docs/en/stdlib/physics.md +493 -0
  126. package/redscript-docs/docs/en/stdlib/player.md +78 -0
  127. package/redscript-docs/docs/en/stdlib/quaternion.md +673 -0
  128. package/redscript-docs/docs/en/stdlib/queue.md +134 -0
  129. package/redscript-docs/docs/en/stdlib/random.md +223 -0
  130. package/redscript-docs/docs/en/stdlib/result.md +143 -0
  131. package/redscript-docs/docs/en/stdlib/scheduler.md +183 -0
  132. package/redscript-docs/docs/en/stdlib/set_int.md +190 -0
  133. package/redscript-docs/docs/en/stdlib/sets.md +101 -0
  134. package/redscript-docs/docs/en/stdlib/signal.md +400 -0
  135. package/redscript-docs/docs/en/stdlib/sort.md +104 -0
  136. package/redscript-docs/docs/en/stdlib/spawn.md +147 -0
  137. package/redscript-docs/docs/en/stdlib/state.md +142 -0
  138. package/redscript-docs/docs/en/stdlib/strings.md +154 -0
  139. package/redscript-docs/docs/en/stdlib/tags.md +3451 -0
  140. package/redscript-docs/docs/en/stdlib/teams.md +153 -0
  141. package/redscript-docs/docs/en/stdlib/timer.md +246 -0
  142. package/redscript-docs/docs/en/stdlib/vec.md +158 -0
  143. package/redscript-docs/docs/en/stdlib/world.md +298 -0
  144. package/redscript-docs/docs/zh/stdlib/advanced.md +615 -0
  145. package/redscript-docs/docs/zh/stdlib/bigint.md +316 -0
  146. package/redscript-docs/docs/zh/stdlib/bits.md +292 -0
  147. package/redscript-docs/docs/zh/stdlib/bossbar.md +170 -0
  148. package/redscript-docs/docs/zh/stdlib/calculus.md +287 -0
  149. package/redscript-docs/docs/zh/stdlib/color.md +353 -0
  150. package/redscript-docs/docs/zh/stdlib/combat.md +88 -0
  151. package/redscript-docs/docs/zh/stdlib/cooldown.md +84 -0
  152. package/redscript-docs/docs/zh/stdlib/dialog.md +152 -0
  153. package/redscript-docs/docs/zh/stdlib/easing.md +558 -0
  154. package/redscript-docs/docs/zh/stdlib/ecs.md +472 -0
  155. package/redscript-docs/docs/zh/stdlib/effects.md +324 -0
  156. package/redscript-docs/docs/zh/stdlib/events.md +3 -0
  157. package/redscript-docs/docs/zh/stdlib/expr.md +37 -0
  158. package/redscript-docs/docs/zh/stdlib/fft.md +128 -0
  159. package/redscript-docs/docs/zh/stdlib/geometry.md +430 -0
  160. package/redscript-docs/docs/zh/stdlib/graph.md +259 -0
  161. package/redscript-docs/docs/zh/stdlib/heap.md +185 -0
  162. package/redscript-docs/docs/zh/stdlib/interactions.md +160 -0
  163. package/redscript-docs/docs/zh/stdlib/inventory.md +94 -0
  164. package/redscript-docs/docs/zh/stdlib/linalg.md +543 -0
  165. package/redscript-docs/docs/zh/stdlib/list.md +561 -0
  166. package/redscript-docs/docs/zh/stdlib/map.md +132 -0
  167. package/redscript-docs/docs/zh/stdlib/math.md +193 -0
  168. package/redscript-docs/docs/zh/stdlib/math_hp.md +143 -0
  169. package/redscript-docs/docs/zh/stdlib/matrix.md +396 -0
  170. package/redscript-docs/docs/zh/stdlib/mobs.md +965 -0
  171. package/redscript-docs/docs/zh/stdlib/noise.md +244 -0
  172. package/redscript-docs/docs/zh/stdlib/ode.md +243 -0
  173. package/redscript-docs/docs/zh/stdlib/parabola.md +337 -0
  174. package/redscript-docs/docs/zh/stdlib/particles.md +307 -0
  175. package/redscript-docs/docs/zh/stdlib/pathfind.md +255 -0
  176. package/redscript-docs/docs/zh/stdlib/physics.md +493 -0
  177. package/redscript-docs/docs/zh/stdlib/player.md +78 -0
  178. package/redscript-docs/docs/zh/stdlib/quaternion.md +669 -0
  179. package/redscript-docs/docs/zh/stdlib/queue.md +124 -0
  180. package/redscript-docs/docs/zh/stdlib/random.md +222 -0
  181. package/redscript-docs/docs/zh/stdlib/result.md +147 -0
  182. package/redscript-docs/docs/zh/stdlib/scheduler.md +173 -0
  183. package/redscript-docs/docs/zh/stdlib/set_int.md +180 -0
  184. package/redscript-docs/docs/zh/stdlib/sets.md +107 -0
  185. package/redscript-docs/docs/zh/stdlib/signal.md +373 -0
  186. package/redscript-docs/docs/zh/stdlib/sort.md +104 -0
  187. package/redscript-docs/docs/zh/stdlib/spawn.md +142 -0
  188. package/redscript-docs/docs/zh/stdlib/state.md +134 -0
  189. package/redscript-docs/docs/zh/stdlib/strings.md +107 -0
  190. package/redscript-docs/docs/zh/stdlib/tags.md +3451 -0
  191. package/redscript-docs/docs/zh/stdlib/teams.md +150 -0
  192. package/redscript-docs/docs/zh/stdlib/timer.md +254 -0
  193. package/redscript-docs/docs/zh/stdlib/vec.md +158 -0
  194. package/redscript-docs/docs/zh/stdlib/world.md +289 -0
  195. package/src/__tests__/formatter-extra.test.ts +139 -0
  196. package/src/__tests__/global-vars.test.ts +171 -0
  197. package/src/__tests__/lint/new-rules.test.ts +437 -0
  198. package/src/__tests__/lsp-rename.test.ts +171 -0
  199. package/src/__tests__/mc-integration/say-fstring.test.ts +211 -0
  200. package/src/__tests__/mc-integration/stdlib-coverage-2.test.ts +1 -1
  201. package/src/__tests__/mc-integration/stdlib-coverage-3.test.ts +1 -1
  202. package/src/__tests__/mc-integration/stdlib-coverage-4.test.ts +1 -1
  203. package/src/__tests__/mc-integration/stdlib-coverage-5.test.ts +1 -1
  204. package/src/__tests__/mc-integration/stdlib-coverage-6.test.ts +1 -1
  205. package/src/__tests__/mc-integration/stdlib-coverage-7.test.ts +1 -1
  206. package/src/__tests__/mc-integration/stdlib-coverage-8.test.ts +1 -1
  207. package/src/__tests__/mc-syntax.test.ts +3 -0
  208. package/src/__tests__/monomorphize-coverage.test.ts +220 -0
  209. package/src/__tests__/optimizer-cse.test.ts +250 -0
  210. package/src/__tests__/parser.test.ts +4 -13
  211. package/src/__tests__/repl-server-extra.test.ts +6 -6
  212. package/src/__tests__/repl-server.test.ts +5 -6
  213. package/src/__tests__/stdlib/queue.test.ts +6 -6
  214. package/src/lexer/index.ts +2 -1
  215. package/src/lint/index.ts +713 -5
  216. package/src/mc-test/client.ts +40 -0
  217. package/src/mir/lower.ts +111 -2
  218. package/src/optimizer/interprocedural.ts +40 -2
  219. package/src/parser/decl-parser.ts +349 -0
  220. package/src/parser/expr-parser.ts +838 -0
  221. package/src/parser/index.ts +17 -2558
  222. package/src/parser/stmt-parser.ts +585 -0
  223. package/src/parser/type-parser.ts +276 -0
  224. package/src/parser/utils.ts +173 -0
  225. package/src/stdlib/queue.mcrs +19 -6
@@ -0,0 +1,430 @@
1
+ # Geometry
2
+
3
+ > 本文档由 `src/stdlib/geometry.mcrs` 自动生成,请勿手动编辑。
4
+
5
+ ## API 列表
6
+
7
+ - [midpoint](#midpoint)
8
+ - [aabb_contains](#aabb-contains)
9
+ - [sphere_contains](#sphere-contains)
10
+ - [cylinder_contains](#cylinder-contains)
11
+ - [parabola_y](#parabola-y)
12
+ - [parabola_x](#parabola-x)
13
+ - [parabola_land_t](#parabola-land-t)
14
+ - [tile_of](#tile-of)
15
+ - [tile_center](#tile-center)
16
+ - [angle_normalize](#angle-normalize)
17
+ - [angle_diff](#angle-diff)
18
+ - [mc_day_angle](#mc-day-angle)
19
+ - [in_cylinder](#in-cylinder)
20
+ - [in_cone](#in-cone)
21
+ - [in_sector_2d](#in-sector-2d)
22
+
23
+ ---
24
+
25
+ ## `midpoint` <Badge type="info" text="v1.0.0" />
26
+
27
+ 计算两个坐标的整数中点
28
+
29
+ ```redscript
30
+ fn midpoint(a: int, b: int): int
31
+ ```
32
+
33
+ **参数**
34
+
35
+ | 参数 | 说明 |
36
+ |------|------|
37
+ | `a` | 第一个坐标 |
38
+ | `b` | 第二个坐标 |
39
+
40
+ **返回:** (a + b) / 2(整数截断)
41
+
42
+ **示例**
43
+
44
+ ```redscript
45
+ let m: int = midpoint(100, 300) // result: 200
46
+ ```
47
+
48
+ ---
49
+
50
+ ## `aabb_contains` <Badge type="info" text="v1.0.0" />
51
+
52
+ 检测三维点是否在轴对齐包围盒(AABB)内
53
+
54
+ ```redscript
55
+ fn aabb_contains(px: int, py: int, pz: int, minx: int, miny: int, minz: int, maxx: int, maxy: int, maxz: int): int
56
+ ```
57
+
58
+ **参数**
59
+
60
+ | 参数 | 说明 |
61
+ |------|------|
62
+ | `px` | 点 X 坐标 |
63
+ | `py` | 点 Y 坐标 |
64
+ | `pz` | 点 Z 坐标 |
65
+ | `minx` | 包围盒最小 X(含) |
66
+ | `miny` | 包围盒最小 Y(含) |
67
+ | `minz` | 包围盒最小 Z(含) |
68
+ | `maxx` | 包围盒最大 X(含) |
69
+ | `maxy` | 包围盒最大 Y(含) |
70
+ | `maxz` | 包围盒最大 Z(含) |
71
+
72
+ **返回:** 点在包围盒内或边界上返回 1,否则返回 0
73
+
74
+ **示例**
75
+
76
+ ```redscript
77
+ let inside: int = aabb_contains(50, 64, 50, 0, 60, 0, 100, 70, 100)
78
+ ```
79
+
80
+ ---
81
+
82
+ ## `sphere_contains` <Badge type="info" text="v1.0.0" />
83
+
84
+ 检测三维点是否在球体内(用平方距离避免 sqrt)
85
+
86
+ ```redscript
87
+ fn sphere_contains(px: int, py: int, pz: int, cx: int, cy: int, cz: int, r: int): int
88
+ ```
89
+
90
+ **参数**
91
+
92
+ | 参数 | 说明 |
93
+ |------|------|
94
+ | `px` | 点 X |
95
+ | `py` | 点 Y |
96
+ | `pz` | 点 Z |
97
+ | `cx` | 球心 X |
98
+ | `cy` | 球心 Y |
99
+ | `cz` | 球心 Z |
100
+ | `r` | 球半径(与坐标同单位) |
101
+
102
+ **返回:** 点在球内返回 1,否则返回 0
103
+
104
+ **示例**
105
+
106
+ ```redscript
107
+ let hit: int = sphere_contains(10, 64, 10, 0, 64, 0, 15)
108
+ ```
109
+
110
+ ---
111
+
112
+ ## `cylinder_contains` <Badge type="info" text="v1.0.0" />
113
+
114
+ 检测二维点(XZ 平面)是否在竖直圆柱截面内(忽略 Y 轴)
115
+
116
+ ```redscript
117
+ fn cylinder_contains(px: int, pz: int, cx: int, cz: int, r: int): int
118
+ ```
119
+
120
+ **参数**
121
+
122
+ | 参数 | 说明 |
123
+ |------|------|
124
+ | `px` | 点 X |
125
+ | `pz` | 点 Z |
126
+ | `cx` | 圆柱中心 X |
127
+ | `cz` | 圆柱中心 Z |
128
+ | `r` | 圆柱半径 |
129
+
130
+ **返回:** 点在圆柱截面内返回 1,否则返回 0
131
+
132
+ **示例**
133
+
134
+ ```redscript
135
+ let in_zone: int = cylinder_contains(5, 5, 0, 0, 8)
136
+ ```
137
+
138
+ ---
139
+
140
+ ## `parabola_y` <Badge type="info" text="v1.0.0" />
141
+
142
+ Compute Y position of a projectile along a parabolic arc at tick t.
143
+
144
+ ```redscript
145
+ fn parabola_y(y0: int, vy0: int, t: int): int
146
+ ```
147
+
148
+ **参数**
149
+
150
+ | 参数 | 说明 |
151
+ |------|------|
152
+ | `y0` | Initial Y ×100 |
153
+ | `vy0` | Initial Y velocity ×100 (blocks/tick × 100) |
154
+ | `t` | Tick index |
155
+
156
+ **返回:** y0 + vy0*t - 5*t²/2 (gravity = 5 units/tick² = 0.05 blocks/tick²×100)
157
+
158
+ **示例**
159
+
160
+ ```redscript
161
+ let y: int = parabola_y(6400, 100, 10) // at tick 10, v0=1 block/tick
162
+ ```
163
+
164
+ ---
165
+
166
+ ## `parabola_x` <Badge type="info" text="v1.0.0" />
167
+
168
+ Compute horizontal X position along a parabolic path (constant velocity).
169
+
170
+ ```redscript
171
+ fn parabola_x(x0: int, vx0: int, t: int): int
172
+ ```
173
+
174
+ **参数**
175
+
176
+ | 参数 | 说明 |
177
+ |------|------|
178
+ | `x0` | Initial X ×100 |
179
+ | `vx0` | Horizontal X velocity ×100 |
180
+ | `t` | Tick index |
181
+
182
+ **返回:** x0 + vx0*t
183
+
184
+ **示例**
185
+
186
+ ```redscript
187
+ let x: int = parabola_x(0, 50, 10) // 0 + 50*10 = 500
188
+ ```
189
+
190
+ ---
191
+
192
+ ## `parabola_land_t` <Badge type="info" text="v1.0.0" />
193
+
194
+ Estimate the tick when a projectile launched upward returns to Y=0.
195
+
196
+ ```redscript
197
+ fn parabola_land_t(vy0: int): int
198
+ ```
199
+
200
+ **参数**
201
+
202
+ | 参数 | 说明 |
203
+ |------|------|
204
+ | `vy0` | Initial upward Y velocity ×100 |
205
+
206
+ **返回:** Approximate landing tick: 2 * vy0 / 5
207
+
208
+ **示例**
209
+
210
+ ```redscript
211
+ let land: int = parabola_land_t(100) // tick when projectile lands
212
+ ```
213
+
214
+ ---
215
+
216
+ ## `tile_of` <Badge type="info" text="v1.0.0" />
217
+
218
+ Compute which tile a coordinate falls in (floor division, handles negatives).
219
+
220
+ ```redscript
221
+ fn tile_of(coord: int, tile_size: int): int
222
+ ```
223
+
224
+ **参数**
225
+
226
+ | 参数 | 说明 |
227
+ |------|------|
228
+ | `coord` | Coordinate value (any unit) |
229
+ | `tile_size` | Size of each tile in the same unit |
230
+
231
+ **返回:** Floor-divided tile index (correct for negative coordinates)
232
+
233
+ **示例**
234
+
235
+ ```redscript
236
+ let tile: int = tile_of(250, 100) // result: 2 (tile index 2)
237
+ ```
238
+
239
+ ---
240
+
241
+ ## `tile_center` <Badge type="info" text="v1.0.0" />
242
+
243
+ Compute the center coordinate of a tile.
244
+
245
+ ```redscript
246
+ fn tile_center(tile: int, tile_size: int): int
247
+ ```
248
+
249
+ **参数**
250
+
251
+ | 参数 | 说明 |
252
+ |------|------|
253
+ | `tile` | Tile index |
254
+ | `tile_size` | Size of each tile |
255
+
256
+ **返回:** tile * tile_size + tile_size / 2
257
+
258
+ **示例**
259
+
260
+ ```redscript
261
+ let c: int = tile_center(2, 100) // result: 250 (center of tile 2)
262
+ ```
263
+
264
+ ---
265
+
266
+ ## `angle_normalize` <Badge type="info" text="v1.0.0" />
267
+
268
+ 将角度(度×10000)归一化到 [0, 3600000) 范围
269
+
270
+ ```redscript
271
+ fn angle_normalize(deg: int): int
272
+ ```
273
+
274
+ **参数**
275
+
276
+ | 参数 | 说明 |
277
+ |------|------|
278
+ | `deg` | 输入角度 ×10000(可为负数或超过 360°) |
279
+
280
+ **返回:** 等效角度在 [0, 3600000) 范围内
281
+
282
+ **示例**
283
+
284
+ ```redscript
285
+ let a: int = angle_normalize(-900000) // result: 2700000 (270°)
286
+ ```
287
+
288
+ ---
289
+
290
+ ## `angle_diff` <Badge type="info" text="v1.0.0" />
291
+
292
+ 计算两角度之间的有符号最短角度差(度×10000)
293
+
294
+ ```redscript
295
+ fn angle_diff(a: int, b: int): int
296
+ ```
297
+
298
+ **参数**
299
+
300
+ | 参数 | 说明 |
301
+ |------|------|
302
+ | `a` | 起始角 ×10000 |
303
+ | `b` | 目标角 ×10000 |
304
+
305
+ **返回:** 有符号差值在 (-1800000, 1800000]
306
+
307
+ **示例**
308
+
309
+ ```redscript
310
+ let diff: int = angle_diff(3500000, 100000) // ≈ -3400000 → wraps to short arc
311
+ ```
312
+
313
+ ---
314
+
315
+ ## `mc_day_angle` <Badge type="info" text="v1.0.0" />
316
+
317
+ Convert Minecraft daytime ticks to sun angle in degrees ×10000.
318
+
319
+ ```redscript
320
+ fn mc_day_angle(daytime: int): int
321
+ ```
322
+
323
+ **参数**
324
+
325
+ | 参数 | 说明 |
326
+ |------|------|
327
+ | `daytime` | /time query daytime value (0-23999; 0=dawn, 6000=noon) |
328
+
329
+ **返回:** Sun angle in [0, 3600000) degrees ×10000
330
+
331
+ **示例**
332
+
333
+ ```redscript
334
+ let sun: int = mc_day_angle(6000) // noon → 1800000 (180°)
335
+ ```
336
+
337
+ ---
338
+
339
+ ## `in_cylinder` <Badge type="info" text="v1.0.0" />
340
+
341
+ Test whether a point is inside a vertical cylinder (XZ circle with Y bounds).
342
+
343
+ ```redscript
344
+ fn in_cylinder(px: int, py: int, pz: int, cx: int, cz: int, radius: int, y_lo: int, y_hi: int): int
345
+ ```
346
+
347
+ **参数**
348
+
349
+ | 参数 | 说明 |
350
+ |------|------|
351
+ | `px` | Point X ×10000 |
352
+ | `py` | Point Y ×10000 |
353
+ | `pz` | Point Z ×10000 |
354
+ | `cx` | Cylinder center X ×10000 |
355
+ | `cz` | Cylinder center Z ×10000 |
356
+ | `radius` | Cylinder radius ×10000 (keep ≤ 46340 to avoid overflow) |
357
+ | `y_lo` | Y lower bound ×10000 (inclusive) |
358
+ | `y_hi` | Y upper bound ×10000 (inclusive) |
359
+
360
+ **返回:** 1 if point is inside the cylinder, 0 otherwise
361
+
362
+ **示例**
363
+
364
+ ```redscript
365
+ let hit: int = in_cylinder(100000, 640000, 100000, 0, 0, 80000, 600000, 800000)
366
+ ```
367
+
368
+ ---
369
+
370
+ ## `in_cone` <Badge type="info" text="v1.0.0" />
371
+
372
+ Test whether a point is inside an upright cone (axis along +Y or -Y from apex).
373
+
374
+ ```redscript
375
+ fn in_cone(px: int, py: int, pz: int, apex_x: int, apex_y: int, apex_z: int, dir_y: int, half_angle_tan: int, height: int): int
376
+ ```
377
+
378
+ **参数**
379
+
380
+ | 参数 | 说明 |
381
+ |------|------|
382
+ | `px` | Point X ×10000 |
383
+ | `py` | Point Y ×10000 |
384
+ | `pz` | Point Z ×10000 |
385
+ | `apex_x` | Cone apex X ×10000 |
386
+ | `apex_y` | Cone apex Y ×10000 |
387
+ | `apex_z` | Cone apex Z ×10000 |
388
+ | `dir_y` | Cone direction: positive = upward, negative = downward |
389
+ | `half_angle_tan` | tan(half-angle) ×10000 (45° = 10000, 30° = 5773) |
390
+ | `height` | Cone height ×10000 |
391
+
392
+ **返回:** 1 if point is inside the cone, 0 otherwise
393
+
394
+ **示例**
395
+
396
+ ```redscript
397
+ let hit: int = in_cone(px, py, pz, apex_x, apex_y, apex_z, 1, 10000, 50000)
398
+ ```
399
+
400
+ ---
401
+
402
+ ## `in_sector_2d` <Badge type="info" text="v1.0.0" />
403
+
404
+ Test whether a 2D point is inside a sector (pie-slice) in the XZ plane.
405
+
406
+ ```redscript
407
+ fn in_sector_2d(px: int, pz: int, cx: int, cz: int, dir_angle: int, half_angle: int, radius: int): int
408
+ ```
409
+
410
+ **参数**
411
+
412
+ | 参数 | 说明 |
413
+ |------|------|
414
+ | `px` | Point X ×10000 |
415
+ | `pz` | Point Z ×10000 |
416
+ | `cx` | Sector center X ×10000 |
417
+ | `cz` | Sector center Z ×10000 |
418
+ | `dir_angle` | Sector center direction in ×10000 radians (0 = +X, 628318 = 2π) |
419
+ | `half_angle` | Half-width of sector in ×10000 radians |
420
+ | `radius` | Maximum radius (same units as px, pz) |
421
+
422
+ **返回:** 1 if point is within the sector, 0 otherwise
423
+
424
+ **示例**
425
+
426
+ ```redscript
427
+ let hit: int = in_sector_2d(px, pz, 0, 0, 0, 157079, 100000) // quarter-circle facing +X
428
+ ```
429
+
430
+ ---
@@ -0,0 +1,259 @@
1
+ # Graph
2
+
3
+ > 本文档由 `src/stdlib/graph.mcrs` 自动生成,请勿手动编辑。
4
+
5
+ ## API 列表
6
+
7
+ - [graph_is_valid_node](#graph-is-valid-node)
8
+ - [graph_new](#graph-new)
9
+ - [graph_add_edge](#graph-add-edge)
10
+ - [graph_add_undirected](#graph-add-undirected)
11
+ - [graph_node_count](#graph-node-count)
12
+ - [graph_edge_count](#graph-edge-count)
13
+ - [graph_bfs](#graph-bfs)
14
+ - [graph_dfs](#graph-dfs)
15
+ - [graph_has_path](#graph-has-path)
16
+ - [graph_shortest_path](#graph-shortest-path)
17
+
18
+ ---
19
+
20
+ ## `graph_is_valid_node` <Badge type="info" text="v1.0.0" />
21
+
22
+ Check whether a node index is valid for this graph.
23
+
24
+ ```redscript
25
+ fn graph_is_valid_node(g: int[], node: int): int
26
+ ```
27
+
28
+ **参数**
29
+
30
+ | 参数 | 说明 |
31
+ |------|------|
32
+ | `g` | Graph array (from graph_new) |
33
+ | `node` | Node index to validate |
34
+
35
+ **返回:** 1 if node is in [0, node_count), 0 otherwise
36
+
37
+ ---
38
+
39
+ ## `graph_new` <Badge type="info" text="v1.0.0" />
40
+
41
+ 创建含 n 个节点、最多 256 条有向边的新空图
42
+
43
+ ```redscript
44
+ fn graph_new(n: int): int[]
45
+ ```
46
+
47
+ **参数**
48
+
49
+ | 参数 | 说明 |
50
+ |------|------|
51
+ | `n` | 节点数量(限制在 [0, 64]) |
52
+
53
+ **返回:** 初始化的图 int[],g[0]=0(边数),g[1]=n(节点数)
54
+
55
+ **示例**
56
+
57
+ ```redscript
58
+ let g: int[] = graph_new(5) // graph with 5 nodes, no edges
59
+ ```
60
+
61
+ ---
62
+
63
+ ## `graph_add_edge` <Badge type="info" text="v1.0.0" />
64
+
65
+ 向图中添加一条有向加权边
66
+
67
+ ```redscript
68
+ fn graph_add_edge(g: int[], src: int, dst: int, weight: int): int[]
69
+ ```
70
+
71
+ **参数**
72
+
73
+ | 参数 | 说明 |
74
+ |------|------|
75
+ | `g` | 图数组 |
76
+ | `src` | 源节点索引 |
77
+ | `dst` | 目标节点索引 |
78
+ | `weight` | 边权重(无权图使用 1) |
79
+
80
+ **返回:** 更新后的图数组;节点无效或边数已满时静默忽略
81
+
82
+ **示例**
83
+
84
+ ```redscript
85
+ g = graph_add_edge(g, 0, 1, 5) // edge from 0 to 1 with weight 5
86
+ ```
87
+
88
+ ---
89
+
90
+ ## `graph_add_undirected` <Badge type="info" text="v1.0.0" />
91
+
92
+ 添加无向加权边(同时添加 a→b 和 b→a 两条有向边)
93
+
94
+ ```redscript
95
+ fn graph_add_undirected(g: int[], a: int, b: int, weight: int): int[]
96
+ ```
97
+
98
+ **参数**
99
+
100
+ | 参数 | 说明 |
101
+ |------|------|
102
+ | `g` | 图数组 |
103
+ | `a` | 第一个节点索引 |
104
+ | `b` | 第二个节点索引 |
105
+ | `weight` | 边权重 |
106
+
107
+ **返回:** 添加了两条有向边的更新图数组
108
+
109
+ **示例**
110
+
111
+ ```redscript
112
+ g = graph_add_undirected(g, 2, 3, 2) // bidirectional edge between 2 and 3
113
+ ```
114
+
115
+ ---
116
+
117
+ ## `graph_node_count` <Badge type="info" text="v1.0.0" />
118
+
119
+ Return the number of nodes in the graph.
120
+
121
+ ```redscript
122
+ fn graph_node_count(g: int[]): int
123
+ ```
124
+
125
+ **参数**
126
+
127
+ | 参数 | 说明 |
128
+ |------|------|
129
+ | `g` | Graph array |
130
+
131
+ **返回:** Node count (g[1])
132
+
133
+ ---
134
+
135
+ ## `graph_edge_count` <Badge type="info" text="v1.0.0" />
136
+
137
+ Return the number of directed edges in the graph.
138
+
139
+ ```redscript
140
+ fn graph_edge_count(g: int[]): int
141
+ ```
142
+
143
+ **参数**
144
+
145
+ | 参数 | 说明 |
146
+ |------|------|
147
+ | `g` | Graph array |
148
+
149
+ **返回:** Edge count (g[0])
150
+
151
+ ---
152
+
153
+ ## `graph_bfs` <Badge type="info" text="v1.0.0" />
154
+
155
+ 从起始节点广度优先搜索,返回访问顺序
156
+
157
+ ```redscript
158
+ fn graph_bfs(g: int[], start: int, out_visited: int[]): int[]
159
+ ```
160
+
161
+ **参数**
162
+
163
+ | 参数 | 说明 |
164
+ |------|------|
165
+ | `g` | 图数组 |
166
+ | `start` | 起始节点索引 |
167
+ | `out_visited` | 长度 >= node_count 的 int[];已访问节点对应格设为 1 |
168
+
169
+ **返回:** BFS 访问顺序的节点索引 int[];起始节点无效时返回空数组
170
+
171
+ **示例**
172
+
173
+ ```redscript
174
+ let vis: int[] = [0, 0, 0, 0, 0]
175
+ let order: int[] = graph_bfs(g, 0, vis)
176
+ ```
177
+
178
+ ---
179
+
180
+ ## `graph_dfs` <Badge type="info" text="v1.0.0" />
181
+
182
+ 从起始节点深度优先搜索,返回访问顺序(迭代实现,基于栈)
183
+
184
+ ```redscript
185
+ fn graph_dfs(g: int[], start: int, out_visited: int[]): int[]
186
+ ```
187
+
188
+ **参数**
189
+
190
+ | 参数 | 说明 |
191
+ |------|------|
192
+ | `g` | 图数组 |
193
+ | `start` | 起始节点索引 |
194
+ | `out_visited` | 长度 >= node_count 的 int[] |
195
+
196
+ **返回:** DFS 访问顺序的节点索引 int[]
197
+
198
+ **示例**
199
+
200
+ ```redscript
201
+ let vis: int[] = [0, 0, 0, 0, 0]
202
+ let order: int[] = graph_dfs(g, 0, vis)
203
+ ```
204
+
205
+ ---
206
+
207
+ ## `graph_has_path` <Badge type="info" text="v1.0.0" />
208
+
209
+ 使用 BFS 检测两节点之间是否存在有向路径
210
+
211
+ ```redscript
212
+ fn graph_has_path(g: int[], src: int, dst: int): int
213
+ ```
214
+
215
+ **参数**
216
+
217
+ | 参数 | 说明 |
218
+ |------|------|
219
+ | `g` | 图数组 |
220
+ | `src` | 源节点索引 |
221
+ | `dst` | 目标节点索引 |
222
+
223
+ **返回:** 存在从 src 到 dst 的有向路径返回 1,否则返回 0
224
+
225
+ **示例**
226
+
227
+ ```redscript
228
+ let reachable: int = graph_has_path(g, 0, 3)
229
+ ```
230
+
231
+ ---
232
+
233
+ ## `graph_shortest_path` <Badge type="info" text="v1.0.0" />
234
+
235
+ 使用 Dijkstra 算法计算从源节点到所有节点的最短加权路径
236
+
237
+ ```redscript
238
+ fn graph_shortest_path(g: int[], src: int, dst: int, out_dist: int[]): int
239
+ ```
240
+
241
+ **参数**
242
+
243
+ | 参数 | 说明 |
244
+ |------|------|
245
+ | `g` | 图数组 |
246
+ | `src` | 源节点索引 |
247
+ | `dst` | 目标节点索引(用于返回值) |
248
+ | `out_dist` | 长度 >= node_count 的 int[];填入最短距离(不可达为 -1) |
249
+
250
+ **返回:** src 到 dst 的最短距离,不可达返回 -1
251
+
252
+ **示例**
253
+
254
+ ```redscript
255
+ let dist: int[] = [0, 0, 0, 0, 0]
256
+ let d: int = graph_shortest_path(g, 0, 3, dist)
257
+ ```
258
+
259
+ ---