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.
- package/README.md +245 -121
- package/doc/dev/architecture.md +415 -0
- package/doc/dev/cli.md +467 -0
- package/doc/dev/core.md +717 -0
- package/doc/dev/oc.md +582 -0
- package/doc/user/api/biome.md +558 -0
- package/doc/user/api/block.md +945 -0
- package/doc/user/api/entity.md +685 -0
- package/doc/user/api/extra.md +231 -0
- package/doc/user/api/item.md +896 -0
- package/doc/user/api/recipe.md +427 -0
- package/doc/user/api/texture.md +181 -0
- package/doc/user/config/build-config.md +84 -0
- package/doc/user/config/mod-info.md +33 -0
- package/doc/user/faq.md +160 -0
- package/doc/user/quick-start.md +108 -0
- package/doc/user/tutorials/block.md +463 -0
- package/doc/user/tutorials/entity.md +356 -0
- package/doc/user/tutorials/item.md +449 -0
- package/doc/user/tutorials/recipe.md +278 -0
- package/package.json +4 -3
- package/prod/cli/index.js +1 -1
- package/prod/cli/start.js +1 -1458
- package/prod/core/index.d.ts +3290 -2150
- package/prod/core/index.js +1 -59015
- package/prod/core/package.json +7 -0
- package/prod/oc/index.d.ts +348 -108
- package/prod/oc/index.js +1 -1
- package/prod/oc/package.json +7 -0
- package/prod/utils/index.d.ts +20 -2
- package/prod/utils/index.js +1 -1
- package/prod/utils/package.json +7 -0
- package/doc/BlockAPI.md +0 -145
- package/doc/api.md +0 -128
- package/doc/oc/index.md +0 -0
- package/doc/sapdon-ts.md +0 -64
- package/src/templates/js_sapdon/build.config +0 -23
- package/src/templates/js_sapdon/main.mjs +0 -4
- package/src/templates/js_sapdon/mod.info +0 -7
- package/src/templates/js_sapdon/pack_icon.png +0 -0
- package/src/templates/js_sapdon/package.json +0 -20
- package/src/templates/js_sapdon/res/animations/animation_item.animation.json +0 -34
- package/src/templates/js_sapdon/res/animations/large_item.animation.json +0 -27
- package/src/templates/js_sapdon/res/models/blocks/crop.geo.json +0 -48
- package/src/templates/js_sapdon/res/models/entity/animation/animation_item.geo.json +0 -26
- package/src/templates/js_sapdon/res/models/entity/animation/large_item.geo.json +0 -28
- package/src/templates/js_sapdon/res/textures/blocks/none.png +0 -0
- package/src/templates/js_sapdon/res/textures/blocks/test_log_oak.png +0 -0
- package/src/templates/js_sapdon/res/textures/blocks/test_log_top.png +0 -0
- package/src/templates/js_sapdon/res/textures/items/masterball.png +0 -0
- package/src/templates/js_sapdon/scripts/custom_components/cropComponent.js +0 -50
- package/src/templates/js_sapdon/scripts/custom_components/items/gui_book.js +0 -37
- package/src/templates/js_sapdon/scripts/custom_components/registry.js +0 -25
- package/src/templates/js_sapdon/scripts/index.js +0 -0
- package/src/templates/ts_sapdon/build.config +0 -23
- package/src/templates/ts_sapdon/main.ts +0 -11
- package/src/templates/ts_sapdon/mod.info +0 -7
- package/src/templates/ts_sapdon/pack_icon.png +0 -0
- package/src/templates/ts_sapdon/package.json +0 -20
- package/src/templates/ts_sapdon/res/models/blocks/crop.geo.json +0 -48
- package/src/templates/ts_sapdon/res/textures/blocks/test_log_oak.png +0 -0
- package/src/templates/ts_sapdon/res/textures/blocks/test_log_top.png +0 -0
- package/src/templates/ts_sapdon/res/textures/items/masterball.png +0 -0
- package/src/templates/ts_sapdon/scripts/components/cropComponent.ts +0 -44
- package/src/templates/ts_sapdon/scripts/components/items/guiBook.ts +0 -36
- package/src/templates/ts_sapdon/scripts/components/registry.ts +0 -24
- package/src/templates/ts_sapdon/scripts/index.ts +0 -7
- package/src/templates/ts_sapdon/tsconfig.json +0 -117
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
# 方块创建教程
|
|
2
|
+
|
|
3
|
+
本文档介绍如何使用 sapdon 框架创建各类 Minecraft 方块。
|
|
4
|
+
|
|
5
|
+
> 开始前请确保已完成[快速入门](../quick-start.md)中的环境搭建。
|
|
6
|
+
|
|
7
|
+
## 导入
|
|
8
|
+
|
|
9
|
+
所有方块相关 API 均从 `@sapdon/core` 导入:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
import { BlockAPI, registry, BlockComponent, RotationTypes, Permutation } from '@sapdon/core'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
完成后调用 `registry.submit()` 提交所有注册数据。
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 1. 基础方块
|
|
20
|
+
|
|
21
|
+
`BlockAPI.createBasicBlock()` 创建具有 6 个面纹理的基础方块。
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { BlockAPI, registry } from '@sapdon/core'
|
|
25
|
+
|
|
26
|
+
const myBlock = BlockAPI.createBasicBlock(
|
|
27
|
+
'sapdon:my_basic_block',
|
|
28
|
+
'nature',
|
|
29
|
+
[
|
|
30
|
+
'stone', // down
|
|
31
|
+
'stone', // up
|
|
32
|
+
'stone', // north
|
|
33
|
+
'stone', // south
|
|
34
|
+
'stone', // west
|
|
35
|
+
'stone' // east
|
|
36
|
+
],
|
|
37
|
+
{
|
|
38
|
+
group: 'construction',
|
|
39
|
+
hide_in_command: false
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
registry.submit()
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 关于 material_instances
|
|
47
|
+
|
|
48
|
+
`createBasicBlock` 内部自动将 6 个纹理映射为 `minecraft:material_instances` 组件:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
// 等效的手动写法
|
|
52
|
+
BlockComponent.setMaterialInstances({
|
|
53
|
+
down: { texture: 'stone_down' },
|
|
54
|
+
up: { texture: 'stone_up' },
|
|
55
|
+
north: { texture: 'stone_north' },
|
|
56
|
+
south: { texture: 'stone_south' },
|
|
57
|
+
west: { texture: 'stone_west' },
|
|
58
|
+
east: { texture: 'stone_east' }
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
每个材质实例可以额外指定渲染属性:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
BlockComponent.setMaterialInstances({
|
|
66
|
+
'*': {
|
|
67
|
+
texture: 'my_texture',
|
|
68
|
+
ambient_occlusion: true,
|
|
69
|
+
face_dimming: true,
|
|
70
|
+
render_method: 'opaque' // opaque | blend | alpha_test | double_sided | alpha_test_single_sided
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 2. 多变体方块
|
|
78
|
+
|
|
79
|
+
`BlockAPI.createBlock()` 创建带有多个变体的方块,每个变体对应一个 `sapdon:block_variant_tag` 状态值。
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { BlockAPI, registry, BlockComponent } from '@sapdon/core'
|
|
83
|
+
|
|
84
|
+
const multiBlock = BlockAPI.createBlock(
|
|
85
|
+
'sapdon:multi_block',
|
|
86
|
+
'nature',
|
|
87
|
+
[
|
|
88
|
+
{
|
|
89
|
+
stateTag: 0,
|
|
90
|
+
textures: ['stone', 'stone', 'stone', 'stone', 'stone', 'stone']
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
stateTag: 1,
|
|
94
|
+
textures: ['cobblestone', 'cobblestone', 'cobblestone', 'cobblestone', 'cobblestone', 'cobblestone']
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
stateTag: 2,
|
|
98
|
+
textures: ['mossy_cobblestone', 'mossy_cobblestone', 'mossy_cobblestone', 'mossy_cobblestone', 'mossy_cobblestone', 'mossy_cobblestone']
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
{
|
|
102
|
+
group: 'nature',
|
|
103
|
+
ambient_occlusion: false,
|
|
104
|
+
face_dimming: false,
|
|
105
|
+
render_method: 'alpha_test'
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
registry.submit()
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 变体工作原理
|
|
113
|
+
|
|
114
|
+
框架自动注册状态 `sapdon:block_variant_tag`(值为 0 到变体数-1),并为每个变体生成 permutation:
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
// 每个变体对应条件
|
|
118
|
+
condition: "q.block_state('sapdon:block_variant_tag') == 0"
|
|
119
|
+
condition: "q.block_state('sapdon:block_variant_tag') == 1"
|
|
120
|
+
// ...
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 为特定变体添加额外组件
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
// 为变体 2 添加自定义组件
|
|
127
|
+
multiBlock.addVariantComponent(2, BlockComponent.setLightEmission(15))
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## 3. 可旋转方块
|
|
133
|
+
|
|
134
|
+
`BlockAPI.createRotatableBlock()` 创建支持多方向放置的方块。
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { BlockAPI, registry, RotationTypes } from '@sapdon/core'
|
|
138
|
+
|
|
139
|
+
// CARDINAL — 北/南/东/西 四个方向
|
|
140
|
+
const pillar = BlockAPI.createRotatableBlock(
|
|
141
|
+
'sapdon:pillar',
|
|
142
|
+
'construction',
|
|
143
|
+
['oak_log_top', 'oak_log_top', 'oak_log', 'oak_log', 'oak_log', 'oak_log'],
|
|
144
|
+
{
|
|
145
|
+
rotationType: RotationTypes.CARDINAL,
|
|
146
|
+
yRotationOffset: 180
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
// FACING — 上/下/北/南/东/西 六个方向
|
|
151
|
+
const machine = BlockAPI.createRotatableBlock(
|
|
152
|
+
'sapdon:machine',
|
|
153
|
+
'construction',
|
|
154
|
+
['stone', 'stone', 'furnace_front', 'stone', 'stone', 'stone'],
|
|
155
|
+
{
|
|
156
|
+
rotationType: RotationTypes.FACING
|
|
157
|
+
}
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
// LOG — 原木式旋转(X/Y/Z 轴)
|
|
161
|
+
const customLog = BlockAPI.createRotatableBlock(
|
|
162
|
+
'sapdon:custom_log',
|
|
163
|
+
'nature',
|
|
164
|
+
['oak_log_top', 'oak_log_top', 'oak_log', 'oak_log', 'oak_log', 'oak_log'],
|
|
165
|
+
{
|
|
166
|
+
rotationType: RotationTypes.LOG
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
registry.submit()
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### RotationTypes 说明
|
|
174
|
+
|
|
175
|
+
| 类型 | 方向 | 适用场景 |
|
|
176
|
+
|------|------|----------|
|
|
177
|
+
| `CARDINAL` | 北、南、东、西 | 柱子、竖纹方块 |
|
|
178
|
+
| `FACING` | 上、下、北、南、东、西 | 熔炉、发射器类 |
|
|
179
|
+
| `BLOCK_FACE` | 上、下、北、南、东、西 | 附着型方块 |
|
|
180
|
+
| `LOG` | X/Y/Z 轴对齐 | 原木、横纹方块 |
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## 4. 几何方块
|
|
185
|
+
|
|
186
|
+
`BlockAPI.createGeometryBlock()` 创建使用自定义几何模型的方块。
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { BlockAPI, registry } from '@sapdon/core'
|
|
190
|
+
|
|
191
|
+
const chair = BlockAPI.createGeometryBlock(
|
|
192
|
+
'sapdon:chair',
|
|
193
|
+
'construction',
|
|
194
|
+
'geometry.chair',
|
|
195
|
+
{
|
|
196
|
+
'*': {
|
|
197
|
+
texture: 'oak_planks',
|
|
198
|
+
render_method: 'opaque'
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
registry.submit()
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
多材质实例示例:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
const table = BlockAPI.createGeometryBlock(
|
|
210
|
+
'sapdon:table',
|
|
211
|
+
'construction',
|
|
212
|
+
'geometry.table',
|
|
213
|
+
{
|
|
214
|
+
'wood': {
|
|
215
|
+
texture: 'oak_planks',
|
|
216
|
+
render_method: 'opaque'
|
|
217
|
+
},
|
|
218
|
+
'metal': {
|
|
219
|
+
texture: 'iron_block',
|
|
220
|
+
render_method: 'opaque'
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
registry.submit()
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## 5. 作物方块
|
|
231
|
+
|
|
232
|
+
`BlockAPI.createCropBlock()` 创建具有生长阶段的作物方块。
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { BlockAPI, registry } from '@sapdon/core'
|
|
236
|
+
|
|
237
|
+
const tomato = BlockAPI.createCropBlock(
|
|
238
|
+
'sapdon:tomato',
|
|
239
|
+
'nature',
|
|
240
|
+
[
|
|
241
|
+
{ stateTag: 0, textures: ['wheat_stage_0', 'wheat_stage_0', 'wheat_stage_0', 'wheat_stage_0', 'wheat_stage_0', 'wheat_stage_0'] },
|
|
242
|
+
{ stateTag: 1, textures: ['wheat_stage_1', 'wheat_stage_1', 'wheat_stage_1', 'wheat_stage_1', 'wheat_stage_1', 'wheat_stage_1'] },
|
|
243
|
+
{ stateTag: 2, textures: ['wheat_stage_2', 'wheat_stage_2', 'wheat_stage_2', 'wheat_stage_2', 'wheat_stage_2', 'wheat_stage_2'] },
|
|
244
|
+
{ stateTag: 3, textures: ['wheat_stage_3', 'wheat_stage_3', 'wheat_stage_3', 'wheat_stage_3', 'wheat_stage_3', 'wheat_stage_3'] }
|
|
245
|
+
],
|
|
246
|
+
{
|
|
247
|
+
group: 'nature',
|
|
248
|
+
render_method: 'alpha_test'
|
|
249
|
+
}
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
registry.submit()
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### 自动添加的组件
|
|
256
|
+
|
|
257
|
+
作物方块会自动设置:
|
|
258
|
+
- **碰撞箱禁用** — `minecraft:collision_box` 设为 `false`
|
|
259
|
+
- **几何模型** — 使用 `geometry.crop`
|
|
260
|
+
- **放置过滤** — 只能放置在耕地上方
|
|
261
|
+
- **选择框** — 每阶段自动调整高度
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## 6. 矿物方块
|
|
266
|
+
|
|
267
|
+
`BlockAPI.createOreBlock()` 自动创建方块 + 矿脉特征 + 特征规则。
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
import { BlockAPI, registry } from '@sapdon/core'
|
|
271
|
+
|
|
272
|
+
const rubyOre = BlockAPI.createOreBlock(
|
|
273
|
+
'sapdon:ruby_ore',
|
|
274
|
+
'nature',
|
|
275
|
+
['diamond_ore', 'diamond_ore', 'diamond_ore', 'diamond_ore', 'diamond_ore', 'diamond_ore'],
|
|
276
|
+
{
|
|
277
|
+
group: 'nature'
|
|
278
|
+
}
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
registry.submit()
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### 自动生成的内容
|
|
285
|
+
|
|
286
|
+
| 内容 | 标识符 |
|
|
287
|
+
|------|--------|
|
|
288
|
+
| 方块 (BasicBlock) | `sapdon:ruby_ore` |
|
|
289
|
+
| 矿脉特征 (OreFeature) | `sapdon:ruby_ore_ore_feature` |
|
|
290
|
+
| 特征规则 (FeatureRule) | `sapdon:ruby_ore_orefeatre_rule` |
|
|
291
|
+
|
|
292
|
+
生成的矿石会在 Y 0-64 层之间以 10 次/区块的频率生成,替换石头。
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## 7. 方块组件
|
|
297
|
+
|
|
298
|
+
使用 `BlockComponent` 的静态方法为方块添加各种行为。
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
import { BlockAPI, registry, BlockComponent } from '@sapdon/core'
|
|
302
|
+
|
|
303
|
+
const componentBlock = BlockAPI.createBasicBlock(
|
|
304
|
+
'sapdon:component_demo',
|
|
305
|
+
'construction',
|
|
306
|
+
['stone', 'stone', 'stone', 'stone', 'stone', 'stone']
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
// 材质实例
|
|
310
|
+
componentBlock.addComponent(
|
|
311
|
+
BlockComponent.setMaterialInstances({
|
|
312
|
+
'*': { texture: 'demo', render_method: 'opaque' }
|
|
313
|
+
})
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
// 几何模型
|
|
317
|
+
componentBlock.addComponent(
|
|
318
|
+
BlockComponent.setGeometry('geometry.demo', { 'bone1': true })
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
// 碰撞箱 — 启用/禁用
|
|
322
|
+
componentBlock.addComponent(BlockComponent.setCollisionBoxEnabled(true))
|
|
323
|
+
// 碰撞箱 — 自定义尺寸
|
|
324
|
+
componentBlock.addComponent(BlockComponent.setCollisionBoxCustom([-8, 0, -8], [16, 16, 16]))
|
|
325
|
+
|
|
326
|
+
// 选择框 — 启用/禁用
|
|
327
|
+
componentBlock.addComponent(BlockComponent.setSelectionBoxEnabled(true))
|
|
328
|
+
// 选择框 — 自定义尺寸
|
|
329
|
+
componentBlock.addComponent(BlockComponent.setSelectionBoxCustom([-8, 0, -8], [16, 16, 16]))
|
|
330
|
+
|
|
331
|
+
// 爆炸抗性 — 启用/禁用
|
|
332
|
+
componentBlock.addComponent(BlockComponent.setDestructibleByExplosionEnabled(true))
|
|
333
|
+
// 爆炸抗性 — 自定义值
|
|
334
|
+
componentBlock.addComponent(BlockComponent.setDestructibleByExplosionCustom(5.0))
|
|
335
|
+
|
|
336
|
+
// 挖掘抗性 — 启用/禁用
|
|
337
|
+
componentBlock.addComponent(BlockComponent.setDestructibleByMiningEnabled(true))
|
|
338
|
+
// 挖掘抗性 — 自定义值(带工具速度)
|
|
339
|
+
componentBlock.addComponent(
|
|
340
|
+
BlockComponent.setDestructibleByMiningCustom(2.0, [
|
|
341
|
+
{ item: 'minecraft:diamond_pickaxe', destroy_speed: 0.5 }
|
|
342
|
+
])
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
// 显示名称
|
|
346
|
+
componentBlock.addComponent(BlockComponent.setDisplayName('组件演示方块'))
|
|
347
|
+
|
|
348
|
+
// 易燃性
|
|
349
|
+
componentBlock.addComponent(BlockComponent.setFlammableEnabled(true))
|
|
350
|
+
componentBlock.addComponent(BlockComponent.setFlammableCustom(0.5, 0.3))
|
|
351
|
+
|
|
352
|
+
// 摩擦力
|
|
353
|
+
componentBlock.addComponent(BlockComponent.setFriction(0.6))
|
|
354
|
+
|
|
355
|
+
// 遮光值
|
|
356
|
+
componentBlock.addComponent(BlockComponent.setLightDampening(15))
|
|
357
|
+
// 发光值
|
|
358
|
+
componentBlock.addComponent(BlockComponent.setLightEmission(0))
|
|
359
|
+
|
|
360
|
+
// 战利品表
|
|
361
|
+
componentBlock.addComponent(BlockComponent.setLoot('loot_tables/demo.json'))
|
|
362
|
+
|
|
363
|
+
// 地图颜色
|
|
364
|
+
componentBlock.addComponent(BlockComponent.setMapColor('#FF0000'))
|
|
365
|
+
// 或 RGB 数组
|
|
366
|
+
componentBlock.addComponent(BlockComponent.setMapColor([255, 0, 0]))
|
|
367
|
+
|
|
368
|
+
// 变换
|
|
369
|
+
componentBlock.addComponent(
|
|
370
|
+
BlockComponent.setTransformation([0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 0, 0], [0, 0, 0])
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
// 放置过滤
|
|
374
|
+
componentBlock.addComponent(
|
|
375
|
+
BlockComponent.setPlacementFilter([
|
|
376
|
+
{ allowed_faces: ['up'], block_filter: ['minecraft:grass'] }
|
|
377
|
+
])
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
// 红石导电性
|
|
381
|
+
componentBlock.addComponent(
|
|
382
|
+
BlockComponent.setRedstoneConductivity(false, true)
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
// 合成台
|
|
386
|
+
componentBlock.addComponent(
|
|
387
|
+
BlockComponent.setCraftingTable(['crafting_table'], '演示工作台')
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
// Tick
|
|
391
|
+
componentBlock.addComponent(BlockComponent.setTick([10, 20], true))
|
|
392
|
+
|
|
393
|
+
// 自定义组件 (Script API)
|
|
394
|
+
componentBlock.addComponent(BlockComponent.setCustomComponents(['sapdon:custom_component']))
|
|
395
|
+
// 自定义组件 V2
|
|
396
|
+
componentBlock.addComponent(
|
|
397
|
+
BlockComponent.setCustomComponentV2('sapdon:custom_v2', { enabled: true })
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
// 破坏粒子
|
|
401
|
+
componentBlock.addComponent(BlockComponent.setDestructionParticles('particle_texture', 'none'))
|
|
402
|
+
|
|
403
|
+
// 物品视觉
|
|
404
|
+
componentBlock.addComponent(
|
|
405
|
+
BlockComponent.setItemVisual('geometry.item', { '*': { texture: 'item_tex', render_method: 'opaque' } })
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
// 液体检测
|
|
409
|
+
componentBlock.addComponent(
|
|
410
|
+
BlockComponent.setLiquidDetection(true, 'water', 'blocking', ['down'])
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
// 呼吸性
|
|
414
|
+
componentBlock.addComponent(BlockComponent.setBreathability('solid'))
|
|
415
|
+
|
|
416
|
+
registry.submit()
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### 合并多个组件
|
|
420
|
+
|
|
421
|
+
```typescript
|
|
422
|
+
componentBlock.addComponent(
|
|
423
|
+
BlockComponent.combineComponents(
|
|
424
|
+
BlockComponent.setDisplayName('合并示例'),
|
|
425
|
+
BlockComponent.setLightEmission(10),
|
|
426
|
+
BlockComponent.setFriction(0.5)
|
|
427
|
+
)
|
|
428
|
+
)
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
---
|
|
432
|
+
|
|
433
|
+
## 8. TileBlock
|
|
434
|
+
|
|
435
|
+
`TileBlock` 将方块与实体结合,实现方块实体效果。
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
import { TileBlock, registry } from '@sapdon/core'
|
|
439
|
+
|
|
440
|
+
const chestBlock = new TileBlock(
|
|
441
|
+
'sapdon:tile_chest',
|
|
442
|
+
'construction',
|
|
443
|
+
['stone', 'stone', 'stone', 'stone', 'stone', 'stone']
|
|
444
|
+
)
|
|
445
|
+
|
|
446
|
+
// 自定义几何模型
|
|
447
|
+
chestBlock.setGeometry('geometry.chest')
|
|
448
|
+
|
|
449
|
+
// 添加动画
|
|
450
|
+
chestBlock.addAnimation('open', 'animation.chest.open')
|
|
451
|
+
|
|
452
|
+
// 自定义脚本属性
|
|
453
|
+
chestBlock.setScript('animate', 'open')
|
|
454
|
+
|
|
455
|
+
registry.submit()
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
### TileBlock 工作原理
|
|
459
|
+
|
|
460
|
+
1. 创建 `BasicBlock`(带有 `sapdon:block_or_entity` 状态)
|
|
461
|
+
2. 创建 `Entity`(带有容器、无敌、不可推动等组件)
|
|
462
|
+
3. 方块状态为 0 时显示普通方块,状态为 1 时通过 tick 切换为实体容器
|
|
463
|
+
4. 实体使用 `block_sensor` 监听方块破坏事件以触发消失
|