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,896 @@
1
+ # 物品系统 API 参考
2
+
3
+ 本文档提供 sapdon 框架中物品系统的完整 API 参考。
4
+
5
+ ---
6
+
7
+ ## 目录
8
+
9
+ 1. [ItemAPI](#1-itemapi)
10
+ 2. [Item 类](#2-item-类)
11
+ 3. [ItemComponent](#3-itemcomponent)
12
+ 4. [Armor 子类](#4-armor-子类)
13
+ 5. [Food 类](#5-food-类)
14
+ 6. [ItemCategory 枚举](#6-itemcategory-枚举)
15
+ 7. [Attachable 类](#7-attachable-类)
16
+ 8. [注册流程](#8-注册流程)
17
+
18
+ ---
19
+
20
+ ## 1. ItemAPI
21
+
22
+ `ItemAPI` 是一个工厂对象,提供创建各种类型物品的静态方法。所有创建方法会自动调用 `GRegistry.register()` 注册物品到游戏。
23
+
24
+ ### createItem()
25
+
26
+ 创建普通物品。
27
+
28
+ ```typescript
29
+ import { ItemAPI, ItemCategory } from '@sapdon/core'
30
+
31
+ const item = ItemAPI.createItem(
32
+ 'my_mod:simple_item', // identifier: string — 唯一标识符(命名空间:名称)
33
+ ItemCategory.Items, // category: string — 创造菜单分类
34
+ 'my_texture', // texture: string — 纹理名称
35
+ { // options?: object — 可选配置
36
+ group: 'minecraft:itemGroup.name.ingredients',
37
+ hide_in_command: false, // 是否在命令中隐藏
38
+ max_stack_size: 64, // 最大堆叠数量
39
+ format_version: '1.21.40', // 格式版本
40
+ }
41
+ )
42
+ ```
43
+
44
+ **参数:**
45
+
46
+ | 参数 | 类型 | 必填 | 描述 |
47
+ |------|------|------|------|
48
+ | `identifier` | string | 是 | 物品唯一标识符,格式 `namespace:name` |
49
+ | `category` | string | 是 | 创造模式物品栏分类 |
50
+ | `texture` | string | 是 | 纹理名称 |
51
+ | `options.group` | string | 否 | 物品分组 |
52
+ | `options.hide_in_command` | boolean | 否 | 是否在命令自动补全中隐藏(默认 false)。为 true 时自动创建附加物。 |
53
+ | `options.max_stack_size` | number | 否 | 最大堆叠数量(默认 64,范围 1-99) |
54
+ | `options.format_version` | string | 否 | 格式版本(默认 `'1.21.40'`) |
55
+
56
+ **返回值:** `Item` — 创建的物品实例。
57
+
58
+ ---
59
+
60
+ ### createFood()
61
+
62
+ 创建食物物品。
63
+
64
+ ```typescript
65
+ import { ItemAPI, ItemCategory } from '@sapdon/core'
66
+
67
+ const food = ItemAPI.createFood(
68
+ 'my_mod:magic_apple', // identifier: string
69
+ ItemCategory.Items, // category: string
70
+ 'magic_apple', // texture: string
71
+ {
72
+ group: 'minecraft:itemGroup.name.food',
73
+ hide_in_command: false,
74
+ animation: 'eat', // 使用动画('eat' | 'drink')
75
+ canAlwaysEat: false, // 是否可随时食用
76
+ nutrition: 6, // 营养值
77
+ saturationModifier: 1.2, // 饱和度修正值
78
+ movement: 1, // 移动速度修正
79
+ useDuration: 1, // 使用时间(秒)
80
+ }
81
+ )
82
+ ```
83
+
84
+ **参数:**
85
+
86
+ | 参数 | 类型 | 默认值 | 描述 |
87
+ |------|------|--------|------|
88
+ | `identifier` | string | — | 唯一标识符 |
89
+ | `category` | string | — | 创造菜单分类 |
90
+ | `texture` | string | — | 纹理名称 |
91
+ | `options.group` | string | `undefined` | 物品分组 |
92
+ | `options.hide_in_command` | boolean | `false` | 是否在命令中隐藏 |
93
+ | `options.animation` | string | `'eat'` | 食用动画 |
94
+ | `options.canAlwaysEat` | boolean | `false` | 是否可随时食用 |
95
+ | `options.nutrition` | number | `0` | 营养值(非负) |
96
+ | `options.saturationModifier` | number | `1` | 饱和度修正(正数) |
97
+ | `options.movement` | number | `1` | 食用时移动速度缩放 |
98
+ | `options.useDuration` | number | `1` | 食用所需时间(秒) |
99
+
100
+ **返回值:** `Food` — 创建的食物物品实例。
101
+
102
+ ---
103
+
104
+ ### createAttachable()
105
+
106
+ 创建可附着物(用于手持 3D 模型或穿戴物品)。
107
+
108
+ ```typescript
109
+ import { ItemAPI } from '@sapdon/core'
110
+
111
+ const attachable = ItemAPI.createAttachable(
112
+ 'my_mod:special_item', // identifier: string
113
+ 'textures/items/special_item', // texture: string — 纹理路径
114
+ 'entity_alphatest', // material: string — 材质类型
115
+ // options?: object — 当前未使用额外选项
116
+ )
117
+
118
+ // 进一步配置
119
+ attachable
120
+ .addGeometry('default', 'geometry.special_item')
121
+ .addTexture('enchanted', 'textures/misc/enchanted_item_glint')
122
+ .addRenderController('controller.render.special_item')
123
+ ```
124
+
125
+ **参数:**
126
+
127
+ | 参数 | 类型 | 必填 | 描述 |
128
+ |------|------|------|------|
129
+ | `identifier` | string | 是 | 唯一标识符 |
130
+ | `texture` | string | 是 | 纹理路径(如 `'textures/items/my_item'`) |
131
+ | `material` | string | 是 | 材质类型(如 `'entity_alphatest'`、`'armor'`) |
132
+ | `options` | object | 否 | 预留扩展参数 |
133
+
134
+ **返回值:** `Attachable` — 可附着物实例。
135
+
136
+ ---
137
+
138
+ ### createChestplateArmor()
139
+
140
+ 创建胸甲盔甲。
141
+
142
+ ```typescript
143
+ import { ItemAPI } from '@sapdon/core'
144
+
145
+ const chestplate = ItemAPI.createChestplateArmor(
146
+ 'my_mod:ruby_chestplate', // identifier: string
147
+ 'ruby_chestplate', // item_texture: string — 物品图标纹理
148
+ 'textures/models/armor/ruby', // texture_path: string — 模型纹理路径
149
+ { // options?: object
150
+ // 可传入标准选项
151
+ }
152
+ )
153
+ ```
154
+
155
+ **返回值:** `Chestplate` — 胸甲实例。
156
+
157
+ ---
158
+
159
+ ### createHelmetArmor()
160
+
161
+ 创建头盔盔甲。
162
+
163
+ ```typescript
164
+ const helmet = ItemAPI.createHelmetArmor(
165
+ 'my_mod:ruby_helmet',
166
+ 'ruby_helmet',
167
+ 'textures/models/armor/ruby'
168
+ )
169
+ ```
170
+
171
+ **返回值:** `Helmet` — 头盔实例。
172
+
173
+ ---
174
+
175
+ ### createBootArmor()
176
+
177
+ 创建靴子盔甲。
178
+
179
+ ```typescript
180
+ const boots = ItemAPI.createBootArmor(
181
+ 'my_mod:ruby_boots',
182
+ 'ruby_boots',
183
+ 'textures/models/armor/ruby'
184
+ )
185
+ ```
186
+
187
+ **返回值:** `Boot` — 靴子实例。
188
+
189
+ ---
190
+
191
+ ### createLeggingsArmor()
192
+
193
+ 创建护腿盔甲。
194
+
195
+ ```typescript
196
+ const leggings = ItemAPI.createLeggingsArmor(
197
+ 'my_mod:ruby_leggings',
198
+ 'ruby_leggings',
199
+ 'textures/models/armor/ruby'
200
+ )
201
+ ```
202
+
203
+ **返回值:** `Leggings` — 护腿实例。
204
+
205
+ ---
206
+
207
+ ### createFlipbookItem()
208
+
209
+ 创建翻书物品(动态帧动画物品)。
210
+
211
+ ```typescript
212
+ import { ItemAPI } from '@sapdon/core'
213
+
214
+ const flipbook = ItemAPI.createFlipbookItem(
215
+ 'my_mod:animated_block', // identifier: string
216
+ 'construction', // category: string
217
+ 'my_flipbook_tex', // texture: string — 纹理名称
218
+ {
219
+ group: 'minecraft:itemGroup.name.construction',
220
+ hide_in_command: false,
221
+ ticks_per_frame: 8, // 每帧持续刻数(默认 8,1秒=20刻)
222
+ max_stack_size: 64,
223
+ format_version: '1.21.40',
224
+ }
225
+ )
226
+ ```
227
+
228
+ **参数:**
229
+
230
+ | 参数 | 类型 | 默认值 | 描述 |
231
+ |------|------|--------|------|
232
+ | `identifier` | string | — | 唯一标识符 |
233
+ | `category` | string | — | 创造菜单分类 |
234
+ | `texture` | string | — | 纹理名称(位于 `textures/blocks/` 目录) |
235
+ | `options.group` | string | `undefined` | 物品分组 |
236
+ | `options.hide_in_command` | boolean | `false` | 是否在命令中隐藏 |
237
+ | `options.ticks_per_frame` | number | `8` | 每帧持续刻数 |
238
+ | `options.max_stack_size` | number | `64` | 最大堆叠数量 |
239
+ | `options.format_version` | string | `'1.21.40'` | 格式版本 |
240
+
241
+ **返回值:** `FlipbookItem` — 翻书物品实例。可通过 `.block` 属性访问关联的 `GeometryBlock`。
242
+
243
+ ---
244
+
245
+ ## 2. Item 类
246
+
247
+ `Item` 是所有物品类型的基类,提供组件管理和序列化功能。
248
+
249
+ ### 构造函数
250
+
251
+ ```typescript
252
+ import { Item } from '@sapdon/core'
253
+
254
+ const item = new Item(
255
+ 'my_mod:custom_item', // identifier: string — 唯一标识符
256
+ 'items', // category: string — 创造菜单分类
257
+ 'custom_texture', // texture: string — 纹理名称
258
+ { // options?: object
259
+ group: '...',
260
+ hide_in_command: false,
261
+ max_stack_size: 64,
262
+ format_version: '1.21.40',
263
+ }
264
+ )
265
+ ```
266
+
267
+ **参数:**
268
+
269
+ | 参数 | 类型 | 默认值 | 描述 |
270
+ |------|------|--------|------|
271
+ | `identifier` | string | — | 唯一标识符 |
272
+ | `category` | string | — | 创造菜单分类 |
273
+ | `texture` | string | — | 纹理名称 |
274
+ | `options.group` | string | `undefined` | 分组 |
275
+ | `options.hide_in_command` | boolean | `false` | 是否在命令中隐藏 |
276
+ | `options.max_stack_size` | number | `64` | 最大堆叠数量 |
277
+ | `options.format_version` | string | `'1.21.40'` | 格式版本 |
278
+
279
+ 构造函数自动添加 `minecraft:icon` 和 `minecraft:max_stack_size` 组件。
280
+
281
+ ### 方法
282
+
283
+ #### addComponent(componentMap)
284
+
285
+ 添加一个或多个组件到物品。
286
+
287
+ ```typescript
288
+ item.addComponent(
289
+ ItemComponent.setDisplayName('自定义物品')
290
+ )
291
+
292
+ // 或合并多个组件
293
+ item.addComponent(
294
+ ItemComponent.combineComponents(
295
+ ItemComponent.setHandEquipped(true),
296
+ ItemComponent.setDurability(100),
297
+ )
298
+ )
299
+ ```
300
+
301
+ | 参数 | 类型 | 描述 |
302
+ |------|------|------|
303
+ | `componentMap` | Map | 组件 Map 对象 |
304
+
305
+ **返回值:** `this` — 支持链式调用。
306
+
307
+ ---
308
+
309
+ #### removeComponent(key)
310
+
311
+ 移除指定组件。
312
+
313
+ ```typescript
314
+ item.removeComponent('minecraft:icon') // 移除图标组件
315
+ ```
316
+
317
+ | 参数 | 类型 | 描述 |
318
+ |------|------|------|
319
+ | `key` | string | 要移除的组件名称 |
320
+
321
+ **返回值:** `this` — 支持链式调用。
322
+
323
+ ---
324
+
325
+ #### toObject()
326
+
327
+ 将物品转换为 JSON 对象(使用 `@Serializer` 装饰器),用于生成物品定义文件。
328
+
329
+ ```typescript
330
+ const json = item.toObject()
331
+ // 输出格式:
332
+ // {
333
+ // format_version: '1.21.40',
334
+ // 'minecraft:item': {
335
+ // description: { identifier, menu_category },
336
+ // components: { ... }
337
+ // }
338
+ // }
339
+ ```
340
+
341
+ **返回值:** `object` — 序列化后的物品定义对象。
342
+
343
+ ---
344
+
345
+ ## 3. ItemComponent
346
+
347
+ `ItemComponent` 提供静态方法,用于构建 `minecraft:item` 的组件 Map。每个方法返回一个 `Map<string, any>`。
348
+
349
+ ### setIcon(texture)
350
+
351
+ 设置物品图标纹理。
352
+
353
+ ```typescript
354
+ ItemComponent.setIcon('my_texture')
355
+ // → Map { 'minecraft:icon' => 'my_texture' }
356
+ ```
357
+
358
+ | 参数 | 类型 | 描述 |
359
+ |------|------|------|
360
+ | `texture` | string | 纹理名称 |
361
+
362
+ ---
363
+
364
+ ### setMaxStackSize(size)
365
+
366
+ 设置最大堆叠数量。
367
+
368
+ ```typescript
369
+ ItemComponent.setMaxStackSize(16)
370
+ // → Map { 'minecraft:max_stack_size' => 16 }
371
+ ```
372
+
373
+ | 参数 | 类型 | 默认值 | 描述 |
374
+ |------|------|--------|------|
375
+ | `size` | number | `64` | 最大堆叠数量(正整数) |
376
+
377
+ ---
378
+
379
+ ### setDisplayName(name)
380
+
381
+ 设置物品显示名称。
382
+
383
+ ```typescript
384
+ ItemComponent.setDisplayName('§c传奇之剑')
385
+ // → Map { 'minecraft:display_name' => { value: '§c传奇之剑' } }
386
+ ```
387
+
388
+ | 参数 | 类型 | 描述 |
389
+ |------|------|------|
390
+ | `name` | string | 显示名称(支持 § 颜色代码) |
391
+
392
+ ---
393
+
394
+ ### setFoodComponent(nutrition, saturation, canAlwaysEat?, usingConvertsTo?)
395
+
396
+ 设置食物属性组件。
397
+
398
+ ```typescript
399
+ ItemComponent.setFoodComponent(true, 6, 1.2)
400
+ // → Map { 'minecraft:food' => { can_always_eat: true, nutrition: 6, saturation_modifier: 1.2 } }
401
+ ```
402
+
403
+ | 参数 | 类型 | 默认值 | 描述 |
404
+ |------|------|--------|------|
405
+ | `canAlwaysEat` | boolean | — | 是否可随时食用 |
406
+ | `nutrition` | number | `0` | 营养值 |
407
+ | `saturationModifier` | number | `0.6` | 饱和度修正值 |
408
+ | `usingConvertsTo` | string | `undefined` | 食用后转换的目标物品 ID |
409
+
410
+ ---
411
+
412
+ ### setWearable(slot, protection)
413
+
414
+ 设置可穿戴组件。
415
+
416
+ ```typescript
417
+ // 头盔
418
+ ItemComponent.setWearable(3, 'slot.armor.head')
419
+ // 胸甲
420
+ ItemComponent.setWearable(5, 'slot.armor.chest')
421
+ // 护腿
422
+ ItemComponent.setWearable(6, 'slot.armor.legs')
423
+ // 靴子
424
+ ItemComponent.setWearable(4, 'slot.armor.feet')
425
+ // → Map { 'minecraft:wearable' => { protection: 3, slot: 'slot.armor.head' } }
426
+ ```
427
+
428
+ | 参数 | 类型 | 默认值 | 描述 |
429
+ |------|------|--------|------|
430
+ | `protection` | number | `0` | 保护值 |
431
+ | `slot` | string | `undefined` | 装备槽位(如 `'slot.armor.head'`) |
432
+
433
+ ---
434
+
435
+ ### setFuel(duration)
436
+
437
+ 设置燃料组件,使物品可在熔炉中作为燃料使用。
438
+
439
+ ```typescript
440
+ ItemComponent.setFuel(200)
441
+ // → Map { 'minecraft:fuel' => { duration: 200 } }
442
+ ```
443
+
444
+ | 参数 | 类型 | 描述 |
445
+ |------|------|------|
446
+ | `duration` | number | 燃烧持续时间(秒),最小值 0.05 |
447
+
448
+ ---
449
+
450
+ ### setGlint(hasGlint)
451
+
452
+ 设置附魔光效。
453
+
454
+ ```typescript
455
+ ItemComponent.setGlint(true)
456
+ // → Map { 'minecraft:glint' => true }
457
+ ```
458
+
459
+ | 参数 | 类型 | 描述 |
460
+ |------|------|------|
461
+ | `hasGlint` | boolean | 是否显示附魔光效 |
462
+
463
+ ---
464
+
465
+ ### setHandEquipped(isHandEquipped)
466
+
467
+ 设置手持渲染方式。
468
+
469
+ ```typescript
470
+ ItemComponent.setHandEquipped(true) // 像工具一样手持
471
+ ItemComponent.setHandEquipped(false) // 像物品一样手持
472
+ // → Map { 'minecraft:hand_equipped' => true }
473
+ ```
474
+
475
+ | 参数 | 类型 | 描述 |
476
+ |------|------|------|
477
+ | `isHandEquipped` | boolean | 是否像工具一样渲染 |
478
+
479
+ ---
480
+
481
+ ### setThrowable(doSwingAnimation?, launchPowerScale?, maxDrawDuration?, maxLaunchPower?, minDrawDuration?, scalePowerByDrawDuration?)
482
+
483
+ 设置可投掷组件。
484
+
485
+ ```typescript
486
+ ItemComponent.setThrowable(true, 1.5, 0, 2.0, 0, true)
487
+ // → Map { 'minecraft:throwable' => { do_swing_animation: true, launch_power_scale: 1.5, ... } }
488
+ ```
489
+
490
+ | 参数 | 类型 | 默认值 | 描述 |
491
+ |------|------|--------|------|
492
+ | `doSwingAnimation` | boolean | `false` | 是否使用挥动动画 |
493
+ | `launchPowerScale` | number | `1.0` | 投掷力量缩放 |
494
+ | `maxDrawDuration` | number | `0.0` | 最大蓄力时间 |
495
+ | `maxLaunchPower` | number | `1.0` | 最大投掷力量 |
496
+ | `minDrawDuration` | number | `0.0` | 最小蓄力时间 |
497
+ | `scalePowerByDrawDuration` | boolean | `false` | 力量是否随蓄力增加 |
498
+
499
+ ---
500
+
501
+ ### setProjectile(minimumCriticalPower?, projectileEntity?)
502
+
503
+ 设置投射物组件。
504
+
505
+ ```typescript
506
+ ItemComponent.setProjectile(0.5, 'minecraft:snowball')
507
+ // → Map { 'minecraft:projectile' => { minimum_critical_power: 0.5, projectile_entity: 'minecraft:snowball' } }
508
+ ```
509
+
510
+ | 参数 | 类型 | 描述 |
511
+ |------|------|------|
512
+ | `minimumCriticalPower` | number | 暴击所需的最小蓄力值 |
513
+ | `projectileEntity` | string | 发射的投射物实体 ID |
514
+
515
+ ---
516
+
517
+ ### setUseModifiers(movementModifier?, useDuration?)
518
+
519
+ 设置使用修饰组件。
520
+
521
+ ```typescript
522
+ ItemComponent.setUseModifiers(0.5, 1.5)
523
+ // → Map { 'minecraft:use_modifiers' => { movement_modifier: 0.5, use_duration: 1.5 } }
524
+ ```
525
+
526
+ | 参数 | 类型 | 描述 |
527
+ |------|------|------|
528
+ | `movementModifier` | number | 使用物品时玩家移动速度缩放值 |
529
+ | `useDuration` | number | 物品使用所需时间(秒) |
530
+
531
+ ---
532
+
533
+ ### setUseAnimation(animation)
534
+
535
+ 设置使用动画。
536
+
537
+ ```typescript
538
+ ItemComponent.setUseAnimation('eat')
539
+ ItemComponent.setUseAnimation('drink')
540
+ // → Map { 'minecraft:use_animation' => 'eat' }
541
+ ```
542
+
543
+ | 参数 | 类型 | 描述 |
544
+ |------|------|------|
545
+ | `animation` | string | 动画类型(如 `'eat'`、`'drink'`) |
546
+
547
+ ---
548
+
549
+ ### setDurability(maxDurability, damageChanceMin?, damageChanceMax?)
550
+
551
+ 设置耐久度组件。
552
+
553
+ ```typescript
554
+ ItemComponent.setDurability(500, 10, 50)
555
+ // → Map { 'minecraft:durability' => { max_durability: 500, damage_chance: { min: 10, max: 50 } } }
556
+ ```
557
+
558
+ | 参数 | 类型 | 默认值 | 描述 |
559
+ |------|------|--------|------|
560
+ | `maxDurability` | number | — | 最大耐久值 |
561
+ | `damageChanceMin` | number | `0` | 最小损坏概率(百分比) |
562
+ | `damageChanceMax` | number | `100` | 最大损坏概率(百分比) |
563
+
564
+ ---
565
+
566
+ ### setInteractButton(text)
567
+
568
+ 设置交互按钮文本。
569
+
570
+ ```typescript
571
+ ItemComponent.setInteractButton('打开')
572
+ // → Map { 'minecraft:interact_button' => '打开' }
573
+ ```
574
+
575
+ | 参数 | 类型 | 描述 |
576
+ |------|------|------|
577
+ | `text` | string | 交互时显示的文本 |
578
+
579
+ ---
580
+
581
+ ### setBlockPlacer(block, replaceBlockItem?, useOn?)
582
+
583
+ 设置方块放置器组件。
584
+
585
+ ```typescript
586
+ ItemComponent.setBlockPlacer(
587
+ 'my_mod:custom_block', // 要放置的方块 ID
588
+ false, // 是否替换方块物品
589
+ ['my_mod:custom_block'] // 可以使用的方块列表
590
+ )
591
+ // → Map { 'minecraft:block_placer' => { block: '...', replace_block_item: false, use_on: [...] } }
592
+ ```
593
+
594
+ | 参数 | 类型 | 描述 |
595
+ |------|------|------|
596
+ | `block` | string | 要放置的方块标识符 |
597
+ | `replaceBlockItem` | boolean | 是否替换方块物品 |
598
+ | `useOn` | string[] | 可使用此物品的方块列表 |
599
+
600
+ ---
601
+
602
+ ### setCustomComponentV2(componentId, params)
603
+
604
+ 设置自定义 V2 组件(需要 format_version > 1.21.90 和 Scripting V2)。
605
+
606
+ ```typescript
607
+ ItemComponent.setCustomComponentV2(
608
+ 'my_mod:my_component',
609
+ { speed: 1.5, damage: 10 }
610
+ )
611
+ // → Map { 'my_mod:my_component' => { speed: 1.5, damage: 10 } }
612
+ ```
613
+
614
+ | 参数 | 类型 | 描述 |
615
+ |------|------|------|
616
+ | `componentId` | string | 组件标识符 |
617
+ | `params` | object | 自定义参数对象 |
618
+
619
+ ---
620
+
621
+ ### combineComponents(...maps)
622
+
623
+ 将多个组件 Map 合并为一个。
624
+
625
+ ```typescript
626
+ const combined = ItemComponent.combineComponents(
627
+ ItemComponent.setDisplayName('神剑'),
628
+ ItemComponent.setHandEquipped(true),
629
+ ItemComponent.setDurability(1000),
630
+ )
631
+ // → Map { 'minecraft:display_name': ..., 'minecraft:hand_equipped': ..., 'minecraft:durability': ... }
632
+ ```
633
+
634
+ | 参数 | 类型 | 描述 |
635
+ |------|------|------|
636
+ | `...componentMaps` | Map[] | 多个组件 Map |
637
+
638
+ **返回值:** `Map` — 合并后的组件集合。
639
+
640
+ ---
641
+
642
+ ### toJSON(components)
643
+
644
+ 将组件 Map 转换为普通 JSON 对象。
645
+
646
+ ```typescript
647
+ const map = ItemComponent.setDisplayName('测试')
648
+ const json = ItemComponent.toJSON(map)
649
+ // → { 'minecraft:display_name': { value: '测试' } }
650
+ ```
651
+
652
+ | 参数 | 类型 | 描述 |
653
+ |------|------|------|
654
+ | `components` | Map | 组件集合 |
655
+
656
+ **返回值:** `object` — JSON 对象。
657
+
658
+ ---
659
+
660
+ ### setCustomComponents(customComponents)
661
+
662
+ 设置自定义组件数组。
663
+
664
+ ```typescript
665
+ ItemComponent.setCustomComponents(['my_mod:my_component'])
666
+ // → Map { 'minecraft:custom_components' => ['my_mod:my_component'] }
667
+ ```
668
+
669
+ | 参数 | 类型 | 描述 |
670
+ |------|------|------|
671
+ | `customComponents` | string[] | 自定义组件标识符数组 |
672
+
673
+ ---
674
+
675
+ ## 4. Armor 子类
676
+
677
+ 盔甲系统包含四个子类,分别对应四种盔甲类型。它们继承自 `Armor` 基类,内部创建 `Item` 和 `Attachable` 实例。
678
+
679
+ ### Armor 基类
680
+
681
+ ```typescript
682
+ // 基类构造函数(不直接使用)
683
+ new Armor(identifier, category, item_texture, texture_path, options?)
684
+ ```
685
+
686
+ | 属性/方法 | 类型 | 描述 |
687
+ |-----------|------|------|
688
+ | `item` | Item | 关联的物品实例 |
689
+ | `attachable` | Attachable | 关联的可附着物实例 |
690
+ | `setArrachableGeometry(key, geometry)` | this | 设置可附着物几何模型 |
691
+
692
+ ### 子类对照表
693
+
694
+ | 类 | 创建方法 | 保护值 | 插槽 | 几何模型 | 脚本 |
695
+ |----|---------|--------|------|---------|------|
696
+ | **Helmet** | `ItemAPI.createHelmetArmor()` | 3 | `slot.armor.head` | `geometry.player.armor.helmet` | `v.helmet_layer_visible = 0.0;` |
697
+ | **Chestplate** | `ItemAPI.createChestplateArmor()` | 5 | `slot.armor.chest` | `geometry.player.armor.chestplate` | `v.chest_layer_visible = 0.0;` |
698
+ | **Leggings** | `ItemAPI.createLeggingsArmor()` | 6 | `slot.armor.legs` | `geometry.player.armor.leggings` | `v.leg_layer_visible = 0.0;` |
699
+ | **Boot** | `ItemAPI.createBootArmor()` | 4 | `slot.armor.feet` | `geometry.player.armor.boots` | `v.boot_layer_visible = 0.0;` |
700
+
701
+ ### 默认配置
702
+
703
+ 所有盔甲子类自动配置以下属性:
704
+
705
+ - 分类:`'equipment'`
706
+ - 分组:对应的 `itemGroup.name.*`
707
+ - 最大堆叠数量:`1`
708
+ - 显示名称:各类型的默认名称
709
+ - 纹理:通过 `texture_path` 参数指定
710
+ - 材质:`'armor'`(默认)和 `'armor_enchanted'`(附魔)
711
+ - 渲染控制器:`'controller.render.armor'`
712
+
713
+ ```typescript
714
+ // 自定义盔甲几何模型示例
715
+ ItemAPI.createHelmetArmor('my_mod:custom_helmet', 'custom_helmet', 'textures/models/armor/custom')
716
+ .setArrachableGeometry('default', 'geometry.custom.helmet')
717
+ ```
718
+
719
+ ---
720
+
721
+ ## 5. Food 类
722
+
723
+ `Food` 继承自 `Item`,自动添加食物相关组件。
724
+
725
+ ```typescript
726
+ class Food extends Item {
727
+ constructor(identifier, category, texture, options?)
728
+ }
729
+ ```
730
+
731
+ ### 构造函数自动添加的组件
732
+
733
+ | 组件 | 来源 |
734
+ |------|------|
735
+ | `minecraft:icon` | 父类构造 |
736
+ | `minecraft:max_stack_size` | 父类构造 |
737
+ | `minecraft:use_modifiers` | Food 构造 |
738
+ | `minecraft:food` | Food 构造 |
739
+ | `minecraft:use_animation` | Food 构造 |
740
+
741
+ ```typescript
742
+ import { Food } from '@sapdon/core'
743
+
744
+ const food = new Food('my_mod:apple', 'items', 'apple', {
745
+ nutrition: 8,
746
+ saturationModifier: 1.5,
747
+ canAlwaysEat: true,
748
+ animation: 'eat',
749
+ movement: 0.8,
750
+ useDuration: 1.5,
751
+ })
752
+ ```
753
+
754
+ ---
755
+
756
+ ## 6. ItemCategory 枚举
757
+
758
+ `ItemCategory` 提供标准的创造模式物品栏分类。
759
+
760
+ ```typescript
761
+ enum ItemCategory {
762
+ Commands = 'commands', // 命令分类
763
+ Construction = 'construction', // 建筑分类
764
+ Equipment = 'equipment', // 装备分类
765
+ Nature = 'nature', // 自然分类
766
+ Items = 'items', // 物品分类
767
+ None = 'none', // 无分类
768
+ }
769
+ ```
770
+
771
+ ### 使用示例
772
+
773
+ ```typescript
774
+ import { ItemAPI, ItemCategory } from '@sapdon/core'
775
+
776
+ // 使用枚举值
777
+ ItemAPI.createItem('test:item', ItemCategory.Construction, 'tex')
778
+ // 等价于
779
+ ItemAPI.createItem('test:item', 'construction', 'tex')
780
+ ```
781
+
782
+ ---
783
+
784
+ ## 7. Attachable 类
785
+
786
+ `Attachable` 用于创建可附着物(attachables),实现手持 3D 模型或穿戴物品渲染。继承自 `AddonAttachableDescription`。
787
+
788
+ ### 构造函数
789
+
790
+ ```typescript
791
+ import { Attachable } from '@sapdon/core'
792
+
793
+ const att = new Attachable('my_mod:my_attachable')
794
+ ```
795
+
796
+ ### 方法
797
+
798
+ | 方法 | 描述 |
799
+ |------|------|
800
+ | `addMaterial(name, material)` | 添加材质(如 `'default'`, `'entity_alphatest'`) |
801
+ | `addTexture(name, texture)` | 添加纹理路径 |
802
+ | `addGeometry(name, geometry)` | 添加几何模型标识符 |
803
+ | `addAnimation(name, animation)` | 添加动画 |
804
+ | `addAnimationController(name, controller)` | 添加动画控制器 |
805
+ | `addRenderController(controller)` | 添加渲染控制器 |
806
+ | `addLocator(name, locator)` | 添加定位器 |
807
+ | `setScript(key, value)` | 设置脚本变量 |
808
+ | `getId()` | 获取标识符 |
809
+ | `toObject()` | 序列化为 JSON |
810
+
811
+ ### 完整示例
812
+
813
+ ```typescript
814
+ const att = new Attachable('my_mod:custom_armor')
815
+ att
816
+ .addMaterial('default', 'armor')
817
+ .addMaterial('enchanted', 'armor_enchanted')
818
+ .addTexture('default', 'textures/models/armor/custom_main')
819
+ .addTexture('enchanted', 'textures/misc/enchanted_actor_glint')
820
+ .addGeometry('default', 'geometry.player.armor.chestplate')
821
+ .addRenderController('controller.render.armor')
822
+ .setScript('parent_setup', 'v.chest_layer_visible = 0.0;')
823
+ ```
824
+
825
+ ---
826
+
827
+ ## 8. 注册流程
828
+
829
+ 所有通过 `ItemAPI` 创建的对象会自动注册到游戏。但如果你手动创建 `Item` 或需要提交注册数据,需要调用 `registry.submit()`。
830
+
831
+ ### 基本流程
832
+
833
+ ```typescript
834
+ import { ItemAPI, registry, ItemComponent, ItemCategory } from '@sapdon/core'
835
+
836
+ // 1. 创建物品(自动注册到全局注册表)
837
+ ItemAPI.createItem('my_mod:sword', ItemCategory.Equipment, 'sword')
838
+
839
+ // 2. 提交所有注册数据到游戏引擎
840
+ // 必须在所有物品创建完成后调用
841
+ registry.submit()
842
+ ```
843
+
844
+ ### 手动注册
845
+
846
+ ```typescript
847
+ import { GRegistry } from '@sapdon/core'
848
+
849
+ // 手动注册物品数据
850
+ GRegistry.register(
851
+ 'my_item', // name: string — 文件名(不含扩展名)
852
+ 'behavior', // root: string — 根目录('behavior' / 'resource')
853
+ 'items/', // path: string — 子目录
854
+ itemDataObject // data: object — 数据对象(需有 toObject 方法)
855
+ )
856
+
857
+ // 提交
858
+ GRegistry.submit()
859
+ ```
860
+
861
+ ### registry 命名空间
862
+
863
+ ```typescript
864
+ import { registry } from '@sapdon/core'
865
+
866
+ // 提交所有注册数据
867
+ registry.submit()
868
+ ```
869
+
870
+ ### 完整工作流
871
+
872
+ ```typescript
873
+ // main.ts
874
+ import { ItemAPI, registry, ItemComponent, ItemCategory } from '@sapdon/core'
875
+
876
+ // === 定义所有物品 ===
877
+
878
+ // 基础物品
879
+ ItemAPI.createItem('my_mod:materials', ItemCategory.Items, 'materials')
880
+ .addComponent(ItemComponent.setDisplayName('§b基础材料'))
881
+
882
+ // 食物
883
+ ItemAPI.createFood('my_mod:food', ItemCategory.Items, 'food', {
884
+ nutrition: 8,
885
+ saturationModifier: 1.5,
886
+ })
887
+
888
+ // 盔甲
889
+ ItemAPI.createHelmetArmor('my_mod:helmet', 'helmet', 'textures/models/armor/set')
890
+ ItemAPI.createChestplateArmor('my_mod:chestplate', 'chestplate', 'textures/models/armor/set')
891
+
892
+ // === 提交注册 ===
893
+ registry.submit()
894
+ ```
895
+
896
+ > **重要**:`registry.submit()` 必须在所有物品创建完成后调用一次,且通常在文件末尾执行。