sapdon 3.2.2 → 3.3.3

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 (68) hide show
  1. package/README.md +245 -121
  2. package/doc/dev/architecture.md +415 -0
  3. package/doc/dev/cli.md +467 -0
  4. package/doc/dev/core.md +717 -0
  5. package/doc/dev/oc.md +582 -0
  6. package/doc/user/api/biome.md +558 -0
  7. package/doc/user/api/block.md +945 -0
  8. package/doc/user/api/entity.md +685 -0
  9. package/doc/user/api/extra.md +231 -0
  10. package/doc/user/api/item.md +896 -0
  11. package/doc/user/api/recipe.md +427 -0
  12. package/doc/user/api/texture.md +181 -0
  13. package/doc/user/config/build-config.md +84 -0
  14. package/doc/user/config/mod-info.md +33 -0
  15. package/doc/user/faq.md +160 -0
  16. package/doc/user/quick-start.md +108 -0
  17. package/doc/user/tutorials/block.md +463 -0
  18. package/doc/user/tutorials/entity.md +356 -0
  19. package/doc/user/tutorials/item.md +449 -0
  20. package/doc/user/tutorials/recipe.md +278 -0
  21. package/package.json +4 -3
  22. package/prod/cli/index.js +1 -1
  23. package/prod/cli/start.js +1 -1458
  24. package/prod/core/index.d.ts +3290 -2150
  25. package/prod/core/index.js +1 -59015
  26. package/prod/core/package.json +7 -0
  27. package/prod/oc/index.d.ts +348 -108
  28. package/prod/oc/index.js +1 -1
  29. package/prod/oc/package.json +7 -0
  30. package/prod/utils/index.d.ts +20 -2
  31. package/prod/utils/index.js +1 -1
  32. package/prod/utils/package.json +7 -0
  33. package/doc/BlockAPI.md +0 -145
  34. package/doc/api.md +0 -128
  35. package/doc/oc/index.md +0 -0
  36. package/doc/sapdon-ts.md +0 -64
  37. package/src/templates/js_sapdon/build.config +0 -23
  38. package/src/templates/js_sapdon/main.mjs +0 -4
  39. package/src/templates/js_sapdon/mod.info +0 -7
  40. package/src/templates/js_sapdon/pack_icon.png +0 -0
  41. package/src/templates/js_sapdon/package.json +0 -20
  42. package/src/templates/js_sapdon/res/animations/animation_item.animation.json +0 -34
  43. package/src/templates/js_sapdon/res/animations/large_item.animation.json +0 -27
  44. package/src/templates/js_sapdon/res/models/blocks/crop.geo.json +0 -48
  45. package/src/templates/js_sapdon/res/models/entity/animation/animation_item.geo.json +0 -26
  46. package/src/templates/js_sapdon/res/models/entity/animation/large_item.geo.json +0 -28
  47. package/src/templates/js_sapdon/res/textures/blocks/none.png +0 -0
  48. package/src/templates/js_sapdon/res/textures/blocks/test_log_oak.png +0 -0
  49. package/src/templates/js_sapdon/res/textures/blocks/test_log_top.png +0 -0
  50. package/src/templates/js_sapdon/res/textures/items/masterball.png +0 -0
  51. package/src/templates/js_sapdon/scripts/custom_components/cropComponent.js +0 -50
  52. package/src/templates/js_sapdon/scripts/custom_components/items/gui_book.js +0 -37
  53. package/src/templates/js_sapdon/scripts/custom_components/registry.js +0 -25
  54. package/src/templates/js_sapdon/scripts/index.js +0 -0
  55. package/src/templates/ts_sapdon/build.config +0 -23
  56. package/src/templates/ts_sapdon/main.ts +0 -11
  57. package/src/templates/ts_sapdon/mod.info +0 -7
  58. package/src/templates/ts_sapdon/pack_icon.png +0 -0
  59. package/src/templates/ts_sapdon/package.json +0 -20
  60. package/src/templates/ts_sapdon/res/models/blocks/crop.geo.json +0 -48
  61. package/src/templates/ts_sapdon/res/textures/blocks/test_log_oak.png +0 -0
  62. package/src/templates/ts_sapdon/res/textures/blocks/test_log_top.png +0 -0
  63. package/src/templates/ts_sapdon/res/textures/items/masterball.png +0 -0
  64. package/src/templates/ts_sapdon/scripts/components/cropComponent.ts +0 -44
  65. package/src/templates/ts_sapdon/scripts/components/items/guiBook.ts +0 -36
  66. package/src/templates/ts_sapdon/scripts/components/registry.ts +0 -24
  67. package/src/templates/ts_sapdon/scripts/index.ts +0 -7
  68. package/src/templates/ts_sapdon/tsconfig.json +0 -117
@@ -0,0 +1,685 @@
1
+ # 实体系统 API 参考
2
+
3
+ ## EntityAPI
4
+
5
+ `EntityAPI` 是实体工厂对象,包含四个创建方法,均返回 `{ behavior: BasicEntity, resource: ClientEntity }`。
6
+
7
+ ### `EntityAPI.createEntity(identifier, texture, options?, behData?, resData?)`
8
+
9
+ 创建普通自定义实体。
10
+
11
+ | 参数 | 类型 | 默认值 | 说明 |
12
+ |------|------|--------|------|
13
+ | identifier | string | — | 唯一标识符,如 `my_addon:my_entity` |
14
+ | texture | string | — | 纹理路径,如 `textures/entity/my_entity` |
15
+ | options | Object | `{}` | 可选配置,含 `is_spawnable`, `is_summonable`, `runtime_identifier` |
16
+ | behData | Object | `{}` | 继承的行为包数据 |
17
+ | resData | Object | `{}` | 继承的资源包数据 |
18
+
19
+ ```js
20
+ import { EntityAPI, registry } from '@sapdon/core'
21
+ const entity = EntityAPI.createEntity('my_addon:robot', 'textures/entity/robot', {
22
+ is_spawnable: true,
23
+ is_summonable: true
24
+ })
25
+ registry.submit()
26
+ ```
27
+
28
+ ### `EntityAPI.createNativeEntity(identifier, proto_id, options?)`
29
+
30
+ 基于原版实体创建变种,自动复制原版行为包与资源包数据,设置 `runtime_identifier`。
31
+
32
+ | 参数 | 类型 | 说明 |
33
+ |------|------|------|
34
+ | identifier | string | 新实体标识符 |
35
+ | proto_id | string | 原版实体 ID,如 `minecraft:zombie` |
36
+ | options | Object | 额外配置 |
37
+
38
+ ```js
39
+ const { behavior, resource } = EntityAPI.createNativeEntity(
40
+ 'my_addon:ice_zombie',
41
+ 'minecraft:zombie'
42
+ )
43
+ ```
44
+
45
+ ### `EntityAPI.createProjectile(identifier, texture, options?)`
46
+
47
+ 创建抛射物实体,基于 `minecraft:snowball` 原型。
48
+
49
+ ```js
50
+ const { behavior, resource } = EntityAPI.createProjectile(
51
+ 'my_addon:fire_ball',
52
+ 'textures/items/fire_ball'
53
+ )
54
+ ```
55
+
56
+ ### `EntityAPI.createDummyEntity(identifier, texture, options?, behData?, resData?)`
57
+
58
+ 创建无物理的虚拟实体,适用于标记点、GUI 实体等。自动禁用物理、碰撞、推动和伤害。
59
+
60
+ ```js
61
+ const { behavior, resource } = EntityAPI.createDummyEntity(
62
+ 'my_addon:waypoint',
63
+ 'textures/entity/none'
64
+ )
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Entity 类
70
+
71
+ 实体容器类,包含 `behavior` 和 `resource` 两个属性。
72
+
73
+ ```js
74
+ import { Entity } from '@sapdon/core'
75
+
76
+ const entity = new Entity('my_addon:entity', 'textures/entity/tex')
77
+ entity.behavior // BasicEntity 实例
78
+ entity.resource // ClientEntity 实例
79
+ ```
80
+
81
+ ### `entity.behavior` — BasicEntity 实例
82
+
83
+ 行为包操作入口。
84
+
85
+ ### `entity.resource` — ClientEntity 实例
86
+
87
+ 资源包操作入口。
88
+
89
+ ---
90
+
91
+ ## EntityComponent
92
+
93
+ 静态方法集合,每个方法返回 `Map` 对象。使用 `combineComponents` 可将多个 Map 合并。
94
+
95
+ ### `EntityComponent.setHealth({ max, value })`
96
+
97
+ 创建 `minecraft:health` 组件。`value` 可为数字或 `{ range_min, range_max }` 范围对象。
98
+
99
+ ```js
100
+ EntityComponent.setHealth({ max: 40, value: 40 })
101
+ EntityComponent.setHealth({ max: 30, value: { range_min: 20, range_max: 30 } })
102
+ ```
103
+
104
+ ### `EntityComponent.setPhysics(has_collision?, has_gravity?, push_towards_closest_space?)`
105
+
106
+ 创建 `minecraft:physics` 组件。默认 `true, true, false`。
107
+
108
+ ```js
109
+ EntityComponent.setPhysics(true, true) // 有碰撞,有重力
110
+ EntityComponent.setPhysics(false, false) // 无碰撞,无重力(用于 DummyEntity)
111
+ ```
112
+
113
+ ### `EntityComponent.setCollisionBox(width, height)`
114
+
115
+ 创建 `minecraft:collision_box` 组件。
116
+
117
+ ```js
118
+ EntityComponent.setCollisionBox(0.6, 1.9)
119
+ ```
120
+
121
+ ### `EntityComponent.setScale(value)`
122
+
123
+ 创建 `minecraft:scale` 组件。`value` 默认为 1.0。
124
+
125
+ ```js
126
+ EntityComponent.setScale(2.0)
127
+ ```
128
+
129
+ ### `EntityComponent.setPushable(isPushable?, isPushableByPiston?)`
130
+
131
+ 创建 `minecraft:pushable` 组件。默认 `true, true`。
132
+
133
+ ```js
134
+ EntityComponent.setPushable(false, false)
135
+ ```
136
+
137
+ ### `EntityComponent.setDamageSensor(deals_damage)`
138
+
139
+ 创建 `minecraft:damage_sensor` 组件。
140
+
141
+ ```js
142
+ EntityComponent.setDamageSensor(true)
143
+ EntityComponent.setDamageSensor(false)
144
+ ```
145
+
146
+ ### `EntityComponent.setMovement(speed)`
147
+
148
+ 创建 `minecraft:movement` 组件,设置移动速度。
149
+
150
+ ```js
151
+ EntityComponent.setMovement(0.25)
152
+ ```
153
+
154
+ ### `EntityComponent.setTypeFamily(family_arr)`
155
+
156
+ 创建 `minecraft:type_family` 组件,定义实体家族类型。
157
+
158
+ ```js
159
+ EntityComponent.setTypeFamily(['zombie', 'monster', 'undead'])
160
+ ```
161
+
162
+ ### `EntityComponent.setRideable(config)`
163
+
164
+ 创建 `minecraft:rideable` 组件,使实体可骑乘。
165
+
166
+ | 参数 | 类型 | 默认值 | 说明 |
167
+ |------|------|--------|------|
168
+ | controllingSeat | number | 1 | 控制座位编号 |
169
+ | crouchingSkipInteract | boolean | true | 潜行跳过交互 |
170
+ | familyTypes | string[] | `['player']` | 可骑乘的实体家族 |
171
+ | interactText | string | 'drive' | 交互文本 |
172
+ | seatCount | number | — | 座位数量 |
173
+ | seats | Array | — | 座位配置 |
174
+ | passengerMaxWidth | number | — | 乘客最大宽度 |
175
+ | pullInEntities | boolean | — | 是否拉入实体 |
176
+
177
+ ```js
178
+ EntityComponent.setRideable({
179
+ seatCount: 2,
180
+ seats: [
181
+ { position: [0, 0.5, 0] },
182
+ { position: [0, 0.5, -0.5] }
183
+ ]
184
+ })
185
+ ```
186
+
187
+ ### `EntityComponent.setNavigationWalk(options)`
188
+
189
+ 创建 `minecraft:navigation.walk` 组件,配置步行寻路。
190
+
191
+ ```js
192
+ EntityComponent.setNavigationWalk({
193
+ canWalk: true,
194
+ canSwim: true,
195
+ canJump: true,
196
+ canBreakDoors: false,
197
+ avoidWater: false,
198
+ canFloat: true
199
+ })
200
+ ```
201
+
202
+ ### `EntityComponent.setProjectile(options)`
203
+
204
+ 创建 `minecraft:projectile` 组件,配置抛射物属性。
205
+
206
+ | 参数 | 类型 | 默认值 | 说明 |
207
+ |------|------|--------|------|
208
+ | gravity | number | 0.05 | 重力 |
209
+ | power | number | 1.3 | 初速度 |
210
+ | inertia | number | 0.99 | 空气惯性 |
211
+ | knockback | boolean | true | 是否击退 |
212
+ | homing | boolean | false | 是否追踪 |
213
+ | lightning | boolean | false | 是否召唤闪电 |
214
+ | shouldBounce | boolean | false | 是否反弹 |
215
+ | hitSound | string | — | 命中音效 |
216
+ | particle | string | 'ironcrack' | 碰撞粒子 |
217
+
218
+ ```js
219
+ EntityComponent.setProjectile({
220
+ gravity: 0.05,
221
+ power: 2.0,
222
+ knockback: true,
223
+ on_hit: { impact_damage: { damage: 10 } }
224
+ })
225
+ ```
226
+
227
+ ### `EntityComponent.setJumpStatic(jumpPower?)`
228
+
229
+ 创建 `minecraft:jump.static` 组件,默认跳跃力 0.42。
230
+
231
+ ```js
232
+ EntityComponent.setJumpStatic(0.5)
233
+ ```
234
+
235
+ ### `EntityComponent.setMovementBasic(maxTurn?)`
236
+
237
+ 创建 `minecraft:movement.basic` 组件,默认最大转向角 30.0。
238
+
239
+ ```js
240
+ EntityComponent.setMovementBasic(30.0)
241
+ ```
242
+
243
+ ### `EntityComponent.setCustomHitTest(hitboxes)`
244
+
245
+ 创建 `minecraft:custom_hit_test` 组件,用于自定义命中框。
246
+
247
+ ```js
248
+ EntityComponent.setCustomHitTest([
249
+ { pivot: [0, 100, 0], width: 0, height: 0 }
250
+ ])
251
+ ```
252
+
253
+ ### `EntityComponent.setMobEffect({ effect, range?, duration?, cooldown?, filter? })`
254
+
255
+ 创建 `minecraft:mob_effect` 组件。
256
+
257
+ ```js
258
+ EntityComponent.setMobEffect({
259
+ effect: 'minecraft:poison',
260
+ range: 0.2,
261
+ duration: 10
262
+ })
263
+ ```
264
+
265
+ ### `EntityComponent.setItemControllable(controlItems)`
266
+
267
+ 创建 `minecraft:item_controllable` 组件。
268
+
269
+ ```js
270
+ EntityComponent.setItemControllable('carrotOnAStick')
271
+ EntityComponent.setItemControllable(['carrotOnAStick', 'warped_fungus_on_a_stick'])
272
+ ```
273
+
274
+ ### `EntityComponent.setEquipment({ table?, slotDropChance? })`
275
+
276
+ 创建 `minecraft:equipment` 组件,配置装备掉落。
277
+
278
+ ```js
279
+ EntityComponent.setEquipment({
280
+ table: 'loot_tables/entities/skeleton_gear.json'
281
+ })
282
+
283
+ EntityComponent.setEquipment({
284
+ slotDropChance: [
285
+ { slot: 'slot.weapon.mainhand', dropChance: 1 }
286
+ ]
287
+ })
288
+ ```
289
+
290
+ ### `EntityComponent.setInventoryProperties(options)`
291
+
292
+ 创建 `minecraft:inventory` 组件。
293
+
294
+ | 参数 | 类型 | 说明 |
295
+ |------|------|------|
296
+ | additionalSlotsPerStrength | number | 每力量值增加的额外槽位 |
297
+ | canBeSiphonedFrom | boolean | 是否允许漏斗抽取 |
298
+ | containerType | string | 容器类型 |
299
+ | inventorySize | number | 库存槽位数 |
300
+ | isPrivate | boolean | 死亡是否掉落 |
301
+ | restrictToOwner | boolean | 仅所有者可访问 |
302
+
303
+ ```js
304
+ EntityComponent.setInventoryProperties({
305
+ inventorySize: 18,
306
+ containerType: 'minecart_chest'
307
+ })
308
+ ```
309
+
310
+ ### `EntityComponent.combineComponents(...componentMaps)`
311
+
312
+ 合并多个 `Map` 组件为一个 `Map`,方便一次添加。
313
+
314
+ ```js
315
+ EntityComponent.combineComponents(
316
+ EntityComponent.setHealth({ max: 20, value: 20 }),
317
+ EntityComponent.setMovement(0.25)
318
+ )
319
+ ```
320
+
321
+ ### 其他辅助方法
322
+
323
+ | 方法 | 说明 |
324
+ |------|------|
325
+ | `setIsStackable()` | 实体可堆叠 |
326
+ | `setGroupSize(radius?, filter?)` | 群体大小检测 |
327
+ | `setEquipItem(options?)` | 装备物品行为 |
328
+ | `setFireImmune(value?)` | 火焰免疫 |
329
+ | `setGrowsCrop({ chance?, charges? })` | 促进作物生长 |
330
+ | `setInstantDespawn({ removeChildEntities? })` | 立即消失 |
331
+ | `setInsideBlockNotifier(blockList)` | 方块内部通知器 |
332
+ | `setDefaultNameable()` | 可命名(默认配置) |
333
+ | `setCustomNameable(allowNameTagRenaming?, alwaysShow?, defaultTrigger?, nameActions?)` | 可命名(自定义) |
334
+ | `setInputGroundControlled()` | 地面输入控制 |
335
+ | `setVariableMaxAutoStep(base?, controlled?, jumpPrevented?)` | 可变自动踏步 |
336
+
337
+ ---
338
+
339
+ ## AI Behavior 类
340
+
341
+ 所有行为类实现 `toObject()` 方法,返回 `Map`,可直接传入 `addComponent()`。
342
+
343
+ ### NearestAttackableTargetBehavor
344
+
345
+ 选择最近的可攻击目标。
346
+
347
+ ```js
348
+ new NearestAttackableTargetBehavor(priority, entity_types)
349
+ .setMustReach(true) // 需要到达目标位置
350
+ .setMustSee(true) // 需要看见目标
351
+ .toObject()
352
+ ```
353
+
354
+ **参数**
355
+ - `priority` (number) — 优先级
356
+ - `entity_types` (Object) — 实体过滤器,如 `{ filters: { test: 'is_family', value: 'player' } }`
357
+
358
+ ### TemptBehavior
359
+
360
+ 使用物品吸引实体跟随。
361
+
362
+ ```js
363
+ new TemptBehavior(priority)
364
+ .setItems(['minecraft:wheat']) // 吸引物品列表
365
+ .setSpeedMultiplier(1.2) // 移动速度倍率
366
+ .canGetScared(true) // 是否会被吓跑
367
+ .canTemptVertically(false) // 是否考虑垂直距离
368
+ .canTemptWhileRidden(false) // 骑乘时是否受影响
369
+ .setWithinRadius(10) // 吸引半径
370
+ .setTemptSound('mob.sheep.say') // 吸引音效
371
+ .setSoundInterval(2, 5) // 音效随机间隔
372
+ .toObject()
373
+ ```
374
+
375
+ ### RandomStrollBehavior
376
+
377
+ 随机漫步行为。
378
+
379
+ ```js
380
+ new RandomStrollBehavior(priority, interval, speed_multiplier)
381
+ .setXZDist(10) // 水平移动范围
382
+ .setYDist(7) // 垂直移动范围
383
+ .toObject()
384
+ ```
385
+
386
+ **参数**
387
+ - `priority` (number) — 优先级
388
+ - `interval` (number) — 移动间隔(游戏刻)
389
+ - `speed_multiplier` (number) — 速度倍率
390
+
391
+ ### PickupItemsBehavior
392
+
393
+ 拾取物品行为(类似 Allay / Drowned)。
394
+
395
+ ```js
396
+ new PickupItemsBehavior(priority)
397
+ .setCanPickupAnyItem(true) // 是否拾取任意物品
398
+ .setCanPickupToHandOrEquipment(true) // 是否拾取到手中/装备栏
399
+ .setCooldownAfterBeingAttacked(100) // 被攻击后冷却
400
+ .setExcludedItems(['minecraft:glow_ink_sac']) // 排除的物品
401
+ .setGoalRadius(0.5) // 判定半径
402
+ .setMaxDist(32) // 最大搜索距离
403
+ .setPickupBasedOnChance(false) // 随机拾取
404
+ .setPickupSameItemsAsInHand(true) // 仅拾取相同物品
405
+ .setSearchHeight(16) // 垂直搜索范围
406
+ .setSpeedMultiplier(4.0) // 速度倍率
407
+ .setTrackTarget(true) // 追踪目标
408
+ .toObject()
409
+ ```
410
+
411
+ ### FollowParentBehavior
412
+
413
+ 幼年实体跟随成年实体。
414
+
415
+ ```js
416
+ new FollowParentBehavior(priority)
417
+ .setSpeedMultiplier(1.1)
418
+ .toObject()
419
+ ```
420
+
421
+ ### FollowMobBehavior
422
+
423
+ 跟随其他生物。
424
+
425
+ ```js
426
+ new FollowMobBehavior(priority)
427
+ .setSearchRange(10) // 搜索范围
428
+ .setSpeedMultiplier(1.5) // 速度倍率
429
+ .setStopDistance(2.0) // 停止距离
430
+ .toObject()
431
+ ```
432
+
433
+ ---
434
+
435
+ ## BasicEntity
436
+
437
+ 行为包实体操作类,通过 `EntityAPI` 返回的 `.behavior` 访问。
438
+
439
+ ### `basicEntity.addProperty(id, { type, range, default })`
440
+
441
+ 添加实体属性(定义在实体 description 的 properties 中)。
442
+
443
+ ```js
444
+ behavior.addProperty('my_addon:level', {
445
+ type: 'int',
446
+ range: [1, 100],
447
+ default: 1
448
+ })
449
+ ```
450
+
451
+ ### `basicEntity.addEvent(name, eventMap)`
452
+
453
+ 添加事件。`eventMap` 必须是 `Map` 实例,键为 `'add'` / `'remove'`,值为 `{ component_groups: [...] }`。
454
+
455
+ ```js
456
+ behavior.addEvent('my_addon:transform', new Map([
457
+ ['add', { component_groups: ['group_a'] }],
458
+ ['remove', { component_groups: ['group_b'] }]
459
+ ]))
460
+ ```
461
+
462
+ ### `basicEntity.addComponentGroup(name, componentMap)`
463
+
464
+ 添加组件组。`componentMap` 必须是 `Map` 实例。
465
+
466
+ ```js
467
+ behavior.addComponentGroup('my_addon:enraged', new Map([
468
+ ...EntityComponent.combineComponents(
469
+ EntityComponent.setMovement(0.5),
470
+ new Map([['minecraft:attack', { damage: 15 }]])
471
+ )
472
+ ]))
473
+ ```
474
+
475
+ ### `basicEntity.addComponent(componentMap)`
476
+
477
+ 添加组件。`componentMap` 必须是 `Map` 或行为类的 `toObject()` 返回值。
478
+
479
+ ```js
480
+ behavior.addComponent(EntityComponent.setHealth({ max: 20, value: 20 }))
481
+ behavior.addComponent(new TemptBehavior(3).setItems(['minecraft:wheat']).toObject())
482
+ ```
483
+
484
+ ### `basicEntity.removeComponent(key)`
485
+
486
+ 删除组件。
487
+
488
+ ```js
489
+ behavior.removeComponent('minecraft:health')
490
+ ```
491
+
492
+ ### 其他方法
493
+
494
+ | 方法 | 说明 |
495
+ |------|------|
496
+ | `removeProperty(name)` | 删除属性 |
497
+ | `clearProperties()` | 清除所有属性 |
498
+ | `removeEvent(name)` | 删除事件 |
499
+ | `clearEvents()` | 清除所有事件 |
500
+ | `removeComponentGroup(name)` | 删除组件组 |
501
+ | `clearComponentGroups()` | 清除所有组件组 |
502
+ | `clearComponents()` | 清除所有组件 |
503
+ | `clearAll()` | 清除全部数据 |
504
+
505
+ ---
506
+
507
+ ## ClientEntity
508
+
509
+ 客户端实体类(继承自 `AddonClientEntityDescription`),通过 `EntityAPI` 返回的 `.resource` 访问。
510
+
511
+ ### `clientEntity.addTexture(name, path)`
512
+
513
+ 添加纹理映射。
514
+
515
+ ```js
516
+ resource.addTexture('default', 'textures/entity/my_entity')
517
+ ```
518
+
519
+ ### `clientEntity.addMaterial(name, material)`
520
+
521
+ 添加材质。
522
+
523
+ ```js
524
+ resource.addMaterial('default', 'entity_alphatest')
525
+ ```
526
+
527
+ ### `clientEntity.addGeometry(name, geometry)`
528
+
529
+ 添加几何体模型。
530
+
531
+ ```js
532
+ resource.addGeometry('default', 'geometry.my_entity')
533
+ ```
534
+
535
+ ### `clientEntity.addAnimation(name, animation)`
536
+
537
+ 添加动画。
538
+
539
+ ```js
540
+ resource.addAnimation('walk', 'animation.my_entity.walk')
541
+ resource.addAnimation('attack', 'animation.my_entity.attack')
542
+ ```
543
+
544
+ ### `clientEntity.addAnimationController(name, controller)`
545
+
546
+ 添加动画控制器。
547
+
548
+ ```js
549
+ resource.addAnimationController('controller', 'controller.animation.my_entity')
550
+ ```
551
+
552
+ ### `clientEntity.addRenderController(controller)`
553
+
554
+ 添加渲染控制器。
555
+
556
+ ```js
557
+ resource.addRenderController('controller.render.my_entity')
558
+ ```
559
+
560
+ ### `clientEntity.addParticleEffect(name, particle)`
561
+
562
+ 添加粒子效果。
563
+
564
+ ```js
565
+ resource.addParticleEffect('flame', 'my_addon:flame_particle')
566
+ ```
567
+
568
+ ### `clientEntity.addLocator(name, position)`
569
+
570
+ 添加定位器(用于附着点)。
571
+
572
+ ```js
573
+ resource.addLocator('lead', [0.0, 1.0, 0.0])
574
+ ```
575
+
576
+ ### `clientEntity.setSpawnEgg(texture, texture_index)`
577
+
578
+ 设置生成蛋。
579
+
580
+ ```js
581
+ resource.setSpawnEgg('textures/entity/spawn_egg', 0)
582
+ ```
583
+
584
+ ### `clientEntity.setScript(key, value)`
585
+
586
+ 设置脚本(如 `pre_animation`、`animate`、`scale` 等)。
587
+
588
+ ```js
589
+ resource.setScript('pre_animation', [
590
+ 'variable.tcos = Math.cos(query.life_time * 45.8)'
591
+ ])
592
+ resource.setScript('animate', ['walk', 'attack'])
593
+ ```
594
+
595
+ ---
596
+
597
+ ## DummyEntity
598
+
599
+ 无物理虚拟实体。继承自 `Entity`,预设以下配置:
600
+
601
+ - `minecraft:physics` — `has_collision: false`, `has_gravity: false`
602
+ - `minecraft:pushable` — `is_pushable: false`, `is_pushable_by_piston: false`
603
+ - `minecraft:collision_box` — `width: 0.001, height: 0.001`
604
+ - `minecraft:damage_sensor` — `deals_damage: false`
605
+ - `minecraft:custom_hit_test` — 空命中框
606
+
607
+ ```js
608
+ import { DummyEntity } from '@sapdon/core'
609
+
610
+ const dummy = new DummyEntity('my_addon:dummy', 'textures/entity/none')
611
+ ```
612
+
613
+ ---
614
+
615
+ ## Projectile
616
+
617
+ 抛射物实体。继承自 `NativeEntity`,基于 `minecraft:snowball`。
618
+
619
+ ```js
620
+ import { Projectile } from '@sapdon/core'
621
+
622
+ const proj = new Projectile('my_addon:fireball', 'textures/items/fireball')
623
+ ```
624
+
625
+ ---
626
+
627
+ ## NativeEntity
628
+
629
+ 原生实体。基于原版实体创建变种,自动从内置数据源加载原版行为包与资源包数据。
630
+
631
+ ```js
632
+ import { NativeEntity } from '@sapdon/core'
633
+
634
+ const native = new NativeEntity(
635
+ 'my_addon:cold_zombie',
636
+ 'minecraft:zombie',
637
+ {}
638
+ )
639
+ // native.behavior — 基本实体,包含原版所有组件
640
+ // native.resource — 客户端实体,包含原版纹理、模型等
641
+ ```
642
+
643
+ ---
644
+
645
+ ## Component Bundles
646
+
647
+ ### BasicMovementBundle
648
+
649
+ 预配置的移动组件捆绑包,包含 `minecraft:movement`(速度 0.2)和 `minecraft:movement.basic`。
650
+
651
+ ```js
652
+ import { BasicMovementBundle } from '@sapdon/core'
653
+
654
+ behavior.addComponent(BasicMovementBundle.serialize())
655
+ ```
656
+
657
+ ### BasicBundle
658
+
659
+ 自定义组件捆绑包容器。
660
+
661
+ ```js
662
+ import { BasicBundle, EntityComponent } from '@sapdon/core'
663
+
664
+ const myBundle = new BasicBundle()
665
+ myBundle.addComponent(EntityComponent.setHealth({ max: 50, value: 50 }))
666
+ myBundle.addComponent(
667
+ EntityComponent.combineComponents(
668
+ EntityComponent.setMovement(0.3),
669
+ EntityComponent.setJumpStatic(0.5)
670
+ )
671
+ )
672
+
673
+ behavior.addComponent(myBundle.serialize())
674
+ ```
675
+
676
+ ```js
677
+ // 批量添加
678
+ myBundle.addComponents([
679
+ EntityComponent.setCollisionBox(0.6, 1.9),
680
+ EntityComponent.setScale(1.2)
681
+ ])
682
+
683
+ // 删除组件
684
+ myBundle.removeComponent('minecraft:scale')
685
+ ```