sapdon 3.2.2 → 3.4.0

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 (76) hide show
  1. package/README.md +255 -121
  2. package/doc/dev/architecture.md +418 -0
  3. package/doc/dev/cli.md +467 -0
  4. package/doc/dev/core.md +751 -0
  5. package/doc/dev/lr-paradigm.md +85 -0
  6. package/doc/dev/oc.md +582 -0
  7. package/doc/dev/workflow.md +257 -0
  8. package/doc/hello_sapdon/hello_sapdon.md +3 -3
  9. package/doc/user/api/biome.md +558 -0
  10. package/doc/user/api/block.md +1530 -0
  11. package/doc/user/api/entity.md +685 -0
  12. package/doc/user/api/extra.md +231 -0
  13. package/doc/user/api/item.md +1125 -0
  14. package/doc/user/api/neo-guidebook.md +409 -0
  15. package/doc/user/api/recipe.md +427 -0
  16. package/doc/user/api/sapdon-ui.md +185 -0
  17. package/doc/user/api/texture.md +181 -0
  18. package/doc/user/config/build-config.md +83 -0
  19. package/doc/user/config/mod-info.md +33 -0
  20. package/doc/user/faq.md +160 -0
  21. package/doc/user/quick-start.md +122 -0
  22. package/doc/user/tutorials/block.md +474 -0
  23. package/doc/user/tutorials/entity.md +356 -0
  24. package/doc/user/tutorials/item.md +449 -0
  25. package/doc/user/tutorials/neo-guidebook-experience.md +381 -0
  26. package/doc/user/tutorials/neo-guidebook.md +640 -0
  27. package/doc/user/tutorials/recipe.md +278 -0
  28. package/doc/user/tutorials/sapdon-ui.md +207 -0
  29. package/package.json +8 -3
  30. package/prod/cli/index.js +1 -1
  31. package/prod/cli/start.js +1 -1458
  32. package/prod/core/index.d.ts +4564 -2166
  33. package/prod/core/index.js +1 -59015
  34. package/prod/core/package.json +7 -0
  35. package/prod/oc/index.d.ts +350 -108
  36. package/prod/oc/index.js +1 -1
  37. package/prod/oc/package.json +7 -0
  38. package/prod/utils/index.d.ts +20 -9
  39. package/prod/utils/index.js +1 -1
  40. package/prod/utils/package.json +7 -0
  41. package/doc/BlockAPI.md +0 -145
  42. package/doc/api.md +0 -128
  43. package/doc/oc/index.md +0 -0
  44. package/doc/sapdon-ts.md +0 -64
  45. package/src/templates/js_sapdon/build.config +0 -23
  46. package/src/templates/js_sapdon/main.mjs +0 -4
  47. package/src/templates/js_sapdon/mod.info +0 -7
  48. package/src/templates/js_sapdon/pack_icon.png +0 -0
  49. package/src/templates/js_sapdon/package.json +0 -20
  50. package/src/templates/js_sapdon/res/animations/animation_item.animation.json +0 -34
  51. package/src/templates/js_sapdon/res/animations/large_item.animation.json +0 -27
  52. package/src/templates/js_sapdon/res/models/blocks/crop.geo.json +0 -48
  53. package/src/templates/js_sapdon/res/models/entity/animation/animation_item.geo.json +0 -26
  54. package/src/templates/js_sapdon/res/models/entity/animation/large_item.geo.json +0 -28
  55. package/src/templates/js_sapdon/res/textures/blocks/none.png +0 -0
  56. package/src/templates/js_sapdon/res/textures/blocks/test_log_oak.png +0 -0
  57. package/src/templates/js_sapdon/res/textures/blocks/test_log_top.png +0 -0
  58. package/src/templates/js_sapdon/res/textures/items/masterball.png +0 -0
  59. package/src/templates/js_sapdon/scripts/custom_components/cropComponent.js +0 -50
  60. package/src/templates/js_sapdon/scripts/custom_components/items/gui_book.js +0 -37
  61. package/src/templates/js_sapdon/scripts/custom_components/registry.js +0 -25
  62. package/src/templates/js_sapdon/scripts/index.js +0 -0
  63. package/src/templates/ts_sapdon/build.config +0 -23
  64. package/src/templates/ts_sapdon/main.ts +0 -11
  65. package/src/templates/ts_sapdon/mod.info +0 -7
  66. package/src/templates/ts_sapdon/pack_icon.png +0 -0
  67. package/src/templates/ts_sapdon/package.json +0 -20
  68. package/src/templates/ts_sapdon/res/models/blocks/crop.geo.json +0 -48
  69. package/src/templates/ts_sapdon/res/textures/blocks/test_log_oak.png +0 -0
  70. package/src/templates/ts_sapdon/res/textures/blocks/test_log_top.png +0 -0
  71. package/src/templates/ts_sapdon/res/textures/items/masterball.png +0 -0
  72. package/src/templates/ts_sapdon/scripts/components/cropComponent.ts +0 -44
  73. package/src/templates/ts_sapdon/scripts/components/items/guiBook.ts +0 -36
  74. package/src/templates/ts_sapdon/scripts/components/registry.ts +0 -24
  75. package/src/templates/ts_sapdon/scripts/index.ts +0 -7
  76. package/src/templates/ts_sapdon/tsconfig.json +0 -117
@@ -0,0 +1,1125 @@
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
+ 9. [ItemCatalog 类](#9-itemcatalog-类)
18
+
19
+ ---
20
+
21
+ ## 1. ItemAPI
22
+
23
+ `ItemAPI` 是一个工厂对象,提供创建各种类型物品的静态方法。所有创建方法会自动调用 `GRegistry.register()` 注册物品到游戏。
24
+
25
+ ### createItem()
26
+
27
+ 创建普通物品。
28
+
29
+ ```typescript
30
+ import { ItemAPI, ItemCategory } from '@sapdon/core'
31
+
32
+ const item = ItemAPI.createItem(
33
+ 'my_mod:simple_item', // identifier: string — 唯一标识符(命名空间:名称)
34
+ ItemCategory.Items, // category: string — 创造菜单分类
35
+ 'my_texture', // texture: string — 纹理名称
36
+ { // options?: object — 可选配置
37
+ group: 'minecraft:itemGroup.name.ingredients',
38
+ hide_in_command: false, // 是否在命令中隐藏
39
+ max_stack_size: 64, // 最大堆叠数量
40
+ format_version: '1.21.40', // 格式版本
41
+ }
42
+ )
43
+ ```
44
+
45
+ **参数:**
46
+
47
+ | 参数 | 类型 | 必填 | 描述 |
48
+ |------|------|------|------|
49
+ | `identifier` | string | 是 | 物品唯一标识符,格式 `namespace:name` |
50
+ | `category` | ItemCategory | 是 | 创造模式物品栏分类,见 `ItemCategory` 枚举 |
51
+ | `texture` | string | 是 | 纹理名称 |
52
+ | `options.group` | string | 否 | 物品分组 |
53
+ | `options.hide_in_command` | boolean | 否 | 是否在命令自动补全中隐藏(默认 false) |
54
+ | `options.max_stack_size` | number | 否 | 最大堆叠数量(默认 64,范围 1-99) |
55
+ | `options.format_version` | string | 否 | 格式版本(默认 `'1.21.40'`) |
56
+
57
+ **返回值:** `Item` — 创建的物品实例。
58
+
59
+ ---
60
+
61
+ ### createFood()
62
+
63
+ 创建食物物品。
64
+
65
+ ```typescript
66
+ import { ItemAPI, ItemCategory } from '@sapdon/core'
67
+
68
+ const food = ItemAPI.createFood(
69
+ 'my_mod:magic_apple', // identifier: string
70
+ ItemCategory.Items, // category: string
71
+ 'magic_apple', // texture: string
72
+ {
73
+ group: 'minecraft:itemGroup.name.food',
74
+ hide_in_command: false,
75
+ animation: 'eat', // 使用动画('eat' | 'drink')
76
+ canAlwaysEat: false, // 是否可随时食用
77
+ nutrition: 6, // 营养值
78
+ saturationModifier: 1.2, // 饱和度修正值
79
+ movement: 1, // 移动速度修正
80
+ useDuration: 1, // 使用时间(秒)
81
+ }
82
+ )
83
+ ```
84
+
85
+ **参数:**
86
+
87
+ | 参数 | 类型 | 默认值 | 描述 |
88
+ |------|------|--------|------|
89
+ | `identifier` | string | — | 唯一标识符 |
90
+ | `category` | ItemCategory | — | 创造菜单分类 |
91
+ | `texture` | string | — | 纹理名称 |
92
+ | `options.group` | string | `undefined` | 物品分组 |
93
+ | `options.hide_in_command` | boolean | `false` | 是否在命令中隐藏 |
94
+ | `options.animation` | string | `'eat'` | 食用动画 |
95
+ | `options.canAlwaysEat` | boolean | `false` | 是否可随时食用 |
96
+ | `options.nutrition` | number | `0` | 营养值(非负) |
97
+ | `options.saturationModifier` | number | `1` | 饱和度修正(正数) |
98
+ | `options.movement` | number | `1` | 食用时移动速度缩放 |
99
+ | `options.useDuration` | number | `1` | 食用所需时间(秒) |
100
+
101
+ **返回值:** `Food` — 创建的食物物品实例。
102
+
103
+ ---
104
+
105
+ ### createAttachable()
106
+
107
+ 创建可附着物(用于手持 3D 模型或穿戴物品)。
108
+
109
+ ```typescript
110
+ import { ItemAPI } from '@sapdon/core'
111
+
112
+ const attachable = ItemAPI.createAttachable(
113
+ 'my_mod:special_item', // identifier: string
114
+ 'textures/items/special_item', // texture: string — 纹理路径
115
+ 'entity_alphatest', // material: string — 材质类型
116
+ // options?: object — 当前未使用额外选项
117
+ )
118
+
119
+ // 进一步配置
120
+ attachable
121
+ .addGeometry('default', 'geometry.special_item')
122
+ .addTexture('enchanted', 'textures/misc/enchanted_item_glint')
123
+ .addRenderController('controller.render.special_item')
124
+ ```
125
+
126
+ **参数:**
127
+
128
+ | 参数 | 类型 | 必填 | 描述 |
129
+ |------|------|------|------|
130
+ | `identifier` | string | 是 | 唯一标识符 |
131
+ | `texture` | string | 是 | 纹理路径(如 `'textures/items/my_item'`) |
132
+ | `material` | string | 是 | 材质类型(如 `'entity_alphatest'`、`'armor'`) |
133
+ | `options` | object | 否 | 预留扩展参数 |
134
+
135
+ **返回值:** `Attachable` — 可附着物实例。
136
+
137
+ ---
138
+
139
+ ### createChestplateArmor()
140
+
141
+ 创建胸甲盔甲。
142
+
143
+ ```typescript
144
+ import { ItemAPI } from '@sapdon/core'
145
+
146
+ const chestplate = ItemAPI.createChestplateArmor(
147
+ 'my_mod:ruby_chestplate', // identifier: string
148
+ 'ruby_chestplate', // item_texture: string — 物品图标纹理
149
+ 'textures/models/armor/ruby', // texture_path: string — 模型纹理路径
150
+ { // options?: object
151
+ displayName: '红宝石胸甲', // 自定义显示名称(默认:"我的自定义胸甲")
152
+ }
153
+ )
154
+ ```
155
+
156
+ **返回值:** `Armor` — 盔甲实例(`type === ArmorType.Chestplate`)。
157
+
158
+ ---
159
+
160
+ ### createHelmetArmor()
161
+
162
+ 创建头盔盔甲。
163
+
164
+ ```typescript
165
+ const helmet = ItemAPI.createHelmetArmor(
166
+ 'my_mod:ruby_helmet',
167
+ 'ruby_helmet',
168
+ 'textures/models/armor/ruby'
169
+ )
170
+ ```
171
+
172
+ **返回值:** `Armor` — 盔甲实例(`type === ArmorType.Helmet`)。
173
+
174
+ ---
175
+
176
+ ### createBootArmor()
177
+
178
+ 创建靴子盔甲。
179
+
180
+ ```typescript
181
+ const boots = ItemAPI.createBootArmor(
182
+ 'my_mod:ruby_boots',
183
+ 'ruby_boots',
184
+ 'textures/models/armor/ruby'
185
+ )
186
+ ```
187
+
188
+ **返回值:** `Armor` — 盔甲实例(`type === ArmorType.Boots`)。
189
+
190
+ ---
191
+
192
+ ### createLeggingsArmor()
193
+
194
+ 创建护腿盔甲。
195
+
196
+ ```typescript
197
+ const leggings = ItemAPI.createLeggingsArmor(
198
+ 'my_mod:ruby_leggings',
199
+ 'ruby_leggings',
200
+ 'textures/models/armor/ruby'
201
+ )
202
+ ```
203
+
204
+ **返回值:** `Armor` — 盔甲实例(`type === ArmorType.Leggings`)。
205
+
206
+ > **说明:** 盔甲已重构为数据驱动结构,所有类型共享同一个 `Armor` 类,通过 `ArmorType` 枚举区分。
207
+ > 可直接使用 `new Armor(id, item_texture, texture_path, ArmorType.Helmet, options)` 创建,
208
+ > 并通过 `setAttachableGeometry(key, geometry)` 自定义几何模型(原 `setArrachableGeometry` 已改名)。
209
+ > 访问内部对象:`armor.item`(物品)与 `armor.attachable`(可附着物),或 `armor.toObject()` 获取 `{ behavior, resource }`。
210
+
211
+ ---
212
+
213
+ ### createFlipbookItem()
214
+
215
+ 创建翻书物品(动态帧动画物品)。
216
+
217
+ ```typescript
218
+ import { ItemAPI, ItemCategory } from '@sapdon/core'
219
+
220
+ const flipbook = ItemAPI.createFlipbookItem(
221
+ 'my_mod:animated_block', // identifier: string
222
+ ItemCategory.Construction, // category: ItemCategory
223
+ 'my_flipbook_tex', // texture: string — 纹理名称
224
+ {
225
+ group: 'minecraft:itemGroup.name.construction',
226
+ hide_in_command: false,
227
+ ticks_per_frame: 8, // 每帧持续刻数(默认 8,1秒=20刻)
228
+ max_stack_size: 64,
229
+ format_version: '1.21.40',
230
+ }
231
+ )
232
+ ```
233
+
234
+ **参数:**
235
+
236
+ | 参数 | 类型 | 默认值 | 描述 |
237
+ |------|------|--------|------|
238
+ | `identifier` | string | — | 唯一标识符 |
239
+ | `category` | ItemCategory | — | 创造菜单分类 |
240
+ | `texture` | string | — | 纹理名称(位于 `textures/blocks/` 目录) |
241
+ | `options.group` | string | `undefined` | 物品分组 |
242
+ | `options.hide_in_command` | boolean | `false` | 是否在命令中隐藏 |
243
+ | `options.ticks_per_frame` | number | `8` | 每帧持续刻数 |
244
+ | `options.max_stack_size` | number | `64` | 最大堆叠数量 |
245
+ | `options.format_version` | string | `'1.21.40'` | 格式版本 |
246
+
247
+ **返回值:** `FlipbookItem` — 翻书物品实例。可通过 `.block` 属性访问关联的 `GeometryBlock`。
248
+
249
+ ---
250
+
251
+ ## 2. Item 类
252
+
253
+ `Item` 是所有物品类型的基类,提供组件管理和序列化功能。
254
+
255
+ ### 构造函数
256
+
257
+ ```typescript
258
+ import { Item, ItemCategory } from '@sapdon/core'
259
+
260
+ const item = new Item(
261
+ 'my_mod:custom_item', // identifier: string — 唯一标识符
262
+ ItemCategory.Items, // category: ItemCategory — 创造菜单分类
263
+ 'custom_texture', // texture: string — 纹理名称
264
+ { // options?: object
265
+ group: '...',
266
+ hide_in_command: false,
267
+ max_stack_size: 64,
268
+ format_version: '1.21.40',
269
+ }
270
+ )
271
+ ```
272
+
273
+ **参数:**
274
+
275
+ | 参数 | 类型 | 默认值 | 描述 |
276
+ |------|------|--------|------|
277
+ | `identifier` | string | — | 唯一标识符 |
278
+ | `category` | ItemCategory | — | 创造菜单分类 |
279
+ | `texture` | string | — | 纹理名称 |
280
+ | `options.group` | string | `undefined` | 分组 |
281
+ | `options.hide_in_command` | boolean | `false` | 是否在命令中隐藏 |
282
+ | `options.max_stack_size` | number | `64` | 最大堆叠数量 |
283
+ | `options.format_version` | string | `'1.21.40'` | 格式版本 |
284
+
285
+ 构造函数自动添加 `minecraft:icon` 和 `minecraft:max_stack_size` 组件。
286
+
287
+ ### 方法
288
+
289
+ #### addComponent(componentMap)
290
+
291
+ 添加一个或多个组件到物品。
292
+
293
+ ```typescript
294
+ item.addComponent(
295
+ ItemComponent.setDisplayName('自定义物品')
296
+ )
297
+
298
+ // 或合并多个组件
299
+ item.addComponent(
300
+ ItemComponent.combineComponents(
301
+ ItemComponent.setHandEquipped(true),
302
+ ItemComponent.setDurability(100),
303
+ )
304
+ )
305
+ ```
306
+
307
+ | 参数 | 类型 | 描述 |
308
+ |------|------|------|
309
+ | `componentMap` | Map | 组件 Map 对象 |
310
+
311
+ **返回值:** `this` — 支持链式调用。
312
+
313
+ ---
314
+
315
+ #### removeComponent(key)
316
+
317
+ 移除指定组件。
318
+
319
+ ```typescript
320
+ item.removeComponent('minecraft:icon') // 移除图标组件
321
+ ```
322
+
323
+ | 参数 | 类型 | 描述 |
324
+ |------|------|------|
325
+ | `key` | string | 要移除的组件名称 |
326
+
327
+ **返回值:** `this` — 支持链式调用。
328
+
329
+ ---
330
+
331
+ #### toObject()
332
+
333
+ 将物品转换为 JSON 对象(使用 `@Serializer` 装饰器),用于生成物品定义文件。
334
+
335
+ ```typescript
336
+ const json = item.toObject()
337
+ // 输出格式:
338
+ // {
339
+ // format_version: '1.21.40',
340
+ // 'minecraft:item': {
341
+ // description: { identifier, menu_category },
342
+ // components: { ... }
343
+ // }
344
+ // }
345
+ ```
346
+
347
+ **返回值:** `object` — 序列化后的物品定义对象。
348
+
349
+ ---
350
+
351
+ ## 3. ItemComponent
352
+
353
+ `ItemComponent` 提供静态方法,用于构建 `minecraft:item` 的组件 Map。每个方法返回一个 `Map<string, any>`。
354
+
355
+ ### setIcon(texture)
356
+
357
+ 设置物品图标纹理。支持字符串(默认纹理)或对象(多纹理)两种格式。
358
+
359
+ ```typescript
360
+ ItemComponent.setIcon('my_texture')
361
+ // → Map { 'minecraft:icon' => 'my_texture' }
362
+
363
+ ItemComponent.setIcon({ default: 'my_texture', dyed: 'my_texture_dyed' })
364
+ // → Map { 'minecraft:icon' => { textures: { default: 'my_texture', dyed: 'my_texture_dyed' } } }
365
+ ```
366
+
367
+ | 参数 | 类型 | 描述 |
368
+ |------|------|------|
369
+ | `texture` | string \| object | 纹理名称,或包含 `default`/`dyed`/`iconTrim`/`bundleOpenBack`/`bundleOpenFront` 的纹理对象 |
370
+
371
+ ---
372
+
373
+ ### setMaxStackSize(size)
374
+
375
+ 设置最大堆叠数量。
376
+
377
+ ```typescript
378
+ ItemComponent.setMaxStackSize(16)
379
+ // → Map { 'minecraft:max_stack_size' => 16 }
380
+ ```
381
+
382
+ | 参数 | 类型 | 默认值 | 描述 |
383
+ |------|------|--------|------|
384
+ | `size` | number | `64` | 最大堆叠数量(正整数) |
385
+
386
+ ---
387
+
388
+ ### setDisplayName(name)
389
+
390
+ 设置物品显示名称。
391
+
392
+ ```typescript
393
+ ItemComponent.setDisplayName('§c传奇之剑')
394
+ // → Map { 'minecraft:display_name' => { value: '§c传奇之剑' } }
395
+ ```
396
+
397
+ | 参数 | 类型 | 描述 |
398
+ |------|------|------|
399
+ | `name` | string | 显示名称(支持 § 颜色代码) |
400
+
401
+ ---
402
+
403
+ ### setFoodComponent(options)
404
+
405
+ 设置食物属性组件。
406
+
407
+ ```typescript
408
+ ItemComponent.setFoodComponent({
409
+ nutrition: 6,
410
+ saturationModifier: 1.2,
411
+ canAlwaysEat: true,
412
+ usingConvertsTo: 'minecraft:bowl', // 可选
413
+ })
414
+ // → Map { 'minecraft:food' => { can_always_eat: true, nutrition: 6, saturation_modifier: 1.2, using_converts_to: 'minecraft:bowl' } }
415
+ ```
416
+
417
+ | 参数 | 类型 | 默认值 | 描述 |
418
+ |------|------|--------|------|
419
+ | `options.canAlwaysEat` | boolean | `false` | 是否可随时食用 |
420
+ | `options.nutrition` | number | `0` | 营养值 |
421
+ | `options.saturationModifier` | number | `0.6` | 饱和度修正值 |
422
+ | `options.usingConvertsTo` | string | `undefined` | 食用后转换的目标物品 ID |
423
+
424
+ ---
425
+
426
+ ### setWearable(protection?, slot?, hidesPlayerLocation?)
427
+
428
+ 设置可穿戴组件。
429
+
430
+ ```typescript
431
+ // 头盔
432
+ ItemComponent.setWearable(3, 'slot.armor.head')
433
+ // 胸甲
434
+ ItemComponent.setWearable(5, 'slot.armor.chest')
435
+ // 护腿
436
+ ItemComponent.setWearable(6, 'slot.armor.legs')
437
+ // 靴子
438
+ ItemComponent.setWearable(4, 'slot.armor.feet')
439
+ // → Map { 'minecraft:wearable' => { protection: 3, slot: 'slot.armor.head' } }
440
+ ```
441
+
442
+ | 参数 | 类型 | 默认值 | 描述 |
443
+ |------|------|--------|------|
444
+ | `protection` | number | `0` | 保护值 |
445
+ | `slot` | string | `undefined` | 装备槽位(如 `'slot.armor.head'`) |
446
+ | `hidesPlayerLocation` | boolean | `undefined` | 穿戴时是否在定位栏与定位地图中隐藏 |
447
+
448
+ ---
449
+
450
+ ### setFuel(duration)
451
+
452
+ 设置燃料组件,使物品可在熔炉中作为燃料使用。
453
+
454
+ ```typescript
455
+ ItemComponent.setFuel(200)
456
+ // → Map { 'minecraft:fuel' => { duration: 200 } }
457
+ ```
458
+
459
+ | 参数 | 类型 | 描述 |
460
+ |------|------|------|
461
+ | `duration` | number | 燃烧持续时间(秒),最小值 0.05 |
462
+
463
+ ---
464
+
465
+ ### setGlint(hasGlint)
466
+
467
+ 设置附魔光效。
468
+
469
+ ```typescript
470
+ ItemComponent.setGlint(true)
471
+ // → Map { 'minecraft:glint' => true }
472
+ ```
473
+
474
+ | 参数 | 类型 | 描述 |
475
+ |------|------|------|
476
+ | `hasGlint` | boolean | 是否显示附魔光效 |
477
+
478
+ ---
479
+
480
+ ### setHandEquipped(isHandEquipped)
481
+
482
+ 设置手持渲染方式。
483
+
484
+ ```typescript
485
+ ItemComponent.setHandEquipped(true) // 像工具一样手持
486
+ ItemComponent.setHandEquipped(false) // 像物品一样手持
487
+ // → Map { 'minecraft:hand_equipped' => true }
488
+ ```
489
+
490
+ | 参数 | 类型 | 描述 |
491
+ |------|------|------|
492
+ | `isHandEquipped` | boolean | 是否像工具一样渲染 |
493
+
494
+ ---
495
+
496
+ ### setThrowable(doSwingAnimation?, launchPowerScale?, maxDrawDuration?, maxLaunchPower?, minDrawDuration?, scalePowerByDrawDuration?)
497
+
498
+ 设置可投掷组件。
499
+
500
+ ```typescript
501
+ ItemComponent.setThrowable(true, 1.5, 0, 2.0, 0, true)
502
+ // → Map { 'minecraft:throwable' => { do_swing_animation: true, launch_power_scale: 1.5, ... } }
503
+ ```
504
+
505
+ | 参数 | 类型 | 默认值 | 描述 |
506
+ |------|------|--------|------|
507
+ | `doSwingAnimation` | boolean | `false` | 是否使用挥动动画 |
508
+ | `launchPowerScale` | number | `1.0` | 投掷力量缩放 |
509
+ | `maxDrawDuration` | number | `0.0` | 最大蓄力时间 |
510
+ | `maxLaunchPower` | number | `1.0` | 最大投掷力量 |
511
+ | `minDrawDuration` | number | `0.0` | 最小蓄力时间 |
512
+ | `scalePowerByDrawDuration` | boolean | `false` | 力量是否随蓄力增加 |
513
+
514
+ ---
515
+
516
+ ### setProjectile(minimumCriticalPower?, projectileEntity?)
517
+
518
+ 设置投射物组件。
519
+
520
+ ```typescript
521
+ ItemComponent.setProjectile(0.5, 'minecraft:snowball')
522
+ // → Map { 'minecraft:projectile' => { minimum_critical_power: 0.5, projectile_entity: 'minecraft:snowball' } }
523
+ ```
524
+
525
+ | 参数 | 类型 | 描述 |
526
+ |------|------|------|
527
+ | `minimumCriticalPower` | number | 暴击所需的最小蓄力值 |
528
+ | `projectileEntity` | string | 发射的投射物实体 ID |
529
+
530
+ ---
531
+
532
+ ### setUseModifiers(options?)
533
+
534
+ 设置使用修饰组件。
535
+
536
+ ```typescript
537
+ ItemComponent.setUseModifiers({
538
+ movementModifier: 0.5,
539
+ useDuration: 1.5,
540
+ })
541
+ // → Map { 'minecraft:use_modifiers' => { movement_modifier: 0.5, use_duration: 1.5 } }
542
+ ```
543
+
544
+ | 参数 | 类型 | 描述 |
545
+ |------|------|------|
546
+ | `options.movementModifier` | number | 使用物品时玩家移动速度缩放值 |
547
+ | `options.useDuration` | number | 物品使用所需时间(秒) |
548
+ | `options.emitVibrations` | boolean | 是否在开始/停止使用时发出振动 |
549
+ | `options.startSound` | string | 开始使用时触发的原版音效 |
550
+ | `options.startUsing` | string | 使用修饰生效时机(`'always'` 或 `'if_first'`) |
551
+
552
+ ---
553
+
554
+ ### setUseAnimation(animation)
555
+
556
+ 设置使用动画。
557
+
558
+ ```typescript
559
+ ItemComponent.setUseAnimation('eat')
560
+ ItemComponent.setUseAnimation('drink')
561
+ // → Map { 'minecraft:use_animation' => 'eat' }
562
+ ```
563
+
564
+ | 参数 | 类型 | 描述 |
565
+ |------|------|------|
566
+ | `animation` | string | 动画类型(如 `'eat'`、`'drink'`) |
567
+
568
+ ---
569
+
570
+ ### setDurability(maxDurability, damageChanceMin?, damageChanceMax?)
571
+
572
+ 设置耐久度组件。
573
+
574
+ ```typescript
575
+ ItemComponent.setDurability(500, 10, 50)
576
+ // → Map { 'minecraft:durability' => { max_durability: 500, damage_chance: { min: 10, max: 50 } } }
577
+ ```
578
+
579
+ | 参数 | 类型 | 默认值 | 描述 |
580
+ |------|------|--------|------|
581
+ | `maxDurability` | number | — | 最大耐久值 |
582
+ | `damageChanceMin` | number | `0` | 最小损坏概率(百分比) |
583
+ | `damageChanceMax` | number | `100` | 最大损坏概率(百分比) |
584
+
585
+ ---
586
+
587
+ ### setInteractButton(text)
588
+
589
+ 设置交互按钮。支持字符串(自定义文案)或布尔值(通用 "Use Item" 文案)。
590
+
591
+ ```typescript
592
+ ItemComponent.setInteractButton('打开')
593
+ // → Map { 'minecraft:interact_button' => '打开' }
594
+ ItemComponent.setInteractButton(true)
595
+ // → Map { 'minecraft:interact_button' => true }
596
+ ```
597
+
598
+ | 参数 | 类型 | 描述 |
599
+ |------|------|------|
600
+ | `text` | string \| boolean | 交互时显示的文本,或 `true`/`false` |
601
+
602
+ ---
603
+
604
+ ### setBlockPlacer(block, options?)
605
+
606
+ 设置方块放置器组件。
607
+
608
+ ```typescript
609
+ ItemComponent.setBlockPlacer(
610
+ 'my_mod:custom_block', // 要放置的方块 ID
611
+ {
612
+ replaceBlockItem: false, // 是否替换方块物品(可选)
613
+ alignedPlacement: true, // 是否启用对齐放置(可选)
614
+ useOn: ['minecraft:dirt'], // 可放置的目标方块列表(可选)
615
+ }
616
+ )
617
+ // → Map { 'minecraft:block_placer' => { block: '...', replace_block_item: false, aligned_placement: true, use_on: [...] } }
618
+ ```
619
+
620
+ | 参数 | 类型 | 描述 |
621
+ |------|------|------|
622
+ | `block` | string | 要放置的方块标识符 |
623
+ | `options.replaceBlockItem` | boolean | 是否替换方块物品 |
624
+ | `options.alignedPlacement` | boolean | 是否启用对齐放置 |
625
+ | `options.useOn` | BlockDescriptor[] | 可使用此物品的方块描述符列表 |
626
+
627
+ ---
628
+
629
+ ### setCustomComponentV2(componentId, params)
630
+
631
+ 设置自定义 V2 组件(需要 format_version > 1.21.90 和 Scripting V2)。
632
+
633
+ ```typescript
634
+ ItemComponent.setCustomComponentV2(
635
+ 'my_mod:my_component',
636
+ { speed: 1.5, damage: 10 }
637
+ )
638
+ // → Map { 'my_mod:my_component' => { speed: 1.5, damage: 10 } }
639
+ ```
640
+
641
+ | 参数 | 类型 | 描述 |
642
+ |------|------|------|
643
+ | `componentId` | string | 组件标识符 |
644
+ | `params` | object | 自定义参数对象 |
645
+
646
+ ---
647
+
648
+ ### combineComponents(...maps)
649
+
650
+ 将多个组件 Map 合并为一个。
651
+
652
+ ```typescript
653
+ const combined = ItemComponent.combineComponents(
654
+ ItemComponent.setDisplayName('神剑'),
655
+ ItemComponent.setHandEquipped(true),
656
+ ItemComponent.setDurability(1000),
657
+ )
658
+ // → Map { 'minecraft:display_name': ..., 'minecraft:hand_equipped': ..., 'minecraft:durability': ... }
659
+ ```
660
+
661
+ | 参数 | 类型 | 描述 |
662
+ |------|------|------|
663
+ | `...componentMaps` | Map[] | 多个组件 Map |
664
+
665
+ **返回值:** `Map` — 合并后的组件集合。
666
+
667
+ ---
668
+
669
+ ### toJSON(components)
670
+
671
+ 将组件 Map 转换为普通 JSON 对象。
672
+
673
+ ```typescript
674
+ const map = ItemComponent.setDisplayName('测试')
675
+ const json = ItemComponent.toJSON(map)
676
+ // → { 'minecraft:display_name': { value: '测试' } }
677
+ ```
678
+
679
+ | 参数 | 类型 | 描述 |
680
+ |------|------|------|
681
+ | `components` | Map | 组件集合 |
682
+
683
+ **返回值:** `object` — JSON 对象。
684
+
685
+ ---
686
+
687
+ ### setCustomComponents(customComponents)
688
+
689
+ 设置自定义组件数组。
690
+
691
+ ```typescript
692
+ ItemComponent.setCustomComponents(['my_mod:my_component'])
693
+ // → Map { 'my_mod:my_component' => {} }
694
+ ```
695
+
696
+ | 参数 | 类型 | 描述 |
697
+ |------|------|------|
698
+ | `customComponents` | string[] | 自定义组件标识符数组 |
699
+
700
+ ---
701
+
702
+ ### 更多组件(对齐 Bedrock Wiki 1.26.30)
703
+
704
+ 以下方法均参考 [Bedrock Wiki Item Components](https://wiki.bedrock.dev/items/item-components),覆盖 wiki 收录的全部组件。
705
+
706
+ **布尔/数值/字符串组件:**
707
+
708
+ | 方法 | JSON 组件 | 描述 |
709
+ |------|-----------|------|
710
+ | `setAllowOffHand(allowed)` | `minecraft:allow_off_hand` | 是否可装备至副手 |
711
+ | `setCanDestroyInCreative(can)` | `minecraft:can_destroy_in_creative` | 创造模式下能否破坏方块 |
712
+ | `setDamage(damage)` | `minecraft:damage` | 额外攻击伤害(0-32767) |
713
+ | `setHoverTextColor(color)` | `minecraft:hover_text_color` | 物品名颜色 |
714
+ | `setLiquidClipped(clipped)` | `minecraft:liquid_clipped` | 是否在液体内部交互 |
715
+ | `setRarity(rarity)` | `minecraft:rarity` | 稀有度(`common`/`uncommon`/`rare`/`epic`) |
716
+ | `setShouldDespawn(should)` | `minecraft:should_despawn` | 掉落物是否最终消失 |
717
+ | `setStackedByData(stacked)` | `minecraft:stacked_by_data` | 不同数据值的物品是否分开堆叠 |
718
+ | `setSwingDuration(value)` | `minecraft:swing_duration` | 挥动动画时长(秒) |
719
+ | `setCompostable(chance)` | `minecraft:compostable` | 堆肥成功率(0-100) |
720
+ | `setBundleInteraction(numSlots)` | `minecraft:bundle_interaction` | Bundle 可查看槽位数(1-64) |
721
+
722
+ **对象组件:**
723
+
724
+ ```typescript
725
+ // 冷却
726
+ ItemComponent.setCooldown({ category: 'wiki:cd', duration: 0.2, type: 'use' })
727
+ // → { category, duration, type? }
728
+
729
+ // 伤害吸收(需搭配 durability 与盔甲槽位)
730
+ ItemComponent.setDamageAbsorption(['all'])
731
+
732
+ // 挖掘
733
+ ItemComponent.setDigger({
734
+ destroySpeeds: [{ block: 'minecraft:gravel', speed: 0 }, { block: { tags: "q.any_tag('x')" }, speed: 6 }],
735
+ useEfficiency: true,
736
+ })
737
+
738
+ // 耐久传感器
739
+ ItemComponent.setDurabilitySensor({
740
+ durabilityThresholds: [{ durability: 100, particleType: 'minecraft:explosion_manual', soundEvent: 'blast' }],
741
+ })
742
+
743
+ // 可染色
744
+ ItemComponent.setDyeable('#ffffff')
745
+
746
+ // 可附魔
747
+ ItemComponent.setEnchantable('sword', 10)
748
+
749
+ // 放置实体
750
+ ItemComponent.setEntityPlacer('minecraft:spider', { useOn: ['minecraft:dirt'], dispenseOn: ['minecraft:dirt'] })
751
+
752
+ // 防火
753
+ ItemComponent.setFireResistant(true)
754
+
755
+ // 动能武器
756
+ ItemComponent.setKineticWeapon({
757
+ delay: 15,
758
+ reach: { min: 2.0, max: 4.5 },
759
+ creativeReach: { min: 2.0, max: 7.5 },
760
+ hitboxMargin: 0.25,
761
+ damageMultiplier: 0.7,
762
+ damageConditions: { max_duration: 300 },
763
+ knockbackConditions: { min_speed: 5.1 },
764
+ dismountConditions: { min_speed: 14.0 },
765
+ })
766
+
767
+ // 穿刺武器
768
+ ItemComponent.setPiercingWeapon({ reach: { min: 2.0, max: 4.5 }, creativeReach: { min: 2.0, max: 7.5 } })
769
+
770
+ // 唱片
771
+ ItemComponent.setRecord({ comparatorSignal: 1, duration: 5, soundEvent: 'bucket.empty.powder_snow' })
772
+
773
+ // 可修复
774
+ ItemComponent.setRepairable([
775
+ { items: ['minecraft:diamond'], repairAmount: 10 },
776
+ { items: [{ tags: "q.any_tag('minecraft:planks')" }], repairAmount: 'q.max_durability * 0.25' },
777
+ ])
778
+
779
+ // 射击(需搭配 use_modifiers)
780
+ ItemComponent.setShooter({
781
+ ammunition: [{ item: 'minecraft:arrow', searchInventory: true, useInCreative: true, useOffhand: true }],
782
+ scalePowerByDrawDuration: true,
783
+ })
784
+
785
+ // 容器物品(需 max_stack_size 为 1)
786
+ ItemComponent.setStorageItem({
787
+ maxSlots: 64,
788
+ allowNestedStorageItems: true,
789
+ bannedItems: ['minecraft:shulker_box'],
790
+ })
791
+
792
+ // 容器重量上限(需搭配 storage_item)
793
+ ItemComponent.setStorageWeightLimit(64)
794
+
795
+ // 容器重量修正(0 表示禁止放入其他容器)
796
+ ItemComponent.setStorageWeightModifier(4)
797
+
798
+ // 挥砍音效
799
+ ItemComponent.setSwingSounds({
800
+ attackMiss: 'item.wooden_spear.attack_miss',
801
+ attackHit: 'item.wooden_spear.attack_hit',
802
+ attackCriticalHit: 'item.wooden_spear.attack_critical_hit',
803
+ })
804
+
805
+ // 标签
806
+ ItemComponent.setTags(['wiki:custom_tag'])
807
+ ```
808
+
809
+ ---
810
+
811
+ ## 4. Armor 类
812
+
813
+ 盔甲系统已重构为数据驱动结构:单一 `Armor` 类 + `ArmorType` 枚举,内部创建 `Item` 和 `Attachable` 实例。
814
+
815
+ ### Armor 构造
816
+
817
+ ```typescript
818
+ import { Armor, ArmorType } from '@sapdon/core'
819
+
820
+ new Armor(identifier, item_texture, texture_path, type, options?)
821
+ ```
822
+
823
+ | 属性/方法 | 类型 | 描述 |
824
+ |-----------|------|------|
825
+ | `type` | ArmorType | 盔甲类型 |
826
+ | `item` | Item | 关联的物品实例 |
827
+ | `attachable` | Attachable | 关联的可附着物实例 |
828
+ | `setAttachableGeometry(key, geometry)` | this | 设置可附着物几何模型 |
829
+ | `toObject()` | object | 返回 `{ behavior, resource }` 两包 JSON |
830
+
831
+ ### 类型对照表
832
+
833
+ | ArmorType | 创建方法 | 保护值 | 插槽 | 几何模型 | 脚本 |
834
+ |----|---------|--------|------|---------|------|
835
+ | **Helmet** | `ItemAPI.createHelmetArmor()` | 3 | `slot.armor.head` | `geometry.player.armor.helmet` | `v.helmet_layer_visible = 0.0;` |
836
+ | **Chestplate** | `ItemAPI.createChestplateArmor()` | 5 | `slot.armor.chest` | `geometry.player.armor.chestplate` | `v.chest_layer_visible = 0.0;` |
837
+ | **Leggings** | `ItemAPI.createLeggingsArmor()` | 6 | `slot.armor.legs` | `geometry.player.armor.leggings` | `v.leg_layer_visible = 0.0;` |
838
+ | **Boots** | `ItemAPI.createBootArmor()` | 4 | `slot.armor.feet` | `geometry.player.armor.boots` | `v.boot_layer_visible = 0.0;` |
839
+
840
+ ### 默认配置
841
+
842
+ 所有盔甲类型自动配置以下属性:
843
+
844
+ - 分类:`'equipment'`
845
+ - 分组:对应的 `itemGroup.name.*`
846
+ - 最大堆叠数量:`1`
847
+ - 显示名称:各类型的默认名称(可通过 `options.displayName` 覆盖)
848
+ - 纹理:通过 `texture_path` 参数指定
849
+ - 材质:`'armor'`(默认)和 `'armor_enchanted'`(附魔)
850
+ - 渲染控制器:`'controller.render.armor'`
851
+
852
+ ```typescript
853
+ // 自定义盔甲几何模型示例
854
+ ItemAPI.createHelmetArmor('my_mod:custom_helmet', 'custom_helmet', 'textures/models/armor/custom')
855
+ .setAttachableGeometry('default', 'geometry.custom.helmet')
856
+ ```
857
+
858
+ ---
859
+
860
+ ## 5. Food 类
861
+
862
+ `Food` 继承自 `Item`,自动添加食物相关组件。
863
+
864
+ ```typescript
865
+ class Food extends Item {
866
+ constructor(identifier, category, texture, options?)
867
+ }
868
+ ```
869
+
870
+ ### 构造函数自动添加的组件
871
+
872
+ | 组件 | 来源 |
873
+ |------|------|
874
+ | `minecraft:icon` | 父类构造 |
875
+ | `minecraft:max_stack_size` | 父类构造 |
876
+ | `minecraft:use_modifiers` | Food 构造 |
877
+ | `minecraft:food` | Food 构造 |
878
+ | `minecraft:use_animation` | Food 构造 |
879
+
880
+ ```typescript
881
+ import { Food, ItemCategory } from '@sapdon/core'
882
+
883
+ const food = new Food('my_mod:apple', ItemCategory.Items, 'apple', {
884
+ nutrition: 8,
885
+ saturationModifier: 1.5,
886
+ canAlwaysEat: true,
887
+ animation: 'eat',
888
+ movement: 0.8,
889
+ useDuration: 1.5,
890
+ })
891
+ ```
892
+
893
+ ---
894
+
895
+ ## 6. ItemCategory 枚举
896
+
897
+ `ItemCategory` 提供标准的创造模式物品栏分类。
898
+
899
+ ```typescript
900
+ enum ItemCategory {
901
+ Commands = 'commands', // 命令分类
902
+ Construction = 'construction', // 建筑分类
903
+ Equipment = 'equipment', // 装备分类
904
+ Nature = 'nature', // 自然分类
905
+ Items = 'items', // 物品分类
906
+ None = 'none', // 无分类
907
+ }
908
+ ```
909
+
910
+ ### 使用示例
911
+
912
+ ```typescript
913
+ import { ItemAPI, ItemCategory } from '@sapdon/core'
914
+
915
+ ItemAPI.createItem('test:item', ItemCategory.Construction, 'tex')
916
+ ```
917
+
918
+ > **注意:** `category` 参数为严格枚举类型,传 `'construction'` 等裸字符串会报 TS 编译错误,并会在运行时校验失败。必须使用 `ItemCategory.Construction` 等枚举成员。
919
+
920
+ ---
921
+
922
+ ## 7. Attachable 类
923
+
924
+ `Attachable` 用于创建可附着物(attachables),实现手持 3D 模型或穿戴物品渲染。继承自 `AddonAttachableDescription`。
925
+
926
+ ### 构造函数
927
+
928
+ ```typescript
929
+ import { Attachable } from '@sapdon/core'
930
+
931
+ const att = new Attachable('my_mod:my_attachable')
932
+ ```
933
+
934
+ ### 方法
935
+
936
+ | 方法 | 描述 |
937
+ |------|------|
938
+ | `addMaterial(name, material)` | 添加材质(如 `'default'`, `'entity_alphatest'`) |
939
+ | `addTexture(name, texture)` | 添加纹理路径 |
940
+ | `addGeometry(name, geometry)` | 添加几何模型标识符 |
941
+ | `addAnimation(name, animation)` | 添加动画 |
942
+ | `addAnimationController(name, controller)` | 添加动画控制器 |
943
+ | `addRenderController(controller)` | 添加渲染控制器 |
944
+ | `addLocator(name, locator)` | 添加定位器 |
945
+ | `setScript(key, value)` | 设置脚本变量 |
946
+ | `getId()` | 获取标识符 |
947
+ | `toObject()` | 序列化为 JSON |
948
+
949
+ ### 完整示例
950
+
951
+ ```typescript
952
+ const att = new Attachable('my_mod:custom_armor')
953
+ att
954
+ .addMaterial('default', 'armor')
955
+ .addMaterial('enchanted', 'armor_enchanted')
956
+ .addTexture('default', 'textures/models/armor/custom_main')
957
+ .addTexture('enchanted', 'textures/misc/enchanted_actor_glint')
958
+ .addGeometry('default', 'geometry.player.armor.chestplate')
959
+ .addRenderController('controller.render.armor')
960
+ .setScript('parent_setup', 'v.chest_layer_visible = 0.0;')
961
+ ```
962
+
963
+ ---
964
+
965
+ ## 8. 注册流程
966
+
967
+ 所有通过 `ItemAPI` 创建的对象会自动注册到游戏。但如果你手动创建 `Item` 或需要提交注册数据,需要调用 `registry.submit()`。
968
+
969
+ ### 基本流程
970
+
971
+ ```typescript
972
+ import { ItemAPI, registry, ItemComponent, ItemCategory } from '@sapdon/core'
973
+
974
+ // 1. 创建物品(自动注册到全局注册表)
975
+ ItemAPI.createItem('my_mod:sword', ItemCategory.Equipment, 'sword')
976
+
977
+ // 2. 提交所有注册数据到游戏引擎
978
+ // 必须在所有物品创建完成后调用
979
+ registry.submit()
980
+ ```
981
+
982
+ ### 手动注册
983
+
984
+ ```typescript
985
+ import { GRegistry } from '@sapdon/core'
986
+
987
+ // 手动注册物品数据
988
+ GRegistry.register(
989
+ 'my_item', // name: string — 文件名(不含扩展名)
990
+ 'behavior', // root: string — 根目录('behavior' / 'resource')
991
+ 'items/', // path: string — 子目录
992
+ itemDataObject // data: object — 数据对象(需有 toObject 方法)
993
+ )
994
+
995
+ // 提交
996
+ GRegistry.submit()
997
+ ```
998
+
999
+ ### registry 命名空间
1000
+
1001
+ ```typescript
1002
+ import { registry } from '@sapdon/core'
1003
+
1004
+ // 提交所有注册数据
1005
+ registry.submit()
1006
+ ```
1007
+
1008
+ ### 完整工作流
1009
+
1010
+ ```typescript
1011
+ // main.ts
1012
+ import { ItemAPI, registry, ItemComponent, ItemCategory } from '@sapdon/core'
1013
+
1014
+ // === 定义所有物品 ===
1015
+
1016
+ // 基础物品
1017
+ ItemAPI.createItem('my_mod:materials', ItemCategory.Items, 'materials')
1018
+ .addComponent(ItemComponent.setDisplayName('§b基础材料'))
1019
+
1020
+ // 食物
1021
+ ItemAPI.createFood('my_mod:food', ItemCategory.Items, 'food', {
1022
+ nutrition: 8,
1023
+ saturationModifier: 1.5,
1024
+ })
1025
+
1026
+ // 盔甲
1027
+ ItemAPI.createHelmetArmor('my_mod:helmet', 'helmet', 'textures/models/armor/set')
1028
+ ItemAPI.createChestplateArmor('my_mod:chestplate', 'chestplate', 'textures/models/armor/set')
1029
+
1030
+ // === 提交注册 ===
1031
+ registry.submit()
1032
+ ```
1033
+
1034
+ > **重要**:`registry.submit()` 必须在所有物品创建完成后调用一次,且通常在文件末尾执行。
1035
+
1036
+ ---
1037
+
1038
+ ## 9. ItemCatalog 类
1039
+
1040
+ 参考 [Bedrock Wiki Item Catalog](https://wiki.bedrock.dev/items/item-catalog),用于生成行为包 `BP/item_catalog/crafting_item_catalog.json`,指定物品在创造菜单与配方手册中的分组位置。
1041
+
1042
+ ### 构造与注册
1043
+
1044
+ ```typescript
1045
+ import { ItemAPI, ItemCatalog } from '@sapdon/core'
1046
+
1047
+ // 方式一:ItemAPI 工厂(自动注册)
1048
+ const catalog = ItemAPI.createItemCatalog() // 默认 format_version "1.26.30"
1049
+
1050
+ // 方式二:直接使用类(需手动 register)
1051
+ const catalog2 = new ItemCatalog().register()
1052
+ ```
1053
+
1054
+ ### addGroup(category, items, options?)
1055
+
1056
+ 添加一组物品到指定分类。分类仅支持 `construction` / `equipment` / `items` / `nature`。
1057
+
1058
+ ```typescript
1059
+ catalog.addGroup('nature', ['wiki:silver_ore', 'wiki:steel_ore'], {
1060
+ icon: 'wiki:silver_ore', // 分组图标(可选)
1061
+ name: 'wiki:itemGroup.name.ore' // 分组本地化键(可选,需同时在 .lang 中定义)
1062
+ })
1063
+ ```
1064
+
1065
+ | 参数 | 类型 | 描述 |
1066
+ |------|------|------|
1067
+ | `category` | string | 创造菜单分类(`construction`/`equipment`/`items`/`nature`) |
1068
+ | `items` | string[] | 物品标识符列表 |
1069
+ | `options.icon` | string | 分组图标物品 |
1070
+ | `options.name` | string | 分组本地化键,可用作物品/方块的 `menu_category.group` |
1071
+
1072
+ ### addItem(category, item, options?)
1073
+
1074
+ 添加单个物品到指定分类(内部调用 `addGroup(category, [item], options)`)。
1075
+
1076
+ ```typescript
1077
+ catalog.addItem('items', 'wiki:custom_item')
1078
+ ```
1079
+
1080
+ ### register()
1081
+
1082
+ 将目录注册到行为包 `item_catalog/` 目录,返回当前实例。
1083
+
1084
+ ### toObject()
1085
+
1086
+ ```typescript
1087
+ ItemAPI.createItemCatalog()
1088
+ .addGroup('nature', ['wiki:silver_ore', 'wiki:steel_ore'], { icon: 'wiki:silver_ore', name: 'wiki:itemGroup.name.ore' })
1089
+ .addItem('items', 'wiki:custom_item')
1090
+ .toObject()
1091
+ // → {
1092
+ // format_version: '1.26.30',
1093
+ // 'minecraft:crafting_items_catalog': {
1094
+ // categories: [
1095
+ // { category_name: 'nature', groups: [{ group_identifier: { icon: 'wiki:silver_ore', name: 'wiki:itemGroup.name.ore' }, items: ['wiki:silver_ore', 'wiki:steel_ore'] }] },
1096
+ // { category_name: 'items', groups: [{ items: ['wiki:custom_item'] }] },
1097
+ // ],
1098
+ // },
1099
+ // }
1100
+ ```
1101
+
1102
+ ### 完整示例
1103
+
1104
+ ```typescript
1105
+ import { ItemAPI, registry } from '@sapdon/core'
1106
+
1107
+ // 定义物品
1108
+ ItemAPI.createItem('wiki:silver_ore', ItemCategory.Nature, 'silver_ore')
1109
+ ItemAPI.createItem('wiki:steel_ore', ItemCategory.Nature, 'steel_ore')
1110
+
1111
+ // 添加到创造菜单分组
1112
+ ItemAPI.createItemCatalog()
1113
+ .addGroup('nature', ['wiki:silver_ore', 'wiki:steel_ore'], {
1114
+ icon: 'wiki:silver_ore',
1115
+ name: 'wiki:itemGroup.name.ore',
1116
+ })
1117
+
1118
+ registry.submit()
1119
+ ```
1120
+
1121
+ 对应的 `RP/texts/en_US.lang` 需包含本地化文本:
1122
+
1123
+ ```
1124
+ wiki:itemGroup.name.ore=Custom Ores
1125
+ ```