sapdon 3.3.3 → 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.
- package/README.md +17 -7
- package/doc/dev/architecture.md +418 -415
- package/doc/dev/cli.md +467 -467
- package/doc/dev/core.md +751 -717
- package/doc/dev/lr-paradigm.md +85 -0
- package/doc/dev/workflow.md +257 -0
- package/doc/hello_sapdon/hello_sapdon.md +3 -3
- package/doc/user/api/block.md +599 -14
- package/doc/user/api/item.md +284 -55
- package/doc/user/api/neo-guidebook.md +409 -0
- package/doc/user/api/sapdon-ui.md +185 -0
- package/doc/user/config/build-config.md +4 -5
- package/doc/user/quick-start.md +20 -6
- package/doc/user/tutorials/block.md +12 -1
- package/doc/user/tutorials/item.md +3 -3
- package/doc/user/tutorials/neo-guidebook-experience.md +381 -0
- package/doc/user/tutorials/neo-guidebook.md +640 -0
- package/doc/user/tutorials/sapdon-ui.md +207 -0
- package/package.json +5 -1
- package/prod/cli/index.js +1 -1
- package/prod/cli/start.js +1 -1
- package/prod/core/index.d.ts +1557 -299
- package/prod/core/index.js +1 -1
- package/prod/oc/index.d.ts +3 -1
- package/prod/oc/index.js +1 -1
- package/prod/utils/index.d.ts +0 -7
- package/prod/utils/index.js +1 -1
package/doc/user/api/item.md
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
6. [ItemCategory 枚举](#6-itemcategory-枚举)
|
|
15
15
|
7. [Attachable 类](#7-attachable-类)
|
|
16
16
|
8. [注册流程](#8-注册流程)
|
|
17
|
+
9. [ItemCatalog 类](#9-itemcatalog-类)
|
|
17
18
|
|
|
18
19
|
---
|
|
19
20
|
|
|
@@ -46,10 +47,10 @@ const item = ItemAPI.createItem(
|
|
|
46
47
|
| 参数 | 类型 | 必填 | 描述 |
|
|
47
48
|
|------|------|------|------|
|
|
48
49
|
| `identifier` | string | 是 | 物品唯一标识符,格式 `namespace:name` |
|
|
49
|
-
| `category` |
|
|
50
|
+
| `category` | ItemCategory | 是 | 创造模式物品栏分类,见 `ItemCategory` 枚举 |
|
|
50
51
|
| `texture` | string | 是 | 纹理名称 |
|
|
51
52
|
| `options.group` | string | 否 | 物品分组 |
|
|
52
|
-
| `options.hide_in_command` | boolean | 否 | 是否在命令自动补全中隐藏(默认 false
|
|
53
|
+
| `options.hide_in_command` | boolean | 否 | 是否在命令自动补全中隐藏(默认 false) |
|
|
53
54
|
| `options.max_stack_size` | number | 否 | 最大堆叠数量(默认 64,范围 1-99) |
|
|
54
55
|
| `options.format_version` | string | 否 | 格式版本(默认 `'1.21.40'`) |
|
|
55
56
|
|
|
@@ -86,7 +87,7 @@ const food = ItemAPI.createFood(
|
|
|
86
87
|
| 参数 | 类型 | 默认值 | 描述 |
|
|
87
88
|
|------|------|--------|------|
|
|
88
89
|
| `identifier` | string | — | 唯一标识符 |
|
|
89
|
-
| `category` |
|
|
90
|
+
| `category` | ItemCategory | — | 创造菜单分类 |
|
|
90
91
|
| `texture` | string | — | 纹理名称 |
|
|
91
92
|
| `options.group` | string | `undefined` | 物品分组 |
|
|
92
93
|
| `options.hide_in_command` | boolean | `false` | 是否在命令中隐藏 |
|
|
@@ -147,12 +148,12 @@ const chestplate = ItemAPI.createChestplateArmor(
|
|
|
147
148
|
'ruby_chestplate', // item_texture: string — 物品图标纹理
|
|
148
149
|
'textures/models/armor/ruby', // texture_path: string — 模型纹理路径
|
|
149
150
|
{ // options?: object
|
|
150
|
-
//
|
|
151
|
+
displayName: '红宝石胸甲', // 自定义显示名称(默认:"我的自定义胸甲")
|
|
151
152
|
}
|
|
152
153
|
)
|
|
153
154
|
```
|
|
154
155
|
|
|
155
|
-
**返回值:** `
|
|
156
|
+
**返回值:** `Armor` — 盔甲实例(`type === ArmorType.Chestplate`)。
|
|
156
157
|
|
|
157
158
|
---
|
|
158
159
|
|
|
@@ -168,7 +169,7 @@ const helmet = ItemAPI.createHelmetArmor(
|
|
|
168
169
|
)
|
|
169
170
|
```
|
|
170
171
|
|
|
171
|
-
**返回值:** `
|
|
172
|
+
**返回值:** `Armor` — 盔甲实例(`type === ArmorType.Helmet`)。
|
|
172
173
|
|
|
173
174
|
---
|
|
174
175
|
|
|
@@ -184,7 +185,7 @@ const boots = ItemAPI.createBootArmor(
|
|
|
184
185
|
)
|
|
185
186
|
```
|
|
186
187
|
|
|
187
|
-
**返回值:** `
|
|
188
|
+
**返回值:** `Armor` — 盔甲实例(`type === ArmorType.Boots`)。
|
|
188
189
|
|
|
189
190
|
---
|
|
190
191
|
|
|
@@ -200,7 +201,12 @@ const leggings = ItemAPI.createLeggingsArmor(
|
|
|
200
201
|
)
|
|
201
202
|
```
|
|
202
203
|
|
|
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 }`。
|
|
204
210
|
|
|
205
211
|
---
|
|
206
212
|
|
|
@@ -209,11 +215,11 @@ const leggings = ItemAPI.createLeggingsArmor(
|
|
|
209
215
|
创建翻书物品(动态帧动画物品)。
|
|
210
216
|
|
|
211
217
|
```typescript
|
|
212
|
-
import { ItemAPI } from '@sapdon/core'
|
|
218
|
+
import { ItemAPI, ItemCategory } from '@sapdon/core'
|
|
213
219
|
|
|
214
220
|
const flipbook = ItemAPI.createFlipbookItem(
|
|
215
221
|
'my_mod:animated_block', // identifier: string
|
|
216
|
-
|
|
222
|
+
ItemCategory.Construction, // category: ItemCategory
|
|
217
223
|
'my_flipbook_tex', // texture: string — 纹理名称
|
|
218
224
|
{
|
|
219
225
|
group: 'minecraft:itemGroup.name.construction',
|
|
@@ -230,7 +236,7 @@ const flipbook = ItemAPI.createFlipbookItem(
|
|
|
230
236
|
| 参数 | 类型 | 默认值 | 描述 |
|
|
231
237
|
|------|------|--------|------|
|
|
232
238
|
| `identifier` | string | — | 唯一标识符 |
|
|
233
|
-
| `category` |
|
|
239
|
+
| `category` | ItemCategory | — | 创造菜单分类 |
|
|
234
240
|
| `texture` | string | — | 纹理名称(位于 `textures/blocks/` 目录) |
|
|
235
241
|
| `options.group` | string | `undefined` | 物品分组 |
|
|
236
242
|
| `options.hide_in_command` | boolean | `false` | 是否在命令中隐藏 |
|
|
@@ -249,11 +255,11 @@ const flipbook = ItemAPI.createFlipbookItem(
|
|
|
249
255
|
### 构造函数
|
|
250
256
|
|
|
251
257
|
```typescript
|
|
252
|
-
import { Item } from '@sapdon/core'
|
|
258
|
+
import { Item, ItemCategory } from '@sapdon/core'
|
|
253
259
|
|
|
254
260
|
const item = new Item(
|
|
255
261
|
'my_mod:custom_item', // identifier: string — 唯一标识符
|
|
256
|
-
|
|
262
|
+
ItemCategory.Items, // category: ItemCategory — 创造菜单分类
|
|
257
263
|
'custom_texture', // texture: string — 纹理名称
|
|
258
264
|
{ // options?: object
|
|
259
265
|
group: '...',
|
|
@@ -269,7 +275,7 @@ const item = new Item(
|
|
|
269
275
|
| 参数 | 类型 | 默认值 | 描述 |
|
|
270
276
|
|------|------|--------|------|
|
|
271
277
|
| `identifier` | string | — | 唯一标识符 |
|
|
272
|
-
| `category` |
|
|
278
|
+
| `category` | ItemCategory | — | 创造菜单分类 |
|
|
273
279
|
| `texture` | string | — | 纹理名称 |
|
|
274
280
|
| `options.group` | string | `undefined` | 分组 |
|
|
275
281
|
| `options.hide_in_command` | boolean | `false` | 是否在命令中隐藏 |
|
|
@@ -348,16 +354,19 @@ const json = item.toObject()
|
|
|
348
354
|
|
|
349
355
|
### setIcon(texture)
|
|
350
356
|
|
|
351
|
-
|
|
357
|
+
设置物品图标纹理。支持字符串(默认纹理)或对象(多纹理)两种格式。
|
|
352
358
|
|
|
353
359
|
```typescript
|
|
354
360
|
ItemComponent.setIcon('my_texture')
|
|
355
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' } } }
|
|
356
365
|
```
|
|
357
366
|
|
|
358
367
|
| 参数 | 类型 | 描述 |
|
|
359
368
|
|------|------|------|
|
|
360
|
-
| `texture` | string |
|
|
369
|
+
| `texture` | string \| object | 纹理名称,或包含 `default`/`dyed`/`iconTrim`/`bundleOpenBack`/`bundleOpenFront` 的纹理对象 |
|
|
361
370
|
|
|
362
371
|
---
|
|
363
372
|
|
|
@@ -391,25 +400,30 @@ ItemComponent.setDisplayName('§c传奇之剑')
|
|
|
391
400
|
|
|
392
401
|
---
|
|
393
402
|
|
|
394
|
-
### setFoodComponent(
|
|
403
|
+
### setFoodComponent(options)
|
|
395
404
|
|
|
396
405
|
设置食物属性组件。
|
|
397
406
|
|
|
398
407
|
```typescript
|
|
399
|
-
ItemComponent.setFoodComponent(
|
|
400
|
-
|
|
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' } }
|
|
401
415
|
```
|
|
402
416
|
|
|
403
417
|
| 参数 | 类型 | 默认值 | 描述 |
|
|
404
418
|
|------|------|--------|------|
|
|
405
|
-
| `canAlwaysEat` | boolean |
|
|
406
|
-
| `nutrition` | number | `0` | 营养值 |
|
|
407
|
-
| `saturationModifier` | number | `0.6` | 饱和度修正值 |
|
|
408
|
-
| `usingConvertsTo` | string | `undefined` | 食用后转换的目标物品 ID |
|
|
419
|
+
| `options.canAlwaysEat` | boolean | `false` | 是否可随时食用 |
|
|
420
|
+
| `options.nutrition` | number | `0` | 营养值 |
|
|
421
|
+
| `options.saturationModifier` | number | `0.6` | 饱和度修正值 |
|
|
422
|
+
| `options.usingConvertsTo` | string | `undefined` | 食用后转换的目标物品 ID |
|
|
409
423
|
|
|
410
424
|
---
|
|
411
425
|
|
|
412
|
-
### setWearable(slot
|
|
426
|
+
### setWearable(protection?, slot?, hidesPlayerLocation?)
|
|
413
427
|
|
|
414
428
|
设置可穿戴组件。
|
|
415
429
|
|
|
@@ -429,6 +443,7 @@ ItemComponent.setWearable(4, 'slot.armor.feet')
|
|
|
429
443
|
|------|------|--------|------|
|
|
430
444
|
| `protection` | number | `0` | 保护值 |
|
|
431
445
|
| `slot` | string | `undefined` | 装备槽位(如 `'slot.armor.head'`) |
|
|
446
|
+
| `hidesPlayerLocation` | boolean | `undefined` | 穿戴时是否在定位栏与定位地图中隐藏 |
|
|
432
447
|
|
|
433
448
|
---
|
|
434
449
|
|
|
@@ -514,19 +529,25 @@ ItemComponent.setProjectile(0.5, 'minecraft:snowball')
|
|
|
514
529
|
|
|
515
530
|
---
|
|
516
531
|
|
|
517
|
-
### setUseModifiers(
|
|
532
|
+
### setUseModifiers(options?)
|
|
518
533
|
|
|
519
534
|
设置使用修饰组件。
|
|
520
535
|
|
|
521
536
|
```typescript
|
|
522
|
-
ItemComponent.setUseModifiers(
|
|
537
|
+
ItemComponent.setUseModifiers({
|
|
538
|
+
movementModifier: 0.5,
|
|
539
|
+
useDuration: 1.5,
|
|
540
|
+
})
|
|
523
541
|
// → Map { 'minecraft:use_modifiers' => { movement_modifier: 0.5, use_duration: 1.5 } }
|
|
524
542
|
```
|
|
525
543
|
|
|
526
544
|
| 参数 | 类型 | 描述 |
|
|
527
545
|
|------|------|------|
|
|
528
|
-
| `movementModifier` | number | 使用物品时玩家移动速度缩放值 |
|
|
529
|
-
| `useDuration` | number | 物品使用所需时间(秒) |
|
|
546
|
+
| `options.movementModifier` | number | 使用物品时玩家移动速度缩放值 |
|
|
547
|
+
| `options.useDuration` | number | 物品使用所需时间(秒) |
|
|
548
|
+
| `options.emitVibrations` | boolean | 是否在开始/停止使用时发出振动 |
|
|
549
|
+
| `options.startSound` | string | 开始使用时触发的原版音效 |
|
|
550
|
+
| `options.startUsing` | string | 使用修饰生效时机(`'always'` 或 `'if_first'`) |
|
|
530
551
|
|
|
531
552
|
---
|
|
532
553
|
|
|
@@ -565,37 +586,43 @@ ItemComponent.setDurability(500, 10, 50)
|
|
|
565
586
|
|
|
566
587
|
### setInteractButton(text)
|
|
567
588
|
|
|
568
|
-
|
|
589
|
+
设置交互按钮。支持字符串(自定义文案)或布尔值(通用 "Use Item" 文案)。
|
|
569
590
|
|
|
570
591
|
```typescript
|
|
571
592
|
ItemComponent.setInteractButton('打开')
|
|
572
593
|
// → Map { 'minecraft:interact_button' => '打开' }
|
|
594
|
+
ItemComponent.setInteractButton(true)
|
|
595
|
+
// → Map { 'minecraft:interact_button' => true }
|
|
573
596
|
```
|
|
574
597
|
|
|
575
598
|
| 参数 | 类型 | 描述 |
|
|
576
599
|
|------|------|------|
|
|
577
|
-
| `text` | string |
|
|
600
|
+
| `text` | string \| boolean | 交互时显示的文本,或 `true`/`false` |
|
|
578
601
|
|
|
579
602
|
---
|
|
580
603
|
|
|
581
|
-
### setBlockPlacer(block,
|
|
604
|
+
### setBlockPlacer(block, options?)
|
|
582
605
|
|
|
583
606
|
设置方块放置器组件。
|
|
584
607
|
|
|
585
608
|
```typescript
|
|
586
609
|
ItemComponent.setBlockPlacer(
|
|
587
|
-
'my_mod:custom_block',
|
|
588
|
-
|
|
589
|
-
|
|
610
|
+
'my_mod:custom_block', // 要放置的方块 ID
|
|
611
|
+
{
|
|
612
|
+
replaceBlockItem: false, // 是否替换方块物品(可选)
|
|
613
|
+
alignedPlacement: true, // 是否启用对齐放置(可选)
|
|
614
|
+
useOn: ['minecraft:dirt'], // 可放置的目标方块列表(可选)
|
|
615
|
+
}
|
|
590
616
|
)
|
|
591
|
-
// → Map { 'minecraft:block_placer' => { block: '...', replace_block_item: false, use_on: [...] } }
|
|
617
|
+
// → Map { 'minecraft:block_placer' => { block: '...', replace_block_item: false, aligned_placement: true, use_on: [...] } }
|
|
592
618
|
```
|
|
593
619
|
|
|
594
620
|
| 参数 | 类型 | 描述 |
|
|
595
621
|
|------|------|------|
|
|
596
622
|
| `block` | string | 要放置的方块标识符 |
|
|
597
|
-
| `replaceBlockItem` | boolean | 是否替换方块物品 |
|
|
598
|
-
| `
|
|
623
|
+
| `options.replaceBlockItem` | boolean | 是否替换方块物品 |
|
|
624
|
+
| `options.alignedPlacement` | boolean | 是否启用对齐放置 |
|
|
625
|
+
| `options.useOn` | BlockDescriptor[] | 可使用此物品的方块描述符列表 |
|
|
599
626
|
|
|
600
627
|
---
|
|
601
628
|
|
|
@@ -663,7 +690,7 @@ const json = ItemComponent.toJSON(map)
|
|
|
663
690
|
|
|
664
691
|
```typescript
|
|
665
692
|
ItemComponent.setCustomComponents(['my_mod:my_component'])
|
|
666
|
-
// → Map { '
|
|
693
|
+
// → Map { 'my_mod:my_component' => {} }
|
|
667
694
|
```
|
|
668
695
|
|
|
669
696
|
| 参数 | 类型 | 描述 |
|
|
@@ -672,40 +699,152 @@ ItemComponent.setCustomComponents(['my_mod:my_component'])
|
|
|
672
699
|
|
|
673
700
|
---
|
|
674
701
|
|
|
675
|
-
|
|
702
|
+
### 更多组件(对齐 Bedrock Wiki 1.26.30)
|
|
703
|
+
|
|
704
|
+
以下方法均参考 [Bedrock Wiki Item Components](https://wiki.bedrock.dev/items/item-components),覆盖 wiki 收录的全部组件。
|
|
676
705
|
|
|
677
|
-
|
|
706
|
+
**布尔/数值/字符串组件:**
|
|
678
707
|
|
|
679
|
-
|
|
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
|
+
**对象组件:**
|
|
680
723
|
|
|
681
724
|
```typescript
|
|
682
|
-
//
|
|
683
|
-
|
|
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?)
|
|
684
821
|
```
|
|
685
822
|
|
|
686
823
|
| 属性/方法 | 类型 | 描述 |
|
|
687
824
|
|-----------|------|------|
|
|
825
|
+
| `type` | ArmorType | 盔甲类型 |
|
|
688
826
|
| `item` | Item | 关联的物品实例 |
|
|
689
827
|
| `attachable` | Attachable | 关联的可附着物实例 |
|
|
690
|
-
| `
|
|
828
|
+
| `setAttachableGeometry(key, geometry)` | this | 设置可附着物几何模型 |
|
|
829
|
+
| `toObject()` | object | 返回 `{ behavior, resource }` 两包 JSON |
|
|
691
830
|
|
|
692
|
-
###
|
|
831
|
+
### 类型对照表
|
|
693
832
|
|
|
694
|
-
|
|
|
833
|
+
| ArmorType | 创建方法 | 保护值 | 插槽 | 几何模型 | 脚本 |
|
|
695
834
|
|----|---------|--------|------|---------|------|
|
|
696
835
|
| **Helmet** | `ItemAPI.createHelmetArmor()` | 3 | `slot.armor.head` | `geometry.player.armor.helmet` | `v.helmet_layer_visible = 0.0;` |
|
|
697
836
|
| **Chestplate** | `ItemAPI.createChestplateArmor()` | 5 | `slot.armor.chest` | `geometry.player.armor.chestplate` | `v.chest_layer_visible = 0.0;` |
|
|
698
837
|
| **Leggings** | `ItemAPI.createLeggingsArmor()` | 6 | `slot.armor.legs` | `geometry.player.armor.leggings` | `v.leg_layer_visible = 0.0;` |
|
|
699
|
-
| **
|
|
838
|
+
| **Boots** | `ItemAPI.createBootArmor()` | 4 | `slot.armor.feet` | `geometry.player.armor.boots` | `v.boot_layer_visible = 0.0;` |
|
|
700
839
|
|
|
701
840
|
### 默认配置
|
|
702
841
|
|
|
703
|
-
|
|
842
|
+
所有盔甲类型自动配置以下属性:
|
|
704
843
|
|
|
705
844
|
- 分类:`'equipment'`
|
|
706
845
|
- 分组:对应的 `itemGroup.name.*`
|
|
707
846
|
- 最大堆叠数量:`1`
|
|
708
|
-
-
|
|
847
|
+
- 显示名称:各类型的默认名称(可通过 `options.displayName` 覆盖)
|
|
709
848
|
- 纹理:通过 `texture_path` 参数指定
|
|
710
849
|
- 材质:`'armor'`(默认)和 `'armor_enchanted'`(附魔)
|
|
711
850
|
- 渲染控制器:`'controller.render.armor'`
|
|
@@ -713,7 +852,7 @@ new Armor(identifier, category, item_texture, texture_path, options?)
|
|
|
713
852
|
```typescript
|
|
714
853
|
// 自定义盔甲几何模型示例
|
|
715
854
|
ItemAPI.createHelmetArmor('my_mod:custom_helmet', 'custom_helmet', 'textures/models/armor/custom')
|
|
716
|
-
.
|
|
855
|
+
.setAttachableGeometry('default', 'geometry.custom.helmet')
|
|
717
856
|
```
|
|
718
857
|
|
|
719
858
|
---
|
|
@@ -739,9 +878,9 @@ class Food extends Item {
|
|
|
739
878
|
| `minecraft:use_animation` | Food 构造 |
|
|
740
879
|
|
|
741
880
|
```typescript
|
|
742
|
-
import { Food } from '@sapdon/core'
|
|
881
|
+
import { Food, ItemCategory } from '@sapdon/core'
|
|
743
882
|
|
|
744
|
-
const food = new Food('my_mod:apple',
|
|
883
|
+
const food = new Food('my_mod:apple', ItemCategory.Items, 'apple', {
|
|
745
884
|
nutrition: 8,
|
|
746
885
|
saturationModifier: 1.5,
|
|
747
886
|
canAlwaysEat: true,
|
|
@@ -773,12 +912,11 @@ enum ItemCategory {
|
|
|
773
912
|
```typescript
|
|
774
913
|
import { ItemAPI, ItemCategory } from '@sapdon/core'
|
|
775
914
|
|
|
776
|
-
// 使用枚举值
|
|
777
915
|
ItemAPI.createItem('test:item', ItemCategory.Construction, 'tex')
|
|
778
|
-
// 等价于
|
|
779
|
-
ItemAPI.createItem('test:item', 'construction', 'tex')
|
|
780
916
|
```
|
|
781
917
|
|
|
918
|
+
> **注意:** `category` 参数为严格枚举类型,传 `'construction'` 等裸字符串会报 TS 编译错误,并会在运行时校验失败。必须使用 `ItemCategory.Construction` 等枚举成员。
|
|
919
|
+
|
|
782
920
|
---
|
|
783
921
|
|
|
784
922
|
## 7. Attachable 类
|
|
@@ -894,3 +1032,94 @@ registry.submit()
|
|
|
894
1032
|
```
|
|
895
1033
|
|
|
896
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
|
+
```
|