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,475 @@
1
+ # Ecs
2
+
3
+ > Auto-generated from `src/stdlib/ecs.mcrs` — do not edit manually.
4
+
5
+ ## API
6
+
7
+ - [ecs_registry_new](#ecs-registry-new)
8
+ - [ecs_register](#ecs-register)
9
+ - [ecs_is_registered](#ecs-is-registered)
10
+ - [ecs_health_init](#ecs-health-init)
11
+ - [ecs_health_get](#ecs-health-get)
12
+ - [ecs_health_max](#ecs-health-max)
13
+ - [ecs_health_set](#ecs-health-set)
14
+ - [ecs_health_damage](#ecs-health-damage)
15
+ - [ecs_health_heal](#ecs-health-heal)
16
+ - [ecs_health_is_dead](#ecs-health-is-dead)
17
+ - [ecs_health_pct](#ecs-health-pct)
18
+ - [ecs_vel_init](#ecs-vel-init)
19
+ - [ecs_vel_get_x](#ecs-vel-get-x)
20
+ - [ecs_vel_get_y](#ecs-vel-get-y)
21
+ - [ecs_vel_get_z](#ecs-vel-get-z)
22
+ - [ecs_vel_set](#ecs-vel-set)
23
+ - [ecs_vel_speed](#ecs-vel-speed)
24
+ - [ecs_vel_apply_gravity](#ecs-vel-apply-gravity)
25
+ - [ecs_vel_damp](#ecs-vel-damp)
26
+
27
+ ---
28
+
29
+ ## `ecs_registry_new` <Badge type="info" text="v2.0.0" />
30
+
31
+ Allocate a blank 16-slot component registry.
32
+
33
+ ```redscript
34
+ fn ecs_registry_new(): int[]
35
+ ```
36
+
37
+ **Returns:** A new `int[]` of length 16 with all slots set to `0`
38
+
39
+ **Example**
40
+
41
+ ```redscript
42
+ let reg: int[] = ecs_registry_new()
43
+ ```
44
+
45
+ ---
46
+
47
+ ## `ecs_register` <Badge type="info" text="v2.0.0" />
48
+
49
+ Mark `comp_id` as registered in the registry and return the updated registry.
50
+
51
+ ```redscript
52
+ fn ecs_register(reg: int[], comp_id: int): int[]
53
+ ```
54
+
55
+ **Parameters**
56
+
57
+ | Parameter | Description |
58
+ |-----------|-------------|
59
+ | `reg` | Registry array from `ecs_registry_new` |
60
+ | `comp_id` | Component type ID in range [0, 15] |
61
+
62
+ **Returns:** Updated registry array
63
+
64
+ **Example**
65
+
66
+ ```redscript
67
+ reg = ecs_register(reg, ECS_COMP_HEALTH)
68
+ ```
69
+
70
+ ---
71
+
72
+ ## `ecs_is_registered` <Badge type="info" text="v2.0.0" />
73
+
74
+ Check whether `comp_id` is registered.
75
+
76
+ ```redscript
77
+ fn ecs_is_registered(reg: int[], comp_id: int): int
78
+ ```
79
+
80
+ **Parameters**
81
+
82
+ | Parameter | Description |
83
+ |-----------|-------------|
84
+ | `reg` | Registry array from `ecs_registry_new` |
85
+ | `comp_id` | Component type ID in range [0, 15] |
86
+
87
+ **Returns:** `1` if registered, `0` otherwise
88
+
89
+ **Example**
90
+
91
+ ```redscript
92
+ if (ecs_is_registered(reg, ECS_COMP_HEALTH) == 1) { }
93
+ ```
94
+
95
+ ---
96
+
97
+ ## `ecs_health_init` <Badge type="info" text="v2.0.0" />
98
+
99
+ Create a health component state with `current_hp = max_hp` (full health).
100
+
101
+ ```redscript
102
+ fn ecs_health_init(entity_score: int, max_hp: int): int[]
103
+ ```
104
+
105
+ **Parameters**
106
+
107
+ | Parameter | Description |
108
+ |-----------|-------------|
109
+ | `entity_score` | Scoreboard score identifying the entity |
110
+ | `max_hp` | Maximum hit points |
111
+
112
+ **Returns:** New 8-element health component state array
113
+
114
+ **Example**
115
+
116
+ ```redscript
117
+ let hp: int[] = ecs_health_init(42, 100)
118
+ ```
119
+
120
+ ---
121
+
122
+ ## `ecs_health_get` <Badge type="info" text="v2.0.0" />
123
+
124
+ Return current HP from a health component state.
125
+
126
+ ```redscript
127
+ fn ecs_health_get(state: int[]): int
128
+ ```
129
+
130
+ **Parameters**
131
+
132
+ | Parameter | Description |
133
+ |-----------|-------------|
134
+ | `state` | Health component state from `ecs_health_init` |
135
+
136
+ **Returns:** Current hit point value
137
+
138
+ **Example**
139
+
140
+ ```redscript
141
+ let hp: int = ecs_health_get(state)
142
+ ```
143
+
144
+ ---
145
+
146
+ ## `ecs_health_max` <Badge type="info" text="v2.0.0" />
147
+
148
+ Return maximum HP from a health component state.
149
+
150
+ ```redscript
151
+ fn ecs_health_max(state: int[]): int
152
+ ```
153
+
154
+ **Parameters**
155
+
156
+ | Parameter | Description |
157
+ |-----------|-------------|
158
+ | `state` | Health component state from `ecs_health_init` |
159
+
160
+ **Returns:** Maximum hit point value
161
+
162
+ **Example**
163
+
164
+ ```redscript
165
+ let max: int = ecs_health_max(state)
166
+ ```
167
+
168
+ ---
169
+
170
+ ## `ecs_health_set` <Badge type="info" text="v2.0.0" />
171
+
172
+ Set current HP (clamped to [0, max]) and return the updated state.
173
+
174
+ ```redscript
175
+ fn ecs_health_set(state: int[], hp: int): int[]
176
+ ```
177
+
178
+ **Parameters**
179
+
180
+ | Parameter | Description |
181
+ |-----------|-------------|
182
+ | `state` | Health component state from `ecs_health_init` |
183
+ | `hp` | New HP value (clamped to valid range automatically) |
184
+
185
+ **Returns:** Updated state array
186
+
187
+ **Example**
188
+
189
+ ```redscript
190
+ state = ecs_health_set(state, 50)
191
+ ```
192
+
193
+ ---
194
+
195
+ ## `ecs_health_damage` <Badge type="info" text="v2.0.0" />
196
+
197
+ Subtract `amount` from HP (clamped to 0) and return the updated state.
198
+
199
+ ```redscript
200
+ fn ecs_health_damage(state: int[], amount: int): int[]
201
+ ```
202
+
203
+ **Parameters**
204
+
205
+ | Parameter | Description |
206
+ |-----------|-------------|
207
+ | `state` | Health component state |
208
+ | `amount` | Damage amount to subtract (positive integer) |
209
+
210
+ **Returns:** Updated state array
211
+
212
+ **Example**
213
+
214
+ ```redscript
215
+ state = ecs_health_damage(state, 30)
216
+ ```
217
+
218
+ ---
219
+
220
+ ## `ecs_health_heal` <Badge type="info" text="v2.0.0" />
221
+
222
+ Add `amount` to HP (clamped to max) and return the updated state.
223
+
224
+ ```redscript
225
+ fn ecs_health_heal(state: int[], amount: int): int[]
226
+ ```
227
+
228
+ **Parameters**
229
+
230
+ | Parameter | Description |
231
+ |-----------|-------------|
232
+ | `state` | Health component state |
233
+ | `amount` | Healing amount to add (positive integer) |
234
+
235
+ **Returns:** Updated state array
236
+
237
+ **Example**
238
+
239
+ ```redscript
240
+ state = ecs_health_heal(state, 20)
241
+ ```
242
+
243
+ ---
244
+
245
+ ## `ecs_health_is_dead` <Badge type="info" text="v2.0.0" />
246
+
247
+ Return `1` if the entity HP is at or below zero, otherwise `0`.
248
+
249
+ ```redscript
250
+ fn ecs_health_is_dead(state: int[]): int
251
+ ```
252
+
253
+ **Parameters**
254
+
255
+ | Parameter | Description |
256
+ |-----------|-------------|
257
+ | `state` | Health component state |
258
+
259
+ **Returns:** `1` if dead, `0` if alive
260
+
261
+ **Example**
262
+
263
+ ```redscript
264
+ if (ecs_health_is_dead(state) == 1) { /* handle death */ }
265
+ ```
266
+
267
+ ---
268
+
269
+ ## `ecs_health_pct` <Badge type="info" text="v2.0.0" />
270
+
271
+ Return HP as a percentage in fixed-point ×10000 (e.g., `5000` = 50.00%).
272
+
273
+ ```redscript
274
+ fn ecs_health_pct(state: int[]): int
275
+ ```
276
+
277
+ **Parameters**
278
+
279
+ | Parameter | Description |
280
+ |-----------|-------------|
281
+ | `state` | Health component state |
282
+
283
+ **Returns:** `current_hp * 10000 / max_hp`, or `0` if max_hp is zero
284
+
285
+ **Example**
286
+
287
+ ```redscript
288
+ let pct: int = ecs_health_pct(state)
289
+ ```
290
+
291
+ ---
292
+
293
+ ## `ecs_vel_init` <Badge type="info" text="v2.0.0" />
294
+
295
+ Create a velocity component state with the given initial velocities.
296
+
297
+ ```redscript
298
+ fn ecs_vel_init(vx: int, vy: int, vz: int): int[]
299
+ ```
300
+
301
+ **Parameters**
302
+
303
+ | Parameter | Description |
304
+ |-----------|-------------|
305
+ | `vx` | X velocity ×1000 fixed-point (1000 = 1.0 block/tick) |
306
+ | `vy` | Y velocity ×1000 fixed-point |
307
+ | `vz` | Z velocity ×1000 fixed-point |
308
+
309
+ **Returns:** New 8-element velocity component state array
310
+
311
+ **Example**
312
+
313
+ ```redscript
314
+ let vel: int[] = ecs_vel_init(1000, 0, 500)
315
+ ```
316
+
317
+ ---
318
+
319
+ ## `ecs_vel_get_x` <Badge type="info" text="v2.0.0" />
320
+
321
+ Return X velocity from a velocity component state.
322
+
323
+ ```redscript
324
+ fn ecs_vel_get_x(state: int[]): int
325
+ ```
326
+
327
+ **Parameters**
328
+
329
+ | Parameter | Description |
330
+ |-----------|-------------|
331
+ | `state` | Velocity component state |
332
+
333
+ **Returns:** X velocity ×1000 fixed-point
334
+
335
+ ---
336
+
337
+ ## `ecs_vel_get_y` <Badge type="info" text="v2.0.0" />
338
+
339
+ Return Y velocity from a velocity component state.
340
+
341
+ ```redscript
342
+ fn ecs_vel_get_y(state: int[]): int
343
+ ```
344
+
345
+ **Parameters**
346
+
347
+ | Parameter | Description |
348
+ |-----------|-------------|
349
+ | `state` | Velocity component state |
350
+
351
+ **Returns:** Y velocity ×1000 fixed-point
352
+
353
+ ---
354
+
355
+ ## `ecs_vel_get_z` <Badge type="info" text="v2.0.0" />
356
+
357
+ Return Z velocity from a velocity component state.
358
+
359
+ ```redscript
360
+ fn ecs_vel_get_z(state: int[]): int
361
+ ```
362
+
363
+ **Parameters**
364
+
365
+ | Parameter | Description |
366
+ |-----------|-------------|
367
+ | `state` | Velocity component state |
368
+
369
+ **Returns:** Z velocity ×1000 fixed-point
370
+
371
+ ---
372
+
373
+ ## `ecs_vel_set` <Badge type="info" text="v2.0.0" />
374
+
375
+ Set all velocity components and return the updated state.
376
+
377
+ ```redscript
378
+ fn ecs_vel_set(state: int[], vx: int, vy: int, vz: int): int[]
379
+ ```
380
+
381
+ **Parameters**
382
+
383
+ | Parameter | Description |
384
+ |-----------|-------------|
385
+ | `state` | Velocity component state |
386
+ | `vx` | New X velocity ×1000 |
387
+ | `vy` | New Y velocity ×1000 |
388
+ | `vz` | New Z velocity ×1000 |
389
+
390
+ **Returns:** Updated state array
391
+
392
+ **Example**
393
+
394
+ ```redscript
395
+ state = ecs_vel_set(state, 500, 1200, 0)
396
+ ```
397
+
398
+ ---
399
+
400
+ ## `ecs_vel_speed` <Badge type="info" text="v2.0.0" />
401
+
402
+ Return the speed (magnitude) of the velocity vector ×1000.
403
+
404
+ Uses `sqrt_fixed` from `math.mcrs`. For example,
405
+ `ecs_vel_speed([3000, 4000, 0, ...])` returns approximately `5000`.
406
+
407
+ ```redscript
408
+ fn ecs_vel_speed(state: int[]): int
409
+ ```
410
+
411
+ **Parameters**
412
+
413
+ | Parameter | Description |
414
+ |-----------|-------------|
415
+ | `state` | Velocity component state |
416
+
417
+ **Returns:** `sqrt(vx² + vy² + vz²)` in ×1000 fixed-point
418
+
419
+ **Example**
420
+
421
+ ```redscript
422
+ let speed: int = ecs_vel_speed(vel_state)
423
+ ```
424
+
425
+ ---
426
+
427
+ ## `ecs_vel_apply_gravity` <Badge type="info" text="v2.0.0" />
428
+
429
+ Apply gravity by subtracting `gravity_fx` from the Y velocity each tick.
430
+
431
+ ```redscript
432
+ fn ecs_vel_apply_gravity(state: int[], gravity_fx: int): int[]
433
+ ```
434
+
435
+ **Parameters**
436
+
437
+ | Parameter | Description |
438
+ |-----------|-------------|
439
+ | `state` | Velocity component state |
440
+ | `gravity_fx` | Gravity acceleration ×1000 per tick (e.g. `980` ≈ 0.98 blocks/tick²) |
441
+
442
+ **Returns:** Updated state array
443
+
444
+ **Example**
445
+
446
+ ```redscript
447
+ vel_state = ecs_vel_apply_gravity(vel_state, 980)
448
+ ```
449
+
450
+ ---
451
+
452
+ ## `ecs_vel_damp` <Badge type="info" text="v2.0.0" />
453
+
454
+ Apply a friction damping factor to all velocity components.
455
+
456
+ ```redscript
457
+ fn ecs_vel_damp(state: int[], factor_fx: int): int[]
458
+ ```
459
+
460
+ **Parameters**
461
+
462
+ | Parameter | Description |
463
+ |-----------|-------------|
464
+ | `state` | Velocity component state |
465
+ | `factor_fx` | Friction factor ×10000 (e.g. `8000` = 0.80 damping) |
466
+
467
+ **Returns:** Updated state array with each component multiplied by `factor_fx/10000`
468
+
469
+ **Example**
470
+
471
+ ```redscript
472
+ vel_state = ecs_vel_damp(vel_state, 9000)
473
+ ```
474
+
475
+ ---