sapdon 3.2.2 → 3.3.3

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