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,945 @@
1
+ # 方块系统 API 参考
2
+
3
+ ---
4
+
5
+ ## BlockAPI
6
+
7
+ 工厂函数集合,用于创建各类方块并自动注册到游戏系统。
8
+
9
+ ```typescript
10
+ import { BlockAPI, registry } from '@sapdon/core'
11
+ ```
12
+
13
+ ---
14
+
15
+ ### createBasicBlock
16
+
17
+ 创建基础六面方块。
18
+
19
+ ```typescript
20
+ BlockAPI.createBasicBlock(
21
+ identifier: string,
22
+ category: string,
23
+ textures_arr: string[],
24
+ options?: BasicBlockOptions
25
+ ): BasicBlock
26
+ ```
27
+
28
+ **参数**
29
+
30
+ | 参数 | 类型 | 说明 |
31
+ |------|------|------|
32
+ | `identifier` | `string` | 方块唯一标识符,格式 `命名空间:名称` |
33
+ | `category` | `string` | 创造栏分类:`construction` / `nature` / `equipment` / `items` / `none` |
34
+ | `textures_arr` | `string[]` | 6 纹理数组,顺序 `[down, up, north, south, west, east]` |
35
+ | `options.group` | `string` | 分组,默认 `"construction"` |
36
+ | `options.hide_in_command` | `boolean` | 是否在命令中隐藏,默认 `false` |
37
+
38
+ **示例**
39
+
40
+ ```typescript
41
+ const block = BlockAPI.createBasicBlock('demo:stone', 'nature', [
42
+ 'stone_down', 'stone_up', 'stone_north', 'stone_south', 'stone_west', 'stone_east'
43
+ ])
44
+ ```
45
+
46
+ ---
47
+
48
+ ### createBlock
49
+
50
+ 创建含变体状态的标准方块。
51
+
52
+ ```typescript
53
+ BlockAPI.createBlock(
54
+ identifier: string,
55
+ category: string,
56
+ variantDatas: VariantData[],
57
+ options?: BlockOptions
58
+ ): Block
59
+ ```
60
+
61
+ **参数**
62
+
63
+ | 参数 | 类型 | 说明 |
64
+ |------|------|------|
65
+ | `identifier` | `string` | 方块唯一标识符 |
66
+ | `category` | `string` | 创造栏分类 |
67
+ | `variantDatas` | `VariantData[]` | 变体数据数组 |
68
+ | `options.group` | `string` | 分组,默认 `"construction"` |
69
+ | `options.hide_in_command` | `boolean` | 是否在命令中隐藏,默认 `false` |
70
+ | `options.ambient_occlusion` | `boolean` | 环境光遮蔽,默认 `false` |
71
+ | `options.face_dimming` | `boolean` | 面亮度衰减,默认 `false` |
72
+ | `options.render_method` | `string` | 渲染模式:`opaque` / `blend` / `alpha_test` |
73
+
74
+ **VariantData**
75
+
76
+ ```typescript
77
+ interface VariantData {
78
+ stateTag: number // 状态标签值 (0-15)
79
+ textures: string[] // 6 纹理数组
80
+ }
81
+ ```
82
+
83
+ **示例**
84
+
85
+ ```typescript
86
+ const block = BlockAPI.createBlock('demo:varied', 'nature', [
87
+ { stateTag: 0, textures: ['tex_0', 'tex_0', 'tex_0', 'tex_0', 'tex_0', 'tex_0'] },
88
+ { stateTag: 1, textures: ['tex_1', 'tex_1', 'tex_1', 'tex_1', 'tex_1', 'tex_1'] }
89
+ ])
90
+ ```
91
+
92
+ ---
93
+
94
+ ### createRotatableBlock
95
+
96
+ 创建可旋转方块。
97
+
98
+ ```typescript
99
+ BlockAPI.createRotatableBlock(
100
+ identifier: string,
101
+ category: string,
102
+ textures_arr: string[],
103
+ options?: RotatableBlockOptions
104
+ ): RotatableBlock
105
+ ```
106
+
107
+ **参数**
108
+
109
+ | 参数 | 类型 | 说明 |
110
+ |------|------|------|
111
+ | `identifier` | `string` | 方块唯一标识符 |
112
+ | `category` | `string` | 创造栏分类 |
113
+ | `textures_arr` | `string[]` | 6 纹理数组 |
114
+ | `options.group` | `string` | 分组,默认 `"construction"` |
115
+ | `options.hide_in_command` | `boolean` | 是否在命令中隐藏,默认 `false` |
116
+ | `options.rotationType` | `RotationTypes` | 旋转类型,默认 `RotationTypes.CARDINAL` |
117
+ | `options.yRotationOffset` | `number` | Y轴旋转偏移,默认 `180` |
118
+
119
+ **示例**
120
+
121
+ ```typescript
122
+ const block = BlockAPI.createRotatableBlock('demo:facing', 'construction',
123
+ ['top', 'bottom', 'front', 'back', 'left', 'right'],
124
+ { rotationType: RotationTypes.FACING }
125
+ )
126
+ ```
127
+
128
+ ---
129
+
130
+ ### createGeometryBlock
131
+
132
+ 创建自定义几何模型的方块。
133
+
134
+ ```typescript
135
+ BlockAPI.createGeometryBlock(
136
+ identifier: string,
137
+ category: string,
138
+ geometry: string,
139
+ material_instances: Record<string, MaterialInstance>,
140
+ options?: GeometryBlockOptions
141
+ ): GeometryBlock
142
+ ```
143
+
144
+ **参数**
145
+
146
+ | 参数 | 类型 | 说明 |
147
+ |------|------|------|
148
+ | `identifier` | `string` | 方块唯一标识符 |
149
+ | `category` | `string` | 创造栏分类 |
150
+ | `geometry` | `string` | 几何模型标识符,如 `"geometry.chair"` |
151
+ | `material_instances` | `object` | 材质实例配置 |
152
+ | `options.group` | `string` | 分组,默认 `"construction"` |
153
+ | `options.hide_in_command` | `boolean` | 是否在命令中隐藏,默认 `false` |
154
+
155
+ **MaterialInstance**
156
+
157
+ ```typescript
158
+ interface MaterialInstance {
159
+ texture: string
160
+ render_method?: 'opaque' | 'double_sided' | 'blend' | 'alpha_test' | 'alpha_test_single_sided'
161
+ ambient_occlusion?: boolean | number
162
+ face_dimming?: boolean
163
+ }
164
+ ```
165
+
166
+ **示例**
167
+
168
+ ```typescript
169
+ const block = BlockAPI.createGeometryBlock('demo:chair', 'construction',
170
+ 'geometry.chair',
171
+ { '*': { texture: 'chair_tex', render_method: 'opaque' } }
172
+ )
173
+ ```
174
+
175
+ ---
176
+
177
+ ### createCropBlock
178
+
179
+ 创建作物方块。
180
+
181
+ ```typescript
182
+ BlockAPI.createCropBlock(
183
+ identifier: string,
184
+ category: string,
185
+ variantDatas: VariantData[],
186
+ options?: CropBlockOptions
187
+ ): CropBlock
188
+ ```
189
+
190
+ **参数**
191
+
192
+ | 参数 | 类型 | 说明 |
193
+ |------|------|------|
194
+ | `identifier` | `string` | 方块唯一标识符 |
195
+ | `category` | `string` | 创造栏分类 |
196
+ | `variantDatas` | `VariantData[]` | 生长阶段变体数据 |
197
+ | `options.group` | `string` | 分组,默认 `"construction"` |
198
+ | `options.hide_in_command` | `boolean` | 是否在命令中隐藏,默认 `false` |
199
+ | `options.ambient_occlusion` | `boolean` | 环境光遮蔽,默认 `false` |
200
+ | `options.face_dimming` | `boolean` | 面亮度衰减,默认 `false` |
201
+ | `options.render_method` | `string` | 渲染模式,默认 `"alpha_test"` |
202
+
203
+ **自动添加的组件**
204
+ - `minecraft:collision_box` → `false`
205
+ - `minecraft:geometry` → `geometry.crop`
206
+ - `minecraft:placement_filter` → 仅允许放置在耕地上方
207
+ - 每个生长阶段自动调整选择框高度
208
+
209
+ **示例**
210
+
211
+ ```typescript
212
+ const crop = BlockAPI.createCropBlock('demo:tomato', 'nature', [
213
+ { stateTag: 0, textures: ['stage_0', 'stage_0', 'stage_0', 'stage_0', 'stage_0', 'stage_0'] },
214
+ { stateTag: 1, textures: ['stage_1', 'stage_1', 'stage_1', 'stage_1', 'stage_1', 'stage_1'] },
215
+ { stateTag: 2, textures: ['stage_2', 'stage_2', 'stage_2', 'stage_2', 'stage_2', 'stage_2'] },
216
+ { stateTag: 3, textures: ['stage_3', 'stage_3', 'stage_3', 'stage_3', 'stage_3', 'stage_3'] }
217
+ ])
218
+ ```
219
+
220
+ ---
221
+
222
+ ### createOreBlock
223
+
224
+ 创建矿物方块(自动生成方块 + 矿脉特征 + 特征规则)。
225
+
226
+ ```typescript
227
+ BlockAPI.createOreBlock(
228
+ identifier: string,
229
+ category: string,
230
+ textures_arr: string[],
231
+ options?: OreBlockOptions
232
+ ): OreBlock
233
+ ```
234
+
235
+ **参数**
236
+
237
+ | 参数 | 类型 | 说明 |
238
+ |------|------|------|
239
+ | `identifier` | `string` | 方块唯一标识符 |
240
+ | `category` | `string` | 创造栏分类 |
241
+ | `textures_arr` | `string[]` | 6 纹理数组 |
242
+ | `options.group` | `string` | 分组,默认 `"construction"` |
243
+ | `options.hide_in_command` | `boolean` | 是否在命令中隐藏,默认 `false` |
244
+
245
+ **OreBlock 属性**
246
+
247
+ | 属性 | 类型 | 说明 |
248
+ |------|------|------|
249
+ | `.block` | `BasicBlock` | 矿物方块实例 |
250
+ | `.feature` | `OreFeature` | 矿脉特征实例 |
251
+ | `.feature_rules` | `FeatureRule` | 特征规则实例(Y 0-64,10 次/区块) |
252
+
253
+ **示例**
254
+
255
+ ```typescript
256
+ const ore = BlockAPI.createOreBlock('demo:ruby_ore', 'nature',
257
+ ['ruby_ore', 'ruby_ore', 'ruby_ore', 'ruby_ore', 'ruby_ore', 'ruby_ore']
258
+ )
259
+ // ore.block — 方块
260
+ // ore.feature — 矿脉特征
261
+ // ore.feature_rules — 特征规则
262
+ ```
263
+
264
+ ---
265
+
266
+ ## BasicBlock
267
+
268
+ 所有方块类型的基类。
269
+
270
+ ```typescript
271
+ import { BasicBlock, BlockComponent } from '@sapdon/core'
272
+ ```
273
+
274
+ ### 构造函数
275
+
276
+ ```typescript
277
+ new BasicBlock(
278
+ identifier: string,
279
+ category: string,
280
+ textures_arr: string[],
281
+ options?: {
282
+ group?: string
283
+ hide_in_command?: boolean
284
+ format_version?: string
285
+ }
286
+ )
287
+ ```
288
+
289
+ 构造函数自动调用 `BlockComponent.setMaterialInstances()` 设置 6 面纹理。
290
+
291
+ ### 方法
292
+
293
+ #### `addComponent(componentMap): this`
294
+
295
+ 添加组件。
296
+
297
+ ```typescript
298
+ block.addComponent(BlockComponent.setDisplayName('名称'))
299
+ ```
300
+
301
+ | 参数 | 类型 | 说明 |
302
+ |------|------|------|
303
+ | `componentMap` | `Map<string, any>` | 组件 Map,使用 `BlockComponent` 静态方法生成 |
304
+
305
+ #### `removeComponent(key): this`
306
+
307
+ 移除组件。
308
+
309
+ ```typescript
310
+ block.removeComponent('minecraft:display_name')
311
+ ```
312
+
313
+ | 参数 | 类型 | 说明 |
314
+ |------|------|------|
315
+ | `key` | `string` | 组件名称 |
316
+
317
+ #### `addPermutation(condition, componentMap): this`
318
+
319
+ 添加方块变体。
320
+
321
+ ```typescript
322
+ block.addPermutation(
323
+ "q.block_state('minecraft:cardinal_direction') == 'north'",
324
+ BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 0, 0])
325
+ )
326
+ ```
327
+
328
+ | 参数 | 类型 | 说明 |
329
+ |------|------|------|
330
+ | `condition` | `string` | MoLang 条件表达式 |
331
+ | `componentMap` | `Map<string, any>` | 该变体下的组件集合 |
332
+
333
+ #### `registerTrait(key, value): this`
334
+
335
+ 注册方块 trait。
336
+
337
+ ```typescript
338
+ block.registerTrait('minecraft:placement_direction', {
339
+ enabled_states: ['minecraft:cardinal_direction'],
340
+ y_rotation_offset: 180
341
+ })
342
+ ```
343
+
344
+ | 参数 | 类型 | 说明 |
345
+ |------|------|------|
346
+ | `key` | `string` | Trait 名称 |
347
+ | `value` | `any` | Trait 配置 |
348
+
349
+ #### `registerState(key, value): this`
350
+
351
+ 注册方块状态。
352
+
353
+ ```typescript
354
+ block.registerState('sapdon:block_variant_tag', { values: { min: 0, max: 3 } })
355
+ ```
356
+
357
+ | 参数 | 类型 | 说明 |
358
+ |------|------|------|
359
+ | `key` | `string` | 状态名称 |
360
+ | `value` | `any` | 状态定义(对象或数组) |
361
+
362
+ #### `getId(): string`
363
+
364
+ 返回方块标识符。
365
+
366
+ ```typescript
367
+ const id = block.getId() // "demo:stone"
368
+ ```
369
+
370
+ #### `toObject(): object`
371
+
372
+ 将方块转换为 JSON 格式对象(由 `@Serializer` 装饰器标记,框架自动调用)。
373
+
374
+ ---
375
+
376
+ ## Block
377
+
378
+ 继承自 `BasicBlock`,支持变体状态。
379
+
380
+ ```typescript
381
+ import { Block } from '@sapdon/core'
382
+ ```
383
+
384
+ ### 构造函数
385
+
386
+ ```typescript
387
+ new Block(
388
+ identifier: string,
389
+ category: string,
390
+ variantDatas: VariantData[],
391
+ options?: BlockOptions
392
+ )
393
+ ```
394
+
395
+ 额外注册状态 `sapdon:block_variant_tag`,为每个变体创建 `material_instances` permutation。
396
+
397
+ ### 方法
398
+
399
+ #### `addVariantComponent(variantIndex, componentMap): this`
400
+
401
+ 为指定变体添加组件。
402
+
403
+ ```typescript
404
+ block.addVariantComponent(0, BlockComponent.setLightEmission(10))
405
+ ```
406
+
407
+ | 参数 | 类型 | 说明 |
408
+ |------|------|------|
409
+ | `variantIndex` | `number` | 变体索引(从 0 开始) |
410
+ | `componentMap` | `Map` | 组件 Map |
411
+
412
+ 内部自动生成条件 `q.block_state('sapdon:block_variant_tag') == {index}`。
413
+
414
+ ---
415
+
416
+ ## RotatableBlock
417
+
418
+ 继承自 `BasicBlock`,支持方向旋转。
419
+
420
+ ```typescript
421
+ import { RotatableBlock, RotationTypes } from '@sapdon/core'
422
+ ```
423
+
424
+ ### 构造函数
425
+
426
+ ```typescript
427
+ new RotatableBlock(
428
+ identifier: string,
429
+ category: string,
430
+ textures_arr: string[],
431
+ options?: {
432
+ group?: string
433
+ hide_in_command?: boolean
434
+ rotationType?: RotationTypes
435
+ yRotationOffset?: number
436
+ }
437
+ )
438
+ ```
439
+
440
+ ### RotationTypes
441
+
442
+ ```typescript
443
+ enum RotationTypes {
444
+ CARDINAL = 'cardinal', // 北、南、东、西 (placement_direction)
445
+ FACING = 'facing', // 上、下、北、南、东、西 (placement_direction)
446
+ BLOCK_FACE = 'block_face', // 上、下、北、南、东、西 (placement_position)
447
+ LOG = 'log' // X/Y/Z 轴对齐原木旋转 (placement_position)
448
+ }
449
+ ```
450
+
451
+ | 类型 | 注册的 Trait | 状态值 | 方向数 |
452
+ |------|-------------|--------|--------|
453
+ | `CARDINAL` | `minecraft:placement_direction` | `minecraft:cardinal_direction` | 4 |
454
+ | `FACING` | `minecraft:placement_direction` | `minecraft:facing_direction` | 6 |
455
+ | `BLOCK_FACE` | `minecraft:placement_position` | `minecraft:block_face` | 6 |
456
+ | `LOG` | `minecraft:placement_position` | `minecraft:block_face` | 3 轴 |
457
+
458
+ ---
459
+
460
+ ## CropBlock
461
+
462
+ 继承自 `Block`,用于作物/植物方块。
463
+
464
+ ```typescript
465
+ import { CropBlock } from '@sapdon/core'
466
+ ```
467
+
468
+ ### 构造函数
469
+
470
+ ```typescript
471
+ new CropBlock(
472
+ identifier: string,
473
+ category: string,
474
+ variantDatas: VariantData[],
475
+ options?: CropBlockOptions
476
+ )
477
+ ```
478
+
479
+ 构造函数自动添加:
480
+ - `minecraft:collision_box` → `false`
481
+ - `minecraft:geometry` → `geometry.crop`
482
+ - `minecraft:placement_filter` → 仅限耕地上方
483
+ - 每生长阶段设置自定义选择框高度
484
+
485
+ ---
486
+
487
+ ## GeometryBlock
488
+
489
+ 继承自 `BasicBlock`,使用自定义几何模型。
490
+
491
+ ```typescript
492
+ import { GeometryBlock } from '@sapdon/core'
493
+ ```
494
+
495
+ ### 构造函数
496
+
497
+ ```typescript
498
+ new GeometryBlock(
499
+ identifier: string,
500
+ category: string,
501
+ geometry: string,
502
+ material_instances: Record<string, MaterialInstance>,
503
+ options?: GeometryBlockOptions
504
+ )
505
+ ```
506
+
507
+ 自动添加 `minecraft:geometry` 和 `minecraft:material_instances` 组件。
508
+
509
+ ---
510
+
511
+ ## OreBlock
512
+
513
+ 创建矿物方块及其世界生成规则。
514
+
515
+ ```typescript
516
+ import { OreBlock } from '@sapdon/core'
517
+ ```
518
+
519
+ ### 构造函数
520
+
521
+ ```typescript
522
+ new OreBlock(
523
+ identifier: string,
524
+ category: string,
525
+ textures_arr: string[],
526
+ options?: OreBlockOptions
527
+ )
528
+ ```
529
+
530
+ ### 属性
531
+
532
+ | 属性 | 类型 | 说明 |
533
+ |------|------|------|
534
+ | `block` | `BasicBlock` | 矿方块实例 |
535
+ | `feature` | `OreFeature` | 矿脉特征 |
536
+ | `feature_rules` | `FeatureRule` | 特征规则(默认 Y 0-64,10次/区块,主世界群系) |
537
+
538
+ ---
539
+
540
+ ## TileBlock
541
+
542
+ 方块与实体的组合,实现方块实体功能。
543
+
544
+ ```typescript
545
+ import { TileBlock } from '@sapdon/core'
546
+ ```
547
+
548
+ ### 构造函数
549
+
550
+ ```typescript
551
+ new TileBlock(
552
+ identifier: string,
553
+ category: string,
554
+ textures_arr: string[],
555
+ options?: TileBlockOptions
556
+ )
557
+ ```
558
+
559
+ ### 属性
560
+
561
+ | 属性 | 类型 | 说明 |
562
+ |------|------|------|
563
+ | `block` | `BasicBlock` | 方块实例(带有 `sapdon:block_or_entity` 状态) |
564
+ | `entity` | `Entity` | 实体实例(含容器、无敌、不可推动等组件) |
565
+
566
+ ### 方法
567
+
568
+ #### `setGeometry(geometry): void`
569
+
570
+ 同时设置方块和实体的几何模型。
571
+
572
+ ```typescript
573
+ tileBlock.setGeometry('geometry.chest')
574
+ ```
575
+
576
+ #### `addAnimation(name, animation): void`
577
+
578
+ 为客户端实体添加动画。
579
+
580
+ ```typescript
581
+ tileBlock.addAnimation('open', 'animation.chest.open')
582
+ ```
583
+
584
+ #### `setScript(key, value): void`
585
+
586
+ 为客户端实体设置脚本属性。
587
+
588
+ ```typescript
589
+ tileBlock.setScript('animate', 'open')
590
+ ```
591
+
592
+ ---
593
+
594
+ ## BlockComponent
595
+
596
+ 静态工具方法集合,用于生成组件 Map。每个方法返回 `Map<string, any>`。
597
+
598
+ ```typescript
599
+ import { BlockComponent } from '@sapdon/core'
600
+ ```
601
+
602
+ ### setMaterialInstances
603
+
604
+ ```typescript
605
+ static setMaterialInstances(instances: object): Map
606
+ ```
607
+
608
+ 设置材质实例。
609
+
610
+ ```typescript
611
+ BlockComponent.setMaterialInstances({
612
+ '*': { texture: 'tex', render_method: 'opaque' },
613
+ 'up': { texture: 'tex_top' }
614
+ })
615
+ ```
616
+
617
+ ### setGeometry
618
+
619
+ ```typescript
620
+ static setGeometry(identifier: string, bone_visibility?: object): Map
621
+ ```
622
+
623
+ 设置几何模型。
624
+
625
+ ```typescript
626
+ BlockComponent.setGeometry('geometry.cube', { bone1: true })
627
+ ```
628
+
629
+ ### setCollisionBoxEnabled
630
+
631
+ ```typescript
632
+ static setCollisionBoxEnabled(enabled: boolean): Map
633
+ ```
634
+
635
+ 启用/禁用碰撞箱。
636
+
637
+ ### setCollisionBoxCustom
638
+
639
+ ```typescript
640
+ static setCollisionBoxCustom(origin: number[], size: number[]): Map
641
+ ```
642
+
643
+ 设置自定义碰撞箱。origin 范围:`(-8, 0, -8)` ~ `(8, 16, 8)`。
644
+
645
+ ### setSelectionBoxEnabled
646
+
647
+ ```typescript
648
+ static setSelectionBoxEnabled(enabled: boolean): Map
649
+ ```
650
+
651
+ 启用/禁用选择框。
652
+
653
+ ### setSelectionBoxCustom
654
+
655
+ ```typescript
656
+ static setSelectionBoxCustom(origin: number[], size: number[]): Map
657
+ ```
658
+
659
+ 设置自定义选择框。origin 范围:`(-8, 0, -8)` ~ `(8, 16, 8)`。
660
+
661
+ ### setDestructibleByExplosionEnabled
662
+
663
+ ```typescript
664
+ static setDestructibleByExplosionEnabled(enabled: boolean): Map
665
+ ```
666
+
667
+ 启用/禁用爆炸破坏。
668
+
669
+ ### setDestructibleByExplosionCustom
670
+
671
+ ```typescript
672
+ static setDestructibleByExplosionCustom(explosionResistance: number): Map
673
+ ```
674
+
675
+ 设置自定义爆炸抗性。
676
+
677
+ ### setDestructibleByMiningEnabled
678
+
679
+ ```typescript
680
+ static setDestructibleByMiningEnabled(enabled: boolean): Map
681
+ ```
682
+
683
+ 启用/禁用挖掘破坏。
684
+
685
+ ### setDestructibleByMiningCustom
686
+
687
+ ```typescript
688
+ static setDestructibleByMiningCustom(
689
+ secondsToDestroy: number,
690
+ itemSpecificSpeeds?: Array<{ item: string; destroy_speed: number }>
691
+ ): Map
692
+ ```
693
+
694
+ 设置自定义挖掘时间及工具速度。
695
+
696
+ ### setDisplayName
697
+
698
+ ```typescript
699
+ static setDisplayName(displayName: string): Map
700
+ ```
701
+
702
+ 设置显示名称。
703
+
704
+ ### setFlammableEnabled
705
+
706
+ ```typescript
707
+ static setFlammableEnabled(enabled: boolean): Map
708
+ ```
709
+
710
+ 启用/禁用燃烧。
711
+
712
+ ### setFlammableCustom
713
+
714
+ ```typescript
715
+ static setFlammableCustom(catchChanceModifier: number, destroyChanceModifier: number): Map
716
+ ```
717
+
718
+ 设置自定义燃烧概率(≥ 0)。
719
+
720
+ ### setFriction
721
+
722
+ ```typescript
723
+ static setFriction(value: number): Map
724
+ ```
725
+
726
+ 设置摩擦力(0.0 ~ 0.9)。
727
+
728
+ ### setLightDampening
729
+
730
+ ```typescript
731
+ static setLightDampening(value: number): Map
732
+ ```
733
+
734
+ 设置遮光值(0 ~ 15)。
735
+
736
+ ### setLightEmission
737
+
738
+ ```typescript
739
+ static setLightEmission(value: number): Map
740
+ ```
741
+
742
+ 设置发光值(0 ~ 15)。
743
+
744
+ ### setLoot
745
+
746
+ ```typescript
747
+ static setLoot(path: string): Map
748
+ ```
749
+
750
+ 设置战利品表路径(最大 256 字符)。
751
+
752
+ ### setMapColor
753
+
754
+ ```typescript
755
+ static setMapColor(value: string | number[]): Map
756
+ ```
757
+
758
+ 设置地图颜色。支持十六进制字符串 `"#RRGGBB"` 或 RGB 数组 `[255, 0, 0]`。
759
+
760
+ ### setTransformation
761
+
762
+ ```typescript
763
+ static setTransformation(
764
+ translation?: number[], // 默认 [0, 0, 0]
765
+ scale?: number[], // 默认 [1, 1, 1]
766
+ scale_pivot?: number[], // 默认 [0, 0, 0]
767
+ rotation?: number[], // 默认 [0, 0, 0](角度)
768
+ rotation_pivot?: number[] // 默认 [0, 0, 0]
769
+ ): Map
770
+ ```
771
+
772
+ 设置方块变换(平移、缩放、旋转)。
773
+
774
+ ### setPlacementFilter
775
+
776
+ ```typescript
777
+ static setPlacementFilter(conditions: PlacementCondition[]): Map
778
+ ```
779
+
780
+ 设置放置过滤条件(1 ~ 64 条)。
781
+
782
+ ```typescript
783
+ interface PlacementCondition {
784
+ allowed_faces?: ('up' | 'down' | 'north' | 'south' | 'east' | 'west' | 'side' | 'all')[]
785
+ block_filter?: (string | BlockDescriptor)[]
786
+ }
787
+ interface BlockDescriptor {
788
+ name?: string
789
+ tags?: string
790
+ states?: object
791
+ }
792
+ ```
793
+
794
+ ### setRedstoneConductivity
795
+
796
+ ```typescript
797
+ static setRedstoneConductivity(allowsWireToStepDown: boolean, redstoneConductor: boolean): Map
798
+ ```
799
+
800
+ 设置红石导电性。
801
+
802
+ ### setCraftingTable
803
+
804
+ ```typescript
805
+ static setCraftingTable(craftingTags: string[], tableName?: string): Map
806
+ ```
807
+
808
+ 设置合成台属性(最多 64 个标签)。
809
+
810
+ ### setTick
811
+
812
+ ```typescript
813
+ static setTick(interval_range: number[], looping: boolean): Map
814
+ ```
815
+
816
+ 设置 Tick 间隔。
817
+
818
+ ### setCustomComponents
819
+
820
+ ```typescript
821
+ static setCustomComponents(custom_components: string[]): Map
822
+ ```
823
+
824
+ 设置自定义组件(需要 Script API)。
825
+
826
+ ### setCustomComponentV2
827
+
828
+ ```typescript
829
+ static setCustomComponentV2(component_id: string, params: object): Map
830
+ ```
831
+
832
+ 设置自定义组件 V2(需要 Script API V2.0.0+)。
833
+
834
+ ### setDestructionParticles
835
+
836
+ ```typescript
837
+ static setDestructionParticles(texture: string, tint_method?: string): Map
838
+ ```
839
+
840
+ 设置破坏粒子纹理。
841
+
842
+ ### setItemVisual
843
+
844
+ ```typescript
845
+ static setItemVisual(geometry: string, materialInstances: object): Map
846
+ ```
847
+
848
+ 设置物品栏中的视觉属性。
849
+
850
+ ### setLiquidDetection
851
+
852
+ ```typescript
853
+ static setLiquidDetection(
854
+ canContainLiquid: boolean,
855
+ liquidType?: 'water',
856
+ onLiquidTouches?: 'blocking' | 'broken' | 'popped' | 'no_reaction',
857
+ stopsLiquidFlowingFromDirection?: ('up' | 'down' | 'north' | 'south' | 'east' | 'west')[]
858
+ ): Map
859
+ ```
860
+
861
+ 设置液体检测属性。
862
+
863
+ ### setBreathability
864
+
865
+ ```typescript
866
+ static setBreathability(value: 'solid' | 'air'): Map
867
+ ```
868
+
869
+ 设置呼吸性。
870
+
871
+ ### combineComponents
872
+
873
+ ```typescript
874
+ static combineComponents(...componentMaps: Map[]): Map
875
+ ```
876
+
877
+ 合并多个组件 Map。
878
+
879
+ ```typescript
880
+ BlockComponent.combineComponents(
881
+ BlockComponent.setDisplayName('测试'),
882
+ BlockComponent.setLightEmission(5)
883
+ )
884
+ ```
885
+
886
+ ### toJSON
887
+
888
+ ```typescript
889
+ static toJSON(components: Map): object
890
+ ```
891
+
892
+ 将组件 Map 转换为普通 JSON 对象。
893
+
894
+ ---
895
+
896
+ ## Permutation
897
+
898
+ 方块变体,由条件和组件集合组成。
899
+
900
+ ```typescript
901
+ interface Permutation {
902
+ condition: string
903
+ components: Record<string, any>
904
+ }
905
+ ```
906
+
907
+ 通过 `basicBlock.addPermutation(condition, componentMap)` 创建。
908
+
909
+ **condition** — MoLang 表达式,如:
910
+
911
+ ```
912
+ "q.block_state('minecraft:cardinal_direction') == 'north'"
913
+ "q.block_state('sapdon:block_variant_tag') == 0"
914
+ ```
915
+
916
+ **componentMap** — `Map<string, any>`,由 `BlockComponent` 方法生成。
917
+
918
+ ---
919
+
920
+ ## 类型汇总
921
+
922
+ ```typescript
923
+ // 方块工厂
924
+ BlockAPI.createBasicBlock(identifier, category, textures_arr, options?)
925
+ BlockAPI.createBlock(identifier, category, variantDatas, options?)
926
+ BlockAPI.createRotatableBlock(identifier, category, textures_arr, options?)
927
+ BlockAPI.createGeometryBlock(identifier, category, geometry, material_instances, options?)
928
+ BlockAPI.createCropBlock(identifier, category, variantDatas, options?)
929
+ BlockAPI.createOreBlock(identifier, category, textures_arr, options?)
930
+
931
+ // 类
932
+ class BasicBlock { ... }
933
+ class Block extends BasicBlock { ... }
934
+ class RotatableBlock extends BasicBlock { ... }
935
+ class GeometryBlock extends BasicBlock { ... }
936
+ class CropBlock extends Block { ... }
937
+ class OreBlock { block, feature, feature_rules }
938
+ class TileBlock { block, entity }
939
+
940
+ // 枚举
941
+ RotationTypes = { CARDINAL, FACING, BLOCK_FACE, LOG }
942
+
943
+ // 工具类
944
+ BlockComponent = { setMaterialInstances, setGeometry, ... }
945
+ ```