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,751 @@
1
+ # Core 模块文档
2
+
3
+ `src/core/` 是 Sapdon 的核心库,提供 Minecraft Addon 的所有数据定义、业务逻辑、工厂 API 和注册系统。
4
+
5
+ ---
6
+
7
+ ## 1. 架构总览
8
+
9
+ 核心库采用 **三层架构**:
10
+
11
+ ```
12
+ ┌─────────────────────────────────────────────────────┐
13
+ │ 工厂/API 层 src/core/factory/ │
14
+ │ ItemAPI, EntityAPI, BlockAPI, RecipeAPI... │
15
+ │ 用户直接调用的静态 API,创建实例并调用 GRegistry 注册 │
16
+ ├─────────────────────────────────────────────────────┤
17
+ │ 业务逻辑层 src/core/{item,entity,block,biome,...}/ │
18
+ │ Item, Entity, Block, Biome, Feature... │
19
+ │ 封装组件操作,内部使用 addon/ 的 DTO 生成 JSON │
20
+ ├─────────────────────────────────────────────────────┤
21
+ │ DTO 层 src/core/addon/ │
22
+ │ AddonItem, AddonEntity, AddonBlock, AddonRecipe... │
23
+ │ 纯数据类,1:1 映射 Minecraft JSON Schema │
24
+ │ 每个类有 @Serializer 装饰的 toObject() 方法 │
25
+ └─────────────────────────────────────────────────────┘
26
+ ```
27
+
28
+ 外加:
29
+
30
+ | 模块 | 职责 |
31
+ |------|------|
32
+ | `registry.ts` | 客户端注册系统,通过 `transport/` 模块向 CLI dev server 提交数据 |
33
+ | `texture.js` | 纹理管理器(ItemTextureManager、TerrainTextureManager、FlipbookTextures) |
34
+ | `ui/` | Minecraft JSON UI 系统生成器 |
35
+ | `extra/` | 附加功能(客户端实体外观、载具基类) |
36
+ | `type.ts` | 共享 TypeScript 类型定义 |
37
+
38
+ ---
39
+
40
+ ## 2. 目录结构
41
+
42
+ ```
43
+ src/core/
44
+ ├── index.js # 包入口,聚合导出所有模块
45
+ ├── registry.ts # 注册系统 (GRegistry / registry.submit)
46
+ ├── transport/
47
+ │ └── client.ts # HTTP POST 客户端,向 CLI dev server 提交数据
48
+ ├── texture.js # 纹理管理器
49
+ ├── type.ts # 共享类型 (MaterialDesc, RideableComponent 等)
50
+
51
+ ├── addon/ # ── DTO 层 ──
52
+ │ ├── index.ts # 聚合导出
53
+ │ ├── biome.ts # AddonBiome, AddonBiomeDescription, AddonBiomeDefinition
54
+ │ ├── manifest.ts # AddonManifest, Header, Module, Dependency, Metadata
55
+ │ ├── menuCategory.ts # AddonMenuCategory
56
+ │ ├── featureRule.ts # AddonFeatureRule, Definition, Description
57
+ │ ├── block/block.ts # AddonBlock, AddonBlockDefinition, AddonBlockDescription
58
+ │ ├── entity/entity.ts # AddonEntity, AddonEntityDefinition, AddonEntityDescription
59
+ │ ├── entity/clientEntity.ts # AddonClientEntity, Definition, Description
60
+ │ ├── item/item.ts # AddonItem, AddonItemDefinition, AddonItemDescription
61
+ │ ├── item/attachable.ts # AddonAttachable, Definition, Description
62
+ │ ├── feature/oreFeature.ts # AddonOreFeature, Description, Definition
63
+ │ ├── controllers/ # 动画控制器 + 渲染控制器 DTO
64
+ │ └── recipe/ # 配方 DTO (baseRecipe, shaped, shapeless, furnace, data)
65
+
66
+ ├── item/ # ── 业务逻辑层 ──
67
+ │ ├── index.ts
68
+ │ ├── types.ts # ItemOptions / FoodOptions / ItemComponentMap 等
69
+ │ ├── item.ts # Item 基类
70
+ │ ├── itemComponents.ts # ItemComponent 静态工厂 (~50 个组件方法)
71
+ │ ├── food.ts # Food extends Item
72
+ │ ├── flipbookItem.ts # FlipbookItem (动画纹理物品)
73
+ │ ├── itemCatalog.ts # ItemCatalog (生成 item_catalog/crafting_item_catalog.json)
74
+ │ ├── attachable.ts # Attachable extends AddonAttachableDescription
75
+ │ └── armor.ts # Armor 数据表驱动 (ArmorType: Chestplate/Helmet/Boots/Leggings)
76
+
77
+ ├── entity/ # ── 业务逻辑层 ──
78
+ │ ├── index.ts
79
+ │ ├── entity.js # Entity (组合 BasicEntity + ClientEntity)
80
+ │ ├── basicEntity.js # BasicEntity (行为包实体)
81
+ │ ├── clientEntity.js # ClientEntity (资源包实体, extends AddonClientEntityDescription)
82
+ │ ├── dummyEntity.js # DummyEntity (无物理实体)
83
+ │ ├── nativeEntity.js # NativeEntity (基于原版实体)
84
+ │ ├── projectile.js # Projectile (抛射物)
85
+ │ ├── componets/ # 实体组件工厂
86
+ │ ├── behavior/ # AI 行为类 (tempt, randomStroll, pickupItem...)
87
+ │ ├── bundles/ # 组件包 (BasicMovementBundle)
88
+ │ ├── navigation/ # 导航组件
89
+ │ └── data/ # 原版实体数据 (nativeEntityData)
90
+
91
+ ├── block/ # ── 业务逻辑层 ──
92
+ │ ├── index.ts
93
+ │ ├── basicBlock.js # BasicBlock 基类
94
+ │ ├── block.js # Block (多变体方块)
95
+ │ ├── cropBlock.js # CropBlock (作物方块)
96
+ │ ├── geometryBlock.js # GeometryBlock (几何方块)
97
+ │ ├── rotatableBlock.js # RotatableBlock (可旋转方块)
98
+ │ ├── oreBlock.js # OreBlock (矿物 + 特征 + 特征规则组合)
99
+ │ ├── tileBlock.js # TileBlock (方块 + 实体组合)
100
+ │ └── blockComponent.js # BlockComponent 静态工厂 (~35 个组件方法)
101
+
102
+ ├── biome/ # ── 业务逻辑层 ──
103
+ │ ├── index.ts
104
+ │ ├── biome.js # Biome 类
105
+ │ └── biomeComponent.js # BiomeComponent 静态工厂
106
+
107
+ ├── feature/ # ── 业务逻辑层 ──
108
+ │ ├── index.ts
109
+ │ └── oreFeature.js # OreFeature 类
110
+
111
+ ├── feature-rule/ # ── 业务逻辑层 ──
112
+ │ ├── index.ts
113
+ │ ├── featureRule.js # FeatureRule 类
114
+ │ ├── condition/ # 特征放置条件 (biomeFilter, featureConditions)
115
+ │ └── distribution/ # 特征分布 (featureDistribution, coordinateDistribution)
116
+
117
+ ├── factory/ # ── 工厂/API 层 ──
118
+ │ ├── index.ts
119
+ │ ├── itemFactory.js # ItemAPI
120
+ │ ├── entityFactory.js # EntityAPI
121
+ │ ├── blockFactory.js # BlockAPI
122
+ │ ├── biomeFactory.js # BiomeAPI
123
+ │ ├── recipeFactory.js # RecipeAPI
124
+ │ ├── featureFactory.js # FeatureAPI
125
+ │ ├── uiFactory.js # UiAPI
126
+ │ └── itemExtra.ts # ItemCategory 枚举
127
+
128
+ ├── ui/ # ── UI 系统 ──
129
+ │ ├── index.ts
130
+ │ ├── export.js # 聚合导出所有 UI 组件
131
+ │ ├── buttonMapping.js # ButtonMapping 类
132
+ │ ├── dataBindingObject.js # DataBindingObject 类
133
+ │ ├── elements/ # UI 元素 (UIElement, Panel, Button, Image, Label, Grid...)
134
+ │ ├── properties/ # UI 属性 (Control, Layout, DataBinding, Sprite, Text...)
135
+ │ └── systems/ # UI 系统 (UISystem, Chest, ServerForm, Guidebook, HUD, NeoGuidebook...)
136
+
137
+ └── extra/ # ── 附加模块 ──
138
+ ├── apperance.ts # ClientEntityApperance (实体外观管理)
139
+ └── vehicle.ts # BaseVehicle (载具基类)
140
+ ```
141
+
142
+ ---
143
+
144
+ ## 3. DTO 层 (`addon/`)
145
+
146
+ DTO (Data Transfer Object) 是框架的最底层,每个类对应一个 Minecraft JSON Schema。所有 DTO 类都有一个 `@Serializer` 装饰的 `toObject()` 方法,输出标准的 Minecraft JSON 格式。
147
+
148
+ ### 3.1 通用结构
149
+
150
+ ```typescript
151
+ class AddonXXX {
152
+ @Serializer
153
+ toObject() {
154
+ return {
155
+ format_version: "1.XX.0",
156
+ "minecraft:xxx": { // Schema 标识符
157
+ description: { ... },
158
+ components: { ... }
159
+ }
160
+ }
161
+ }
162
+ }
163
+ ```
164
+
165
+ ### 3.2 完整 DTO 列表
166
+
167
+ | 文件 | 类 | 输出 JSON Schema |
168
+ |------|---|-----------------|
169
+ | `item/item.ts` | `AddonItem`, `AddonItemDefinition`, `AddonItemDescription` | `minecraft:item` |
170
+ | `item/attachable.ts` | `AddonAttachable`, `AddonAttachableDefinition`, `AddonAttachableDescription` | `minecraft:attachable` |
171
+ | `entity/entity.ts` | `AddonEntity`, `AddonEntityDefinition`, `AddonEntityDescription` | `minecraft:entity` |
172
+ | `entity/clientEntity.ts` | `AddonClientEntity`, `AddonClientEntityDefinition`, `AddonClientEntityDescription` | `minecraft:client_entity` |
173
+ | `block/block.ts` | `AddonBlock`, `AddonBlockDefinition`, `AddonBlockDescription` | `minecraft:block` |
174
+ | `biome.ts` | `AddonBiome`, `AddonBiomeDescription`, `AddonBiomeDefinition` | `minecraft:biome` |
175
+ | `featureRule.ts` | `AddonFeatureRule`, `AddonFeatureRuleDenifition`, `AddonFeatureRuleDecription` | `minecraft:feature_rules` |
176
+ | `feature/oreFeature.ts` | `AddonOreFeature`, `AddonOreFeatureDescription`, `AddonOreFeatureDefinition` | `minecraft:ore_feature` |
177
+ | `controllers/animationController.ts` | `AddonAnimationController`, `AddonAnimationStateMachine` | `animation_controllers` |
178
+ | `controllers/render_controllers.ts` | `AddonRenderControllerGroup`, `AddonRenderController` | `render_controllers` |
179
+ | `recipe/baseRecipe.ts` | `AddonRecipe` (基类) | 各类配方 |
180
+ | `recipe/shaped.ts` | `AddonRecipeShaped` 及版本变体 | `minecraft:recipe_shaped` |
181
+ | `recipe/shapeless.ts` | `AddonRecipeShapeless` 及版本变体 | `minecraft:recipe_shapeless` |
182
+ | `recipe/furnace.ts` | `AddonRecipeFurnace` 及版本变体 | `minecraft:recipe_furnace` |
183
+ | `manifest.ts` | `AddonManifest`, `AddonManifestHeader`, `AddonManifestModule` | `manifest.json` |
184
+ | `menuCategory.ts` | `AddonMenuCategory` | 菜单分类 |
185
+
186
+ ### 3.3 序列化机制
187
+
188
+ 序列化系统定义在 `src/utils/serializable.ts`:
189
+
190
+ - `@Serializer` — 方法装饰器,标记 `toObject()` 为序列化方法
191
+ - `serialize(instance)` — 查找实例的序列化器并调用
192
+ - 序列化器存储在 `WeakMap<Constructor, ISerializer>` 中
193
+
194
+ DTO 层是生产方,业务逻辑层的 `toObject()` 委托给 DTO 的 `@Serializer`:
195
+
196
+ ```typescript
197
+ // 业务逻辑层 (Item)
198
+ class Item {
199
+ @Serializer
200
+ toObject() {
201
+ const dto = new AddonItem(this.identifier, ...)
202
+ return serialize(dto) // → 调用 AddonItem 的 @Serializer
203
+ }
204
+ }
205
+ ```
206
+
207
+ ### 3.4 配方数据常量 (`recipe/data.ts`)
208
+
209
+ | 导出 | 说明 |
210
+ |------|------|
211
+ | `RecipeInputTags` | 52 个物品标签映射 (e.g. `Armor: "minecraft:is_armor"`) |
212
+ | `RecipeTags` | 配方站标识 (Furnace, smoker, Campfire, CraftingTable) |
213
+ | `RecipeTypes` | 配方类型标识 (Furnace, Shaped, Shapeless) |
214
+
215
+ ---
216
+
217
+ ## 4. 业务逻辑层
218
+
219
+ ### 4.1 Item 体系
220
+
221
+ ```
222
+ Item
223
+ ├── Food (食物物品)
224
+ ├── FlipbookItem (动画纹理物品)
225
+ └── Armor (盔甲,ArmorType 数据表驱动)
226
+
227
+ Attachable (extends AddonAttachableDescription,独立体系)
228
+ ```
229
+
230
+ #### `Item` (`item/item.ts`)
231
+
232
+ | 方法 | 说明 |
233
+ |------|------|
234
+ | `constructor(identifier, category, texture, options)` | 创建物品,默认添加 icon + max_stack_size 组件(`options.icon` 传 `null` 可跳过 icon) |
235
+ | `addComponent(componentMap)` | 添加组件 Map |
236
+ | `removeComponent(key)` | 移除组件 |
237
+ | `toObject()` | 序列化为 `AddonItem` |
238
+
239
+ **options**: `{ group, hide_in_command / hideInCommand, max_stack_size / maxStackSize, format_version / formatVersion, icon }`
240
+
241
+ #### `ItemComponent` (`item/itemComponents.ts`)
242
+
243
+ 静态工厂方法,每个返回 `Map<string, unknown>`:
244
+
245
+ | 方法 | 对应 Minecraft 组件 |
246
+ |------|-------------------|
247
+ | `setIcon(texture \| textures)` | `minecraft:icon` |
248
+ | `setMaxStackSize(size)` | `minecraft:max_stack_size` |
249
+ | `setDisplayName(name)` | `minecraft:display_name` |
250
+ | `setFoodComponent(options)` | `minecraft:food` |
251
+ | `setWearable(protection, slot, hidesPlayerLocation?)` | `minecraft:wearable` |
252
+ | `setFuel(duration)` | `minecraft:fuel` |
253
+ | `setGlint(bool)` | `minecraft:glint` |
254
+ | `setHandEquipped(bool)` | `minecraft:hand_equipped` |
255
+ | `setThrowable(...)` | `minecraft:throwable` |
256
+ | `setProjectile(...)` | `minecraft:projectile` |
257
+ | `setUseModifiers(options)` | `minecraft:use_modifiers` |
258
+ | `setUseAnimation(animation)` | `minecraft:use_animation` |
259
+ | `setDurability(maxDurability)` | `minecraft:durability` |
260
+ | `setInteractButton(text \| bool)` | `minecraft:interact_button` |
261
+ | `setBlockPlacer(block, options?)` | `minecraft:block_placer` |
262
+ | `setCustomComponentV2(id, data)` | 自定义组件 |
263
+ | `setCustomComponents(ids)` | 自定义组件数组 |
264
+ | `setAllowOffHand(bool)` | `minecraft:allow_off_hand` |
265
+ | `setBundleInteraction(n)` | `minecraft:bundle_interaction` |
266
+ | `setCanDestroyInCreative(bool)` | `minecraft:can_destroy_in_creative` |
267
+ | `setCompostable(chance)` | `minecraft:compostable` |
268
+ | `setCooldown(options)` | `minecraft:cooldown` |
269
+ | `setDamage(n)` | `minecraft:damage` |
270
+ | `setDamageAbsorption(causes)` | `minecraft:damage_absorption` |
271
+ | `setDigger(options)` | `minecraft:digger` |
272
+ | `setDurabilitySensor(options)` | `minecraft:durability_sensor` |
273
+ | `setDyeable(color)` | `minecraft:dyeable` |
274
+ | `setEnchantable(slot, value)` | `minecraft:enchantable` |
275
+ | `setEntityPlacer(entity, options?)` | `minecraft:entity_placer` |
276
+ | `setFireResistant(bool)` | `minecraft:fire_resistant` |
277
+ | `setHoverTextColor(color)` | `minecraft:hover_text_color` |
278
+ | `setKineticWeapon(options)` | `minecraft:kinetic_weapon` |
279
+ | `setLiquidClipped(bool)` | `minecraft:liquid_clipped` |
280
+ | `setPiercingWeapon(options)` | `minecraft:piercing_weapon` |
281
+ | `setRarity(rarity)` | `minecraft:rarity` |
282
+ | `setRecord(options)` | `minecraft:record` |
283
+ | `setRepairable(repairItems)` | `minecraft:repairable` |
284
+ | `setShooter(options)` | `minecraft:shooter` |
285
+ | `setShouldDespawn(bool)` | `minecraft:should_despawn` |
286
+ | `setStackedByData(bool)` | `minecraft:stacked_by_data` |
287
+ | `setStorageItem(options)` | `minecraft:storage_item` |
288
+ | `setStorageWeightLimit(n)` | `minecraft:storage_weight_limit` |
289
+ | `setStorageWeightModifier(n)` | `minecraft:storage_weight_modifier` |
290
+ | `setSwingDuration(value)` | `minecraft:swing_duration` |
291
+ | `setSwingSounds(options)` | `minecraft:swing_sounds` |
292
+ | `setTags(tags)` | `minecraft:tags` |
293
+ | `combineComponents(...maps)` | 合并多个组件 Map |
294
+
295
+ #### `Food` (`item/food.ts`)
296
+
297
+ extends `Item`。自动添加 `use_modifiers`(默认移动 1、持续 1)、`food`(默认营养 0、饱和 1)和 `use_animation`(默认 "eat")组件,均可通过 options 覆盖。
298
+
299
+ #### `Armor` (`item/armor.ts`)
300
+
301
+ 组合 `Item` + `Attachable`。由 `ArmorType` 枚举 + `ARMOR_TYPES` 规格表驱动,不同类型预设不同插槽和保护值:
302
+
303
+ | ArmorType | 插槽 | 保护 |
304
+ |------|------|------|
305
+ | `ArmorType.Helmet` | `slot.armor.head` | 3 |
306
+ | `ArmorType.Chestplate` | `slot.armor.chest` | 5 |
307
+ | `ArmorType.Leggings` | `slot.armor.legs` | 6 |
308
+ | `ArmorType.Boots` | `slot.armor.feet` | 4 |
309
+
310
+ #### `Attachable` (`item/attachable.ts`)
311
+
312
+ extends `AddonAttachableDescription`。管理可附着物品的材质、纹理、几何和渲染控制器。
313
+
314
+ #### `FlipbookItem` (`item/flipbookItem.ts`)
315
+
316
+ extends `Item`。动画纹理物品,内部创建 `GeometryBlock` 用于 3D 展示,并通过 `FlipbookTextures` 注册翻书纹理动画。
317
+
318
+ #### `ItemCatalog` (`item/itemCatalog.ts`)
319
+
320
+ 生成 `BP/item_catalog/crafting_item_catalog.json`,指定物品在创造菜单与配方手册中的分组位置。链式 API:`addGroup(category, items, options?)` / `addItem(category, item, options?)` / `register()`,分类限 `construction`/`equipment`/`items`/`nature`。注册路径为 `behavior` + `item_catalog/` + `crafting_item_catalog`。
321
+
322
+ ---
323
+
324
+ ### 4.2 Entity 体系
325
+
326
+ ```
327
+ BasicEntity (行为包实体)
328
+ ClientEntity (资源包实体, extends AddonClientEntityDescription)
329
+
330
+ Entity (组合 BasicEntity + ClientEntity)
331
+ ├── DummyEntity (无物理实体)
332
+
333
+ NativeEntity (基于原版实体)
334
+ └── Projectile (抛射物)
335
+ ```
336
+
337
+ #### `BasicEntity` (`entity/basicEntity.js`)
338
+
339
+ 行为包实体核心类:
340
+
341
+ | 方法 | 说明 |
342
+ |------|------|
343
+ | `constructor(identifier, options, data)` | 创建实体,含 `properties`, `components`, `component_groups`, `events` 四个 Map |
344
+ | `addComponent(map)` / `removeComponent(key)` / `clearComponents()` | 组件操作 |
345
+ | `addProperty(id, obj)` / `removeProperty(id)` | 属性操作 |
346
+ | `addComponentGroup(id)` / `removeComponentGroup(id)` | 组件组操作 |
347
+ | `addEvent(id, obj)` / `removeEvent(id)` | 事件操作 |
348
+ | `toObject()` | 序列化为 `AddonEntity` |
349
+
350
+ #### `ClientEntity` (`entity/clientEntity.js`)
351
+
352
+ extends `AddonClientEntityDescription`。资源包实体,管理材质、纹理、几何、动画、渲染控制器等。
353
+
354
+ #### `Entity` (`entity/entity.js`)
355
+
356
+ 组合 `BasicEntity` + `ClientEntity`,提供统一的 `entity.behavior` 和 `entity.resource` 访问。
357
+
358
+ #### `DummyEntity` (`entity/dummyEntity.js`)
359
+
360
+ extends `Entity`。预设无物理碰撞的虚拟实体。
361
+
362
+ #### `NativeEntity` (`entity/nativeEntity.js`)
363
+
364
+ 克隆原版实体行为。使用 `NativeEntityData` 中的原版 JSON 数据设定 `runtime_identifier`。
365
+
366
+ #### `Projectile` (`entity/projectile.js`)
367
+
368
+ extends `NativeEntity`。基于 `minecraft:snowball` 的抛射物实体。
369
+
370
+ #### `EntityComponent` (`entity/componets/entityComponet.js`)
371
+
372
+ 静态工厂方法 (~30 个):
373
+
374
+ | 方法 | 组件 |
375
+ |------|------|
376
+ | `setHealth(value, max)` | `minecraft:health` |
377
+ | `setPhysics()` | `minecraft:physics` |
378
+ | `setCollisionBox(width, height)` | `minecraft:collision_box` |
379
+ | `setScale(value)` | `minecraft:scale` |
380
+ | `setPushable(isPushable, isPushableByPiston)` | `minecraft:pushable` |
381
+ | `setMovement(value)` | `minecraft:movement` |
382
+ | `setTypeFamily(families)` | `minecraft:type_family` |
383
+ | `setNavigationWalk(options)` | `minecraft:navigation.walk` |
384
+ | `setRideable(options)` | `minecraft:rideable` |
385
+ | `setEquipment(equipment)` | `minecraft:equipment` |
386
+ | `setInventoryProperties(options)` | `minecraft:inventory` |
387
+ | `combineComponents(...maps)` | 合并多个组件 Map |
388
+
389
+ #### AI Behavior 类 (`entity/behavior/`)
390
+
391
+ | 类 | 组件 |
392
+ |----|------|
393
+ | `TemptBehavior` | `minecraft:behavior.tempt` |
394
+ | `RandomStrollBehavior` | `minecraft:behavior.random_stroll` |
395
+ | `PickupItemsBehavior` | `minecraft:behavior.pickup_items` |
396
+ | `NearestAttackableTargetBehavor` | `minecraft:behavior.nearest_attackable_target` |
397
+ | `FollowParentBehavior` | `minecraft:behavior.follow_parent` |
398
+ | `FollowMobBehavior` | `minecraft:behavior.follow_mob` |
399
+
400
+ #### Component Bundles (`entity/bundles/`)
401
+
402
+ | 导出 | 说明 |
403
+ |------|------|
404
+ | `BasicBundle` | 组件集合类,可批量应用 |
405
+ | `BasicMovementBundle` | 预置包:`setMovement(0.2)` + `setMovementBasic()` |
406
+
407
+ ---
408
+
409
+ ### 4.3 Block 体系
410
+
411
+ ```
412
+ BasicBlock (基础方块)
413
+ ├── Block (多变体方块)
414
+ │ └── CropBlock (作物方块)
415
+ ├── GeometryBlock (自定义几何方块)
416
+ └── RotatableBlock (可旋转方块)
417
+ └── ROTATION_TYPES: CARDINAL, FACING, BLOCK_FACE, LOG
418
+
419
+ OreBlock (矿物 — 组合 BasicBlock + OreFeature + FeatureRule)
420
+ TileBlock (方块+实体 — 组合 BasicBlock + Entity)
421
+ ```
422
+
423
+ #### `BasicBlock` (`block/basicBlock.js`)
424
+
425
+ | 方法 | 说明 |
426
+ |------|------|
427
+ | `constructor(identifier, category, textures_arr[6], options)` | 6 纹理方块 (down, up, north, south, west, east) |
428
+ | `addComponent(map)` / `removeComponent(key)` | 组件操作 |
429
+ | `addPermutation(condition, componentMap)` | 添加 permutation |
430
+ | `registerTrait(key, value)` / `registerState(key, value)` | 注册 trait / state |
431
+ | `toObject()` | 序列化为 `AddonBlock` |
432
+
433
+ #### `Block` (`block/block.js`)
434
+
435
+ extends `BasicBlock`。多变体方块,根据 `variantDatas` 创建 permutations。注册 `sapdon:block_variant_tag` state。
436
+
437
+ #### `RotatableBlock` (`block/rotatableBlock.js`)
438
+
439
+ extends `BasicBlock`。支持 4 种旋转方式:
440
+
441
+ ```typescript
442
+ RotationTypes.CARDINAL // minecraft:cardinal_direction (4向)
443
+ RotationTypes.FACING // minecraft:facing_direction (6向)
444
+ RotationTypes.BLOCK_FACE // minecraft:block_face (6向)
445
+ RotationTypes.LOG // minecraft:pillar_axis (轴向旋转)
446
+ ```
447
+
448
+ #### `BlockComponent` (`block/blockComponent.js`)
449
+
450
+ 静态工厂方法 (~35 个),涵盖所有 Minecraft 方块组件。
451
+
452
+ #### `OreBlock` (`block/oreBlock.js`)
453
+
454
+ 组合模式:创建一个 `BasicBlock` + `OreFeature` + `FeatureRule`,同时注册三个产物。
455
+
456
+ #### `TileBlock` (`block/tileBlock.js`)
457
+
458
+ 组合模式:创建 `BasicBlock` + `Entity` 对,通过 `sapdon:block_or_entity` state 切换。
459
+
460
+ ---
461
+
462
+ ### 4.4 Biome 体系
463
+
464
+ | 文件 | 类/导出 | 说明 |
465
+ |------|---------|------|
466
+ | `biome/biome.js` | `Biome` | 生物群系业务类,`addComponent()` + `toObject()` |
467
+ | `biome/biomeComponent.js` | `BiomeComponent` | 静态工厂:`setClimate()`, `setOverworldHeight()`, `setSurfaceParameters()`, `setOverworldGenerationRules()` |
468
+
469
+ ---
470
+
471
+ ### 4.5 Feature & Feature-Rule 体系
472
+
473
+ | 文件 | 类/导出 | 说明 |
474
+ |------|---------|------|
475
+ | `feature/oreFeature.js` | `OreFeature` | 矿物特征,指定 count + replace_rules |
476
+ | `feature-rule/featureRule.js` | `FeatureRule` | 特征放置规则,含 condition + distribution |
477
+ | `feature-rule/condition/biomeFilter.js` | `BiomeFilter` | 生物群系过滤条件 |
478
+ | `feature-rule/condition/featureConditions.js` | `FeatureConditions` | 放置条件 (placement_pass) |
479
+ | `feature-rule/distribution/coordinateDistribution.js` | `CoordinateDistribution` | 坐标分布 (uniform, triangle 等) |
480
+ | `feature-rule/distribution/featureDistribution.js` | `FeatureDistribution` | 特征分布 (iterations, axis 分布) |
481
+
482
+ ---
483
+
484
+ ## 5. 工厂/API 层 (`factory/`)
485
+
486
+ 工厂层是用户直接调用的入口。每个工厂方法创建业务逻辑对象并调用 `GRegistry.register()` 注册。
487
+
488
+ ### 5.1 ItemAPI (`factory/itemFactory.js`)
489
+
490
+ | 方法 | 说明 |
491
+ |------|------|
492
+ | `createItem(identifier, category, texture, options)` | 创建普通物品并注册 |
493
+ | `createLargeItem(identifier, category, texture, options)` | 创建大型 3D 物品 (Item+Attachable) |
494
+ | `createFood(identifier, category, texture, options)` | 创建食物物品并注册 |
495
+ | `createAttachable(identifier, texture, material, options)` | 创建可附着物并注册 |
496
+ | `createChestplateArmor(id, itemTex, texPath, options)` | 创建胸甲 (Item+Attachable) |
497
+ | `createHelmetArmor(id, itemTex, texPath, options)` | 创建头盔 |
498
+ | `createBootArmor(id, itemTex, texPath, options)` | 创建靴子 |
499
+ | `createLeggingsArmor(id, itemTex, texPath, options)` | 创建护腿 |
500
+ | `createFlipbookItem(id, category, tex, options)` | 创建翻书动画物品 |
501
+ | `createItemCatalog(formatVersion?)` | 创建物品目录 (item_catalog/crafting_item_catalog.json) |
502
+
503
+ **内部注册流程:**
504
+
505
+ ```javascript
506
+ function registerItem(itemData, attachableData) {
507
+ GRegistry.register(itemData.name, 'behavior', 'items/', itemData)
508
+ if (attachableData) {
509
+ GRegistry.register(attachableData.name, 'resource', 'attachables/', attachableData)
510
+ }
511
+ }
512
+ ```
513
+
514
+ ### 5.2 EntityAPI (`factory/entityFactory.js`)
515
+
516
+ | 方法 | 说明 |
517
+ |------|------|
518
+ | `createEntity(identifier, texture, options, behData, resData)` | 创建实体并注册 behavior + resource |
519
+ | `createNativeEntity(identifier, proto_id, options)` | 基于原版原型创建实体 |
520
+ | `createProjectile(identifier, texture, options)` | 创建抛射物 |
521
+ | `createDummyEntity(identifier, texture, options)` | 创建虚拟实体 |
522
+
523
+ **内部注册:**
524
+
525
+ ```javascript
526
+ function registerEntity(behData, resData) {
527
+ GRegistry.register(name, 'behavior', 'entities/', behData)
528
+ GRegistry.register(name, 'resource', 'entity/', resData)
529
+ }
530
+ ```
531
+
532
+ ### 5.3 BlockAPI (`factory/blockFactory.js`)
533
+
534
+ | 方法 | 说明 |
535
+ |------|------|
536
+ | `createBasicBlock(identifier, category, textures, options)` | 基础 6 面纹理方块 |
537
+ | `createBlock(identifier, category, variantDatas, options)` | 多变体方块 |
538
+ | `createRotatableBlock(identifier, category, textures, options)` | 可旋转方块 |
539
+ | `createGeometryBlock(identifier, category, geometry, materialInstances, options)` | 几何方块 |
540
+ | `createOreBlock(identifier, category, textures, options)` | 矿物方块 (含 feature) |
541
+ | `createCropBlock(identifier, category, variantDatas, options)` | 作物方块 |
542
+
543
+ ### 5.4 RecipeAPI (`factory/recipeFactory.js`)
544
+
545
+ | 方法 | 说明 |
546
+ |------|------|
547
+ | `registerSimpleFurnace(identifier, output, input)` | 快捷熔炉配方 |
548
+ | `registerFurnace(identifier)` | 返回 `AddonRecipeFurnace_1_17` 链式构建器 |
549
+ | `registerSimpleShaped(identifier, output, pattern, key)` | 快捷有序配方 |
550
+ | `registerShaped(identifier)` | 返回 `AddonRecipeShaped_1_20` 链式构建器 |
551
+ | `registerSimpleShapeless(identifier, output, ingredients)` | 快捷无序配方 |
552
+ | `registerShapeless(identifier)` | 返回 `AddonRecipeShapeless_1_17` 链式构建器 |
553
+
554
+ ### 5.5 其他 API
555
+
556
+ | API | 方法 | 注册位置 |
557
+ |-----|------|---------|
558
+ | `BiomeAPI` | `createBiome(identifier)` | `behavior/biomes/` |
559
+ | `FeatureAPI` | `createOreFeature(id, count, rules)` | `behavior/features/` |
560
+ | `FeatureAPI` | `createFeatureRules(id, placesFeature)` | `behavior/feature_rules/` |
561
+ | `UiAPI` | `createUISystem(id, path)` | 自动注册到 `UISystemRegistry` |
562
+ | `UiAPI` | `createUIElement(id, type, template)` | 创建 UI 元素 |
563
+
564
+ ### 5.6 ItemCategory 枚举
565
+
566
+ 定义在 `factory/itemExtra.ts`:
567
+
568
+ ```typescript
569
+ enum ItemCategory {
570
+ Commands = 'commands',
571
+ Construction = 'construction',
572
+ Equipment = 'equipment',
573
+ Nature = 'nature',
574
+ Items = 'items',
575
+ None = 'none'
576
+ }
577
+ ```
578
+
579
+ ---
580
+
581
+ ## 6. 注册系统 (`registry.ts`)
582
+
583
+ ### 6.1 架构
584
+
585
+ ```
586
+ 用户代码 (main.ts) CLI 进程
587
+ ┌──────────────────────┐
588
+ GRegistry.register(name,root,path,data)
589
+ → clientRegistryData.push({...}) │ │
590
+ │ dev server │
591
+ registry.submit() │ /submit │
592
+ → transportPost('submit', data) ──→│ handler │
593
+ (core/transport/client.ts) │ → GRegistryServer │
594
+ │ .dataList │
595
+ │ → generateAddon() │
596
+ └──────────────────────┘
597
+ ```
598
+
599
+ ### 6.2 GRegistry (客户端,位于 core)
600
+
601
+ ```typescript
602
+ class GRegistry {
603
+ static register(name: string, root: string, path: string, data: object)
604
+ // 推入 clientRegistryData 数组
605
+
606
+ static submit()
607
+ // 调用 data.toObject() 后通过 transportPost 发送 HTTP POST
608
+ }
609
+ ```
610
+
611
+ ### 6.3 GRegistryServer (服务端,位于 CLI)
612
+
613
+ `GRegistryServer` 位于 `src/cli/registryServer.ts`,直接引用 CLI 的 `DevelopmentServer` 和 `remoteLogger`:
614
+
615
+ ```typescript
616
+ class GRegistryServer {
617
+ static dataList: any[]
618
+ // 存储 { name, root, path, data } 数组
619
+
620
+ static getDataList(): any[]
621
+ // 返回 dataList 的拷贝
622
+
623
+ static startServer()
624
+ // 注册 submitGregistry 和 remote-logger handler
625
+ }
626
+ ```
627
+
628
+ ### 6.4 registry.submit() (用户入口)
629
+
630
+ ```typescript
631
+ import { transportPost } from './transport/client.js'
632
+
633
+ export namespace registry {
634
+ export function submit() {
635
+ const data = clientRegistryData.map(item => {
636
+ if (typeof item.data.toObject === 'function') {
637
+ item.data = item.data.toObject()
638
+ }
639
+ return item
640
+ })
641
+ transportPost('submit', data)
642
+ }
643
+ }
644
+ ```
645
+
646
+ ---
647
+
648
+ ## 7. UI 系统 (`ui/`)
649
+
650
+ UI 模块用于生成 Minecraft Bedrock JSON UI 文件。
651
+
652
+ ### 7.1 UI 元素类体系
653
+
654
+ ```
655
+ UIElement (基类: name, type, template, control, layout, properties)
656
+ ├── Button (交互按钮)
657
+ ├── Image (图片显示)
658
+ ├── Label (文本标签)
659
+ ├── Panel (容器面板)
660
+ │ └── StackPanel (堆叠面板)
661
+ ├── CollectionPanel (集合面板)
662
+ │ └── Grid (网格布局)
663
+ └── ScrollingPanel (滚动面板)
664
+ ```
665
+
666
+ ### 7.2 UI 属性类
667
+
668
+ | 类 | 说明 |
669
+ |---|------|
670
+ | `Control` | 可见性、层级、透明度、剪裁、动画 |
671
+ | `Layout` | 尺寸、锚点、偏移、拖拽 |
672
+ | `DataBinding` | 数据绑定管理 |
673
+ | `Sprite` | 纹理、UV、九宫格、平铺 |
674
+ | `Text` | 文字、颜色、阴影、字体 |
675
+ | `Input` | 按钮映射、模态、手柄/触摸/手势 |
676
+ | `Factory` | 模板工厂控制 |
677
+ | `Sound` | 按钮音效 |
678
+ | `ScrollView` | 滚动条属性 |
679
+ | `GridProp` | 网格布局属性 |
680
+
681
+ ### 7.3 UI 系统
682
+
683
+ | 系统 | 文件 | 说明 |
684
+ |------|------|------|
685
+ | `UISystem` | `systems/system.js` | 核心 UI 文件系统,管理 elements + animations |
686
+ | `ServerFormSystem` | `systems/serverForm.js` | 预置服务器表单 UI |
687
+ | `ChestUISystem` | `systems/chest.js` | 容器 UI 系统 |
688
+ | `ContainerUISystem` | `systems/containerUISystem.js` | 自定义容器 UI |
689
+ | `Guidebook` | `systems/guidebook.js` | 指南书 UI |
690
+ | `NeoGuidebook` | `systems/neoGuibook/book.ts` | 新版指南书 UI,详见 [neo-guidebook.md](neo-guidebook.md) |
691
+ | `HudUISystem` | `systems/hud/hud.ts` | HUD 系统 |
692
+ | `HudStatePanel` | `systems/hud/hudElement.ts` | HUD 状态面板 |
693
+
694
+ ---
695
+
696
+ ## 8. 纹理系统 (`texture.js`)
697
+
698
+ | 类 | 说明 |
699
+ |---|------|
700
+ | `ItemTextureManager` | 管理 `item_texture.json` 数据,`registerTexture(name, path)` 注册纹理,`toObject()` 输出 JSON |
701
+ | `TerrainTextureManager` | 管理 `terrain_texture.json` 数据,同上 |
702
+ | `FlipbookTextures` | 管理 `flipbook_textures.json` 数据,`registerFlipbookTexture(atlas, texture, ticksPerFrame, options)` 注册动画纹理 |
703
+
704
+ 所有管理器自动调用 `GRegistry.register()` 将数据提交到构建管道。
705
+
706
+ ---
707
+
708
+ ## 9. 附加模块 (`extra/`)
709
+
710
+ | 文件 | 导出 | 说明 |
711
+ |------|------|------|
712
+ | `apperance.ts` | `ClientEntityApperance` | 管理客户端实体的纹理、材质、渲染控制器。提供 `decorate(entityId)` 方法应用到 `ClientEntity`。使用共享的 `AddonRenderControllerGroup` 单例。 |
713
+ | `vehicle.ts` | `BaseVehicle` | 载具基类,管理 seats 数组、collisionBox、riderControlled、autoStep。 |
714
+
715
+ ---
716
+
717
+ ## 10. 类型定义 (`type.ts`)
718
+
719
+ | 导出 | 说明 |
720
+ |------|------|
721
+ | `MaterialDesc<Parts>` | `Record<Parts | '*', \`material.${string}\`>` — 材质描述类型 |
722
+ | `RideableComponent` | 可骑乘组件的完整接口 |
723
+ | `RideableComponentDesc` | `Partial<RideableComponent>` |
724
+ | `RideableSeat` | 座位接口 (position, rotation, lock_rider_rotation 等) |
725
+
726
+ ---
727
+
728
+ ## 11. 包入口 (`index.js`)
729
+
730
+ `src/core/index.js` 聚合导出所有模块:
731
+
732
+ ```javascript
733
+ export * from './addon/index.js' // 所有 DTO
734
+ export * from './biome/index.js' // Biome, BiomeComponent
735
+ export * from './block/index.js' // 所有 Block 类 + BlockComponent
736
+ export * from './entity/index.js' // 所有 Entity 类 + EntityComponent + behaviors
737
+ export * from './factory/index.js' // 所有 API (ItemAPI, EntityAPI...)
738
+ export * from './feature/index.js' // OreFeature
739
+ export * from './feature-rule/index.js' // FeatureRule
740
+ export * from './item/index.js' // Item, Food, Armor, Attachable...
741
+ export * from './ui/index.js' // UI 系统
742
+ export * from './ui/export.js' // UI 聚合导出
743
+ export * from './texture.js' // 纹理管理器
744
+ export { registry } from './registry.js' // 注册系统
745
+ ```
746
+
747
+ 用户使用:
748
+
749
+ ```typescript
750
+ import { ItemAPI, EntityAPI, registry, ItemComponent } from '@sapdon/core'
751
+ ```