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,493 @@
1
+ # Physics
2
+
3
+ > 本文档由 `src/stdlib/physics.mcrs` 自动生成,请勿手动编辑。
4
+
5
+ ## API 列表
6
+
7
+ - [gravity_fx](#gravity-fx)
8
+ - [air_drag_fx](#air-drag-fx)
9
+ - [water_drag_fx](#water-drag-fx)
10
+ - [projectile_y](#projectile-y)
11
+ - [projectile_x](#projectile-x)
12
+ - [projectile_vy](#projectile-vy)
13
+ - [projectile_land_t](#projectile-land-t)
14
+ - [projectile_max_height](#projectile-max-height)
15
+ - [apply_drag](#apply-drag)
16
+ - [apply_gravity](#apply-gravity)
17
+ - [update_pos](#update-pos)
18
+ - [bounce_v](#bounce-v)
19
+ - [clamp_velocity](#clamp-velocity)
20
+ - [spring_force](#spring-force)
21
+ - [spring_update_v](#spring-update-v)
22
+ - [circular_x](#circular-x)
23
+ - [circular_z](#circular-z)
24
+ - [friction_decel](#friction-decel)
25
+ - [is_grounded](#is-grounded)
26
+ - [impact_velocity](#impact-velocity)
27
+
28
+ ---
29
+
30
+ ## `gravity_fx` <Badge type="info" text="v1.0.0" />
31
+
32
+ Minecraft 重力常数(定点数,0.08 方块/刻² × 100 = 8)
33
+
34
+ ```redscript
35
+ fn gravity_fx(): int
36
+ ```
37
+
38
+ **返回:** 8
39
+
40
+ ---
41
+
42
+ ## `air_drag_fx` <Badge type="info" text="v1.0.0" />
43
+
44
+ 空气阻力因子(×10000,每刻乘以 0.98)
45
+
46
+ ```redscript
47
+ fn air_drag_fx(): int
48
+ ```
49
+
50
+ **返回:** 9800
51
+
52
+ ---
53
+
54
+ ## `water_drag_fx` <Badge type="info" text="v1.0.0" />
55
+
56
+ 水中阻力因子(×10000,每刻乘以 0.80)
57
+
58
+ ```redscript
59
+ fn water_drag_fx(): int
60
+ ```
61
+
62
+ **返回:** 8000
63
+
64
+ ---
65
+
66
+ ## `projectile_y` <Badge type="info" text="v1.0.0" />
67
+
68
+ 计算抛体在 t 刻后的 Y 轴位置(无阻力,恒定重力)
69
+
70
+ ```redscript
71
+ fn projectile_y(p0: int, v0: int, t: int): int
72
+ ```
73
+
74
+ **参数**
75
+
76
+ | 参数 | 说明 |
77
+ |------|------|
78
+ | `p0` | 初始 Y 位置 ×100 |
79
+ | `v0` | 初始 Y 速度 ×100(方块/刻 × 100) |
80
+ | `t` | 时间(刻) |
81
+
82
+ **返回:** p0 + v0*t - gravity*t²/2
83
+
84
+ **示例**
85
+
86
+ ```redscript
87
+ let y: int = projectile_y(0, 200, 5) // height after 5 ticks, launched at 2 blocks/tick
88
+ ```
89
+
90
+ ---
91
+
92
+ ## `projectile_x` <Badge type="info" text="v1.0.0" />
93
+
94
+ 计算抛体在 t 刻后的水平 X 位置(匀速,无阻力)
95
+
96
+ ```redscript
97
+ fn projectile_x(p0: int, v0: int, t: int): int
98
+ ```
99
+
100
+ **参数**
101
+
102
+ | 参数 | 说明 |
103
+ |------|------|
104
+ | `p0` | 初始 X 位置 ×100 |
105
+ | `v0` | 水平 X 速度 ×100 |
106
+ | `t` | 时间(刻) |
107
+
108
+ **返回:** p0 + v0*t
109
+
110
+ **示例**
111
+
112
+ ```redscript
113
+ let x: int = projectile_x(0, 100, 10) // 10 blocks/tick for 10 ticks = 1000 units
114
+ ```
115
+
116
+ ---
117
+
118
+ ## `projectile_vy` <Badge type="info" text="v1.0.0" />
119
+
120
+ 计算抛体在 t 刻后的 Y 轴速度(含重力)
121
+
122
+ ```redscript
123
+ fn projectile_vy(v0: int, t: int): int
124
+ ```
125
+
126
+ **参数**
127
+
128
+ | 参数 | 说明 |
129
+ |------|------|
130
+ | `v0` | 初始 Y 速度 ×100 |
131
+ | `t` | 时间(刻) |
132
+
133
+ **返回:** v0 - gravity*t
134
+
135
+ **示例**
136
+
137
+ ```redscript
138
+ let vy: int = projectile_vy(200, 5) // velocity after 5 ticks
139
+ ```
140
+
141
+ ---
142
+
143
+ ## `projectile_land_t` <Badge type="info" text="v1.0.0" />
144
+
145
+ Estimate the tick at which a projectile launched upward returns to Y=0.
146
+
147
+ ```redscript
148
+ fn projectile_land_t(v0y: int): int
149
+ ```
150
+
151
+ **参数**
152
+
153
+ | 参数 | 说明 |
154
+ |------|------|
155
+ | `v0y` | Initial upward Y velocity ×100 (must be positive) |
156
+
157
+ **返回:** 2*v0y / gravity; returns 0 if v0y <= 0
158
+
159
+ **示例**
160
+
161
+ ```redscript
162
+ let land_t: int = projectile_land_t(160) // ticks until landing
163
+ ```
164
+
165
+ ---
166
+
167
+ ## `projectile_max_height` <Badge type="info" text="v1.0.0" />
168
+
169
+ Compute the maximum height reached by a projectile launched upward.
170
+
171
+ ```redscript
172
+ fn projectile_max_height(v0y: int): int
173
+ ```
174
+
175
+ **参数**
176
+
177
+ | 参数 | 说明 |
178
+ |------|------|
179
+ | `v0y` | Initial upward Y velocity ×100 |
180
+
181
+ **返回:** v0y² / (2*gravity) in ×100 units
182
+
183
+ **示例**
184
+
185
+ ```redscript
186
+ let max_h: int = projectile_max_height(160) // peak height in units×100
187
+ ```
188
+
189
+ ---
190
+
191
+ ## `apply_drag` <Badge type="info" text="v1.0.0" />
192
+
193
+ 对速度应用一刻的阻力
194
+
195
+ ```redscript
196
+ fn apply_drag(v_fx: int, drag_fx: int): int
197
+ ```
198
+
199
+ **参数**
200
+
201
+ | 参数 | 说明 |
202
+ |------|------|
203
+ | `v_fx` | 速度 ×100 |
204
+ | `drag_fx` | 阻力因子 ×10000(空气 9800,水 8000) |
205
+
206
+ **返回:** v_fx * drag_fx / 10000
207
+
208
+ **示例**
209
+
210
+ ```redscript
211
+ let v: int = apply_drag(500, air_drag_fx()) // 500 * 0.98 = 490
212
+ ```
213
+
214
+ ---
215
+
216
+ ## `apply_gravity` <Badge type="info" text="v1.0.0" />
217
+
218
+ 对 Y 速度分量应用一刻重力
219
+
220
+ ```redscript
221
+ fn apply_gravity(vy_fx: int): int
222
+ ```
223
+
224
+ **参数**
225
+
226
+ | 参数 | 说明 |
227
+ |------|------|
228
+ | `vy_fx` | 当前 Y 速度 ×100 |
229
+
230
+ **返回:** vy_fx - gravity_fx()
231
+
232
+ **示例**
233
+
234
+ ```redscript
235
+ vy = apply_gravity(vy) // call each tick in your physics loop
236
+ ```
237
+
238
+ ---
239
+
240
+ ## `update_pos` <Badge type="info" text="v1.0.0" />
241
+
242
+ Update a position component by one tick of velocity.
243
+
244
+ ```redscript
245
+ fn update_pos(p_fx: int, v_fx: int): int
246
+ ```
247
+
248
+ **参数**
249
+
250
+ | 参数 | 说明 |
251
+ |------|------|
252
+ | `p_fx` | Current position ×100 |
253
+ | `v_fx` | Velocity ×100 |
254
+
255
+ **返回:** p_fx + v_fx
256
+
257
+ **示例**
258
+
259
+ ```redscript
260
+ px = update_pos(px, vx) // advance X each tick
261
+ ```
262
+
263
+ ---
264
+
265
+ ## `bounce_v` <Badge type="info" text="v1.0.0" />
266
+
267
+ 对速度分量进行弹跳反射(含能量损耗)
268
+
269
+ ```redscript
270
+ fn bounce_v(v_fx: int, restitution_fx: int): int
271
+ ```
272
+
273
+ **参数**
274
+
275
+ | 参数 | 说明 |
276
+ |------|------|
277
+ | `v_fx` | 速度 ×100 |
278
+ | `restitution_fx` | 弹性系数 ×10000(10000=完全弹性,0=完全非弹性) |
279
+
280
+ **返回:** 反向并缩放后的速度
281
+
282
+ **示例**
283
+
284
+ ```redscript
285
+ vy = bounce_v(vy, 7000) // 70% energy retained on bounce
286
+ ```
287
+
288
+ ---
289
+
290
+ ## `clamp_velocity` <Badge type="info" text="v1.0.0" />
291
+
292
+ Clamp a velocity component to a maximum absolute speed.
293
+
294
+ ```redscript
295
+ fn clamp_velocity(v_fx: int, max_fx: int): int
296
+ ```
297
+
298
+ **参数**
299
+
300
+ | 参数 | 说明 |
301
+ |------|------|
302
+ | `v_fx` | Velocity ×100 to clamp |
303
+ | `max_fx` | Maximum absolute velocity ×100 (terminal velocity) |
304
+
305
+ **返回:** v_fx clamped to [-max_fx, max_fx]
306
+
307
+ **示例**
308
+
309
+ ```redscript
310
+ vx = clamp_velocity(vx, 500) // cap horizontal speed at 5 blocks/tick
311
+ ```
312
+
313
+ ---
314
+
315
+ ## `spring_force` <Badge type="info" text="v1.0.0" />
316
+
317
+ 计算弹簧力(胡克定律:F = -k*(x-目标))
318
+
319
+ ```redscript
320
+ fn spring_force(pos_fx: int, target_fx: int, k_fx: int): int
321
+ ```
322
+
323
+ **参数**
324
+
325
+ | 参数 | 说明 |
326
+ |------|------|
327
+ | `pos_fx` | 当前位置 ×100 |
328
+ | `target_fx` | 弹簧平衡位置 ×100 |
329
+ | `k_fx` | 弹簧常数 ×10000 |
330
+
331
+ **返回:** (target - pos) * k / 10000
332
+
333
+ **示例**
334
+
335
+ ```redscript
336
+ let f: int = spring_force(pos, 500, 2000) // spring toward position 500 with k=0.2
337
+ ```
338
+
339
+ ---
340
+
341
+ ## `spring_update_v` <Badge type="info" text="v1.0.0" />
342
+
343
+ Update velocity with spring force and damping (one tick).
344
+
345
+ ```redscript
346
+ fn spring_update_v(v_fx: int, pos_fx: int, target_fx: int, k_fx: int, damping_fx: int): int
347
+ ```
348
+
349
+ **参数**
350
+
351
+ | 参数 | 说明 |
352
+ |------|------|
353
+ | `v_fx` | Current velocity ×100 |
354
+ | `pos_fx` | Current position ×100 |
355
+ | `target_fx` | Spring rest position ×100 |
356
+ | `k_fx` | Spring constant ×10000 |
357
+ | `damping_fx` | Damping factor ×10000 (10000=no damping, 8000=some damping) |
358
+
359
+ **返回:** New velocity after applying spring force and damping
360
+
361
+ **示例**
362
+
363
+ ```redscript
364
+ vx = spring_update_v(vx, px, target_px, 1000, 9000)
365
+ ```
366
+
367
+ ---
368
+
369
+ ## `circular_x` <Badge type="info" text="v1.0.0" />
370
+
371
+ Compute X position on a circle given center, radius, and angle.
372
+
373
+ ```redscript
374
+ fn circular_x(cx: int, r: int, angle_deg: int): int
375
+ ```
376
+
377
+ **参数**
378
+
379
+ | 参数 | 说明 |
380
+ |------|------|
381
+ | `cx` | Circle center X ×100 |
382
+ | `r` | Radius ×100 |
383
+ | `angle_deg` | Angle in whole degrees (NOT ×10000) |
384
+
385
+ **返回:** cx + r * cos(angle_deg) / 1000
386
+
387
+ **示例**
388
+
389
+ ```redscript
390
+ let x: int = circular_x(500, 200, 45) // point at 45° on radius-2 circle
391
+ ```
392
+
393
+ ---
394
+
395
+ ## `circular_z` <Badge type="info" text="v1.0.0" />
396
+
397
+ Compute Z position on a circle given center, radius, and angle.
398
+
399
+ ```redscript
400
+ fn circular_z(cz: int, r: int, angle_deg: int): int
401
+ ```
402
+
403
+ **参数**
404
+
405
+ | 参数 | 说明 |
406
+ |------|------|
407
+ | `cz` | Circle center Z ×100 |
408
+ | `r` | Radius ×100 |
409
+ | `angle_deg` | Angle in whole degrees (NOT ×10000) |
410
+
411
+ **返回:** cz + r * sin(angle_deg) / 1000
412
+
413
+ **示例**
414
+
415
+ ```redscript
416
+ let z: int = circular_z(500, 200, 45)
417
+ ```
418
+
419
+ ---
420
+
421
+ ## `friction_decel` <Badge type="info" text="v1.0.0" />
422
+
423
+ Apply friction to reduce a velocity component toward zero.
424
+
425
+ ```redscript
426
+ fn friction_decel(v_fx: int, friction_fx: int): int
427
+ ```
428
+
429
+ **参数**
430
+
431
+ | 参数 | 说明 |
432
+ |------|------|
433
+ | `v_fx` | Current velocity ×100 |
434
+ | `friction_fx` | Friction deceleration per tick ×100 (absolute amount subtracted) |
435
+
436
+ **返回:** Velocity reduced toward 0 by friction; stops at 0 rather than reversing
437
+
438
+ **示例**
439
+
440
+ ```redscript
441
+ vx = friction_decel(vx, 10) // slow down by 0.1 blocks/tick per tick
442
+ ```
443
+
444
+ ---
445
+
446
+ ## `is_grounded` <Badge type="info" text="v1.0.0" />
447
+
448
+ Check whether a position has reached or fallen below the ground level.
449
+
450
+ ```redscript
451
+ fn is_grounded(y_fx: int, ground_y_fx: int): int
452
+ ```
453
+
454
+ **参数**
455
+
456
+ | 参数 | 说明 |
457
+ |------|------|
458
+ | `y_fx` | Current Y position ×100 |
459
+ | `ground_y_fx` | Ground Y level ×100 |
460
+
461
+ **返回:** 1 if y_fx <= ground_y_fx (grounded), 0 otherwise
462
+
463
+ **示例**
464
+
465
+ ```redscript
466
+ if (is_grounded(py, 0) == 1) { py = 0; vy = bounce_v(vy, 7000); }
467
+ ```
468
+
469
+ ---
470
+
471
+ ## `impact_velocity` <Badge type="info" text="v1.0.0" />
472
+
473
+ Estimate the impact velocity after falling from a given height.
474
+
475
+ ```redscript
476
+ fn impact_velocity(h_fx: int): int
477
+ ```
478
+
479
+ **参数**
480
+
481
+ | 参数 | 说明 |
482
+ |------|------|
483
+ | `h_fx` | Fall height ×100 (blocks × 100, must be positive) |
484
+
485
+ **返回:** Approximate impact speed ×100 via integer square root of 2*g*h
486
+
487
+ **示例**
488
+
489
+ ```redscript
490
+ let impact_v: int = impact_velocity(400) // falling from 4 blocks
491
+ ```
492
+
493
+ ---
@@ -0,0 +1,78 @@
1
+ # Player
2
+
3
+ > 本文档由 `src/stdlib/player.mcrs` 自动生成,请勿手动编辑。
4
+
5
+ ## API 列表
6
+
7
+ - [heal](#heal)
8
+ - [damage](#damage)
9
+ - [is_op](#is-op)
10
+
11
+ ---
12
+
13
+ ## `heal` <Badge type="info" text="v1.0.0" />
14
+
15
+ 通过给
16
+
17
+ ```redscript
18
+ fn heal(amount: int)
19
+ ```
20
+
21
+ **参数**
22
+
23
+ | 参数 | 说明 |
24
+ |------|------|
25
+ | `amount` | 要恢复的生命值点数(正整数) |
26
+
27
+ **返回:** void — 修改 @p 的
28
+
29
+ **示例**
30
+
31
+ ```redscript
32
+ heal(10) // restore 10 HP to nearest player
33
+ ```
34
+
35
+ ---
36
+
37
+ ## `damage` <Badge type="info" text="v1.0.0" />
38
+
39
+ 对最近的玩家造成伤害,生命值最低降至 0
40
+
41
+ ```redscript
42
+ fn damage(amount: int)
43
+ ```
44
+
45
+ **参数**
46
+
47
+ | 参数 | 说明 |
48
+ |------|------|
49
+ | `amount` | 造成的伤害点数(正整数) |
50
+
51
+ **返回:** void — 修改 @p 的
52
+
53
+ **示例**
54
+
55
+ ```redscript
56
+ damage(5) // deal 5 damage to nearest player
57
+ ```
58
+
59
+ ---
60
+
61
+ ## `is_op` <Badge type="info" text="v1.0.0" />
62
+
63
+ 检查最近的玩家是否拥有 op 实体标签(管理员权限)
64
+
65
+ ```redscript
66
+ fn is_op() -> int
67
+ ```
68
+
69
+ **返回:** 若 @p 有 op 标签则返回 1,否则返回 0
70
+
71
+ **示例**
72
+
73
+ ```redscript
74
+ let admin: int = is_op()
75
+ // if (admin == 1) { ... }
76
+ ```
77
+
78
+ ---