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.
- package/README.md +255 -121
- package/doc/dev/architecture.md +418 -0
- package/doc/dev/cli.md +467 -0
- package/doc/dev/core.md +751 -0
- package/doc/dev/lr-paradigm.md +85 -0
- package/doc/dev/oc.md +582 -0
- package/doc/dev/workflow.md +257 -0
- package/doc/hello_sapdon/hello_sapdon.md +3 -3
- package/doc/user/api/biome.md +558 -0
- package/doc/user/api/block.md +1530 -0
- package/doc/user/api/entity.md +685 -0
- package/doc/user/api/extra.md +231 -0
- package/doc/user/api/item.md +1125 -0
- package/doc/user/api/neo-guidebook.md +409 -0
- package/doc/user/api/recipe.md +427 -0
- package/doc/user/api/sapdon-ui.md +185 -0
- package/doc/user/api/texture.md +181 -0
- package/doc/user/config/build-config.md +83 -0
- package/doc/user/config/mod-info.md +33 -0
- package/doc/user/faq.md +160 -0
- package/doc/user/quick-start.md +122 -0
- package/doc/user/tutorials/block.md +474 -0
- package/doc/user/tutorials/entity.md +356 -0
- package/doc/user/tutorials/item.md +449 -0
- package/doc/user/tutorials/neo-guidebook-experience.md +381 -0
- package/doc/user/tutorials/neo-guidebook.md +640 -0
- package/doc/user/tutorials/recipe.md +278 -0
- package/doc/user/tutorials/sapdon-ui.md +207 -0
- package/package.json +8 -3
- package/prod/cli/index.js +1 -1
- package/prod/cli/start.js +1 -1458
- package/prod/core/index.d.ts +4564 -2166
- package/prod/core/index.js +1 -59015
- package/prod/core/package.json +7 -0
- package/prod/oc/index.d.ts +350 -108
- package/prod/oc/index.js +1 -1
- package/prod/oc/package.json +7 -0
- package/prod/utils/index.d.ts +20 -9
- 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,356 @@
|
|
|
1
|
+
# 实体创建教程
|
|
2
|
+
|
|
3
|
+
## 1. 创建基础实体
|
|
4
|
+
|
|
5
|
+
使用 `EntityAPI.createEntity()` 创建自定义实体。返回对象包含 `.behavior`(行为包)和 `.resource`(资源包)。
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
import { EntityAPI, registry } from '@sapdon/core'
|
|
9
|
+
|
|
10
|
+
const { behavior, resource } = EntityAPI.createEntity(
|
|
11
|
+
'my_addon:custom_entity', // 标识符
|
|
12
|
+
'textures/entity/custom' // 纹理路径
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
registry.submit()
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
通过 `behavior` 访问行为包,`resource` 访问资源包:
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
behavior.addComponent(...) // 添加行为包组件
|
|
22
|
+
resource.addTexture(...) // 添加资源包纹理
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 2. 行为包组件
|
|
26
|
+
|
|
27
|
+
使用 `EntityComponent` 的静态方法创建组件,通过 `behavior.addComponent()` 添加到实体。
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import { EntityAPI, registry, EntityComponent } from '@sapdon/core'
|
|
31
|
+
import { BasicMovementBundle } from '@sapdon/core'
|
|
32
|
+
|
|
33
|
+
const { behavior, resource } = EntityAPI.createEntity(
|
|
34
|
+
'my_addon:zombie_custom',
|
|
35
|
+
'textures/entity/zombie_custom'
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
behavior.addComponent(
|
|
39
|
+
EntityComponent.combineComponents(
|
|
40
|
+
// 生命值
|
|
41
|
+
EntityComponent.setHealth({ max: 40, value: 40 }),
|
|
42
|
+
|
|
43
|
+
// 移动速度
|
|
44
|
+
EntityComponent.setMovement(0.25),
|
|
45
|
+
|
|
46
|
+
// 碰撞箱(宽0.6,高1.9)
|
|
47
|
+
EntityComponent.setCollisionBox(0.6, 1.9),
|
|
48
|
+
|
|
49
|
+
// 物理属性(有碰撞,有重力)
|
|
50
|
+
EntityComponent.setPhysics(true, true),
|
|
51
|
+
|
|
52
|
+
// 可被推动(非活塞)
|
|
53
|
+
EntityComponent.setPushable(true, false),
|
|
54
|
+
|
|
55
|
+
// 实体家族
|
|
56
|
+
EntityComponent.setTypeFamily(['zombie', 'monster', 'undead']),
|
|
57
|
+
|
|
58
|
+
// 缩放大小
|
|
59
|
+
EntityComponent.setScale(1.0),
|
|
60
|
+
|
|
61
|
+
// 寻路(步行)
|
|
62
|
+
EntityComponent.setNavigationWalk({
|
|
63
|
+
canWalk: true,
|
|
64
|
+
canSwim: true,
|
|
65
|
+
canJump: true,
|
|
66
|
+
avoidWater: false,
|
|
67
|
+
canBreakDoors: true
|
|
68
|
+
}),
|
|
69
|
+
|
|
70
|
+
// 静态跳跃
|
|
71
|
+
EntityComponent.setJumpStatic(0.5),
|
|
72
|
+
|
|
73
|
+
// 可爬墙
|
|
74
|
+
new Map([['minecraft:can_climb', {}]]),
|
|
75
|
+
|
|
76
|
+
// 攻击伤害
|
|
77
|
+
new Map([['minecraft:attack', {
|
|
78
|
+
damage: 5
|
|
79
|
+
}]]),
|
|
80
|
+
|
|
81
|
+
// 伤害传感器
|
|
82
|
+
EntityComponent.setDamageSensor(true),
|
|
83
|
+
|
|
84
|
+
// 可拴绳
|
|
85
|
+
new Map([['minecraft:leashable', {
|
|
86
|
+
soft_distance: 4.0,
|
|
87
|
+
hard_distance: 6.0
|
|
88
|
+
}]]),
|
|
89
|
+
|
|
90
|
+
// 持久化
|
|
91
|
+
new Map([['minecraft:persistent', {}]]),
|
|
92
|
+
|
|
93
|
+
// 追踪范围
|
|
94
|
+
new Map([['minecraft:follow_range', {
|
|
95
|
+
value: 32,
|
|
96
|
+
max: 48
|
|
97
|
+
}]]),
|
|
98
|
+
|
|
99
|
+
// 可命名
|
|
100
|
+
EntityComponent.setCustomNameable(true, false, {
|
|
101
|
+
event: 'my_addon:on_named',
|
|
102
|
+
target: 'self'
|
|
103
|
+
}, [
|
|
104
|
+
{ name: 'Boss', on_named: { event: 'my_addon:boss_mode' } }
|
|
105
|
+
]),
|
|
106
|
+
|
|
107
|
+
// 背包
|
|
108
|
+
EntityComponent.setInventoryProperties({
|
|
109
|
+
inventorySize: 18,
|
|
110
|
+
containerType: 'minecart_chest',
|
|
111
|
+
isPrivate: false
|
|
112
|
+
})
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
// 也可使用 BasicMovementBundle 快速添加移动组件
|
|
117
|
+
behavior.addComponent(BasicMovementBundle.serialize())
|
|
118
|
+
|
|
119
|
+
registry.submit()
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## 3. 行为包属性
|
|
123
|
+
|
|
124
|
+
使用 `behavior.addProperty()` 定义实体属性(用于实体定义中的 `properties` 字段)。
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
behavior.addProperty('my_addon:level', {
|
|
128
|
+
type: 'int',
|
|
129
|
+
range: [1, 100],
|
|
130
|
+
default: 1
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
behavior.addProperty('my_addon:variant', {
|
|
134
|
+
type: 'int',
|
|
135
|
+
range: [0, 3],
|
|
136
|
+
default: 0
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## 4. 行为包事件与组件组
|
|
141
|
+
|
|
142
|
+
`addEvent()` 定义事件,`addComponentGroup()` 定义组件组。事件通过 `Map` 结构关联触发条件。
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
// 创建组件组
|
|
146
|
+
behavior.addComponentGroup('my_addon:angry', new Map([
|
|
147
|
+
...EntityComponent.combineComponents(
|
|
148
|
+
EntityComponent.setMovement(0.4),
|
|
149
|
+
new Map([['minecraft:attack', { damage: 10 }]])
|
|
150
|
+
)
|
|
151
|
+
]))
|
|
152
|
+
|
|
153
|
+
behavior.addComponentGroup('my_addon:calm', new Map([
|
|
154
|
+
...EntityComponent.combineComponents(
|
|
155
|
+
EntityComponent.setMovement(0.2),
|
|
156
|
+
new Map([['minecraft:attack', { damage: 5 }]])
|
|
157
|
+
)
|
|
158
|
+
]))
|
|
159
|
+
|
|
160
|
+
// 添加事件
|
|
161
|
+
behavior.addEvent('my_addon:become_angry', new Map([
|
|
162
|
+
['add', { component_groups: ['my_addon:angry'] }]
|
|
163
|
+
]))
|
|
164
|
+
|
|
165
|
+
behavior.addEvent('my_addon:become_calm', new Map([
|
|
166
|
+
['remove', { component_groups: ['my_addon:angry'] }],
|
|
167
|
+
['add', { component_groups: ['my_addon:calm'] }]
|
|
168
|
+
]))
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 5. 资源包配置
|
|
172
|
+
|
|
173
|
+
通过 `resource` (ClientEntity) 配置模型、纹理、材质、动画、生成蛋等。
|
|
174
|
+
|
|
175
|
+
```js
|
|
176
|
+
// 纹理
|
|
177
|
+
resource.addTexture('default', 'textures/entity/zombie_custom')
|
|
178
|
+
resource.addTexture('overlay', 'textures/entity/zombie_custom_overlay')
|
|
179
|
+
|
|
180
|
+
// 材质
|
|
181
|
+
resource.addMaterial('default', 'entity_alphatest')
|
|
182
|
+
|
|
183
|
+
// 几何体模型
|
|
184
|
+
resource.addGeometry('default', 'geometry.zombie.custom')
|
|
185
|
+
|
|
186
|
+
// 动画
|
|
187
|
+
resource.addAnimation('walk', 'animation.zombie.custom.walk')
|
|
188
|
+
resource.addAnimation('attack', 'animation.zombie.custom.attack')
|
|
189
|
+
|
|
190
|
+
// 动画控制器
|
|
191
|
+
resource.addAnimationController('controller', 'controller.animation.zombie.custom')
|
|
192
|
+
|
|
193
|
+
// 渲染控制器
|
|
194
|
+
resource.addRenderController('controller.render.zombie_custom')
|
|
195
|
+
|
|
196
|
+
// 设置脚本(如 pre_animation)
|
|
197
|
+
resource.setScript('pre_animation', [
|
|
198
|
+
'variable.tcos = Math.cos(query.life_time * 45.8)'
|
|
199
|
+
])
|
|
200
|
+
|
|
201
|
+
// 生成蛋
|
|
202
|
+
resource.setSpawnEgg('textures/entity/zombie_spawn_egg', 0)
|
|
203
|
+
|
|
204
|
+
// 粒子效果
|
|
205
|
+
resource.addParticleEffect('flame', 'my_addon:flame_particle')
|
|
206
|
+
|
|
207
|
+
// 定位器
|
|
208
|
+
resource.addLocator('lead', [0.0, 1.0, 0.0])
|
|
209
|
+
|
|
210
|
+
registry.submit()
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## 6. AI 行为
|
|
214
|
+
|
|
215
|
+
AI 行为类均接受 `priority` 作为第一参数,拥有链式 setter 方法。
|
|
216
|
+
|
|
217
|
+
```js
|
|
218
|
+
import {
|
|
219
|
+
NearestAttackableTargetBehavor,
|
|
220
|
+
TemptBehavior,
|
|
221
|
+
RandomStrollBehavior,
|
|
222
|
+
PickupItemsBehavior,
|
|
223
|
+
FollowParentBehavior,
|
|
224
|
+
FollowMobBehavior
|
|
225
|
+
} from '@sapdon/core'
|
|
226
|
+
|
|
227
|
+
const { behavior } = EntityAPI.createEntity('my_addon:animal', 'textures/entity/animal')
|
|
228
|
+
|
|
229
|
+
behavior.addComponent(
|
|
230
|
+
EntityComponent.combineComponents(
|
|
231
|
+
// 攻击目标
|
|
232
|
+
new NearestAttackableTargetBehavor(2, {
|
|
233
|
+
filters: { test: 'is_family', subject: 'other', value: 'player' }
|
|
234
|
+
})
|
|
235
|
+
.setMustReach(true)
|
|
236
|
+
.setMustSee(false)
|
|
237
|
+
.toObject(),
|
|
238
|
+
|
|
239
|
+
// 诱惑行为
|
|
240
|
+
new TemptBehavior(3)
|
|
241
|
+
.setItems(['minecraft:wheat'])
|
|
242
|
+
.setSpeedMultiplier(1.2)
|
|
243
|
+
.canGetScared(true)
|
|
244
|
+
.setWithinRadius(10)
|
|
245
|
+
.toObject(),
|
|
246
|
+
|
|
247
|
+
// 随机漫步
|
|
248
|
+
new RandomStrollBehavior(4, 120, 1.0)
|
|
249
|
+
.setXZDist(10)
|
|
250
|
+
.setYDist(7)
|
|
251
|
+
.toObject(),
|
|
252
|
+
|
|
253
|
+
// 拾取物品(类似 Allay)
|
|
254
|
+
new PickupItemsBehavior(5)
|
|
255
|
+
.setMaxDist(32)
|
|
256
|
+
.setSearchHeight(16)
|
|
257
|
+
.setSpeedMultiplier(4.0)
|
|
258
|
+
.setCanPickupAnyItem(true)
|
|
259
|
+
.toObject(),
|
|
260
|
+
|
|
261
|
+
// 跟随父母
|
|
262
|
+
new FollowParentBehavior(6)
|
|
263
|
+
.setSpeedMultiplier(1.1)
|
|
264
|
+
.toObject(),
|
|
265
|
+
|
|
266
|
+
// 跟随其他生物
|
|
267
|
+
new FollowMobBehavior(1)
|
|
268
|
+
.setSearchRange(10)
|
|
269
|
+
.setSpeedMultiplier(1.5)
|
|
270
|
+
.setStopDistance(2.0)
|
|
271
|
+
.toObject()
|
|
272
|
+
)
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
registry.submit()
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## 7. DummyEntity — 无物理虚拟实体
|
|
279
|
+
|
|
280
|
+
`DummyEntity` 预先配置了禁用的物理、碰撞箱、推动和伤害,适合用作标记点或 GUI 实体。
|
|
281
|
+
|
|
282
|
+
```js
|
|
283
|
+
import { EntityAPI, registry } from '@sapdon/core'
|
|
284
|
+
|
|
285
|
+
const { behavior, resource } = EntityAPI.createDummyEntity(
|
|
286
|
+
'my_addon:dummy',
|
|
287
|
+
'textures/entity/none'
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
// DummyEntity 会自动设置:
|
|
291
|
+
// - 无物理 (Physics: false)
|
|
292
|
+
// - 不可推动
|
|
293
|
+
// - 极小的碰撞箱 (0.001)
|
|
294
|
+
// - 无伤害传感器
|
|
295
|
+
// - 自定义碰撞命中测试为空
|
|
296
|
+
|
|
297
|
+
registry.submit()
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## 8. Projectile — 抛射物
|
|
301
|
+
|
|
302
|
+
`Projectile` 继承自 `NativeEntity`,基于 `minecraft:snowball`。自动继承雪球的全部行为属性,只需指定纹理。
|
|
303
|
+
|
|
304
|
+
```js
|
|
305
|
+
import { EntityAPI, registry } from '@sapdon/core'
|
|
306
|
+
|
|
307
|
+
const { behavior, resource } = EntityAPI.createProjectile(
|
|
308
|
+
'my_addon:custom_projectile',
|
|
309
|
+
'textures/items/custom_projectile'
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
// 可额外添加行为包组件
|
|
313
|
+
behavior.addComponent(
|
|
314
|
+
new Map([['minecraft:projectile', {
|
|
315
|
+
gravity: 0.05,
|
|
316
|
+
power: 1.5,
|
|
317
|
+
inertia: 0.99,
|
|
318
|
+
knockback: true,
|
|
319
|
+
on_hit: {
|
|
320
|
+
impact_damage: {
|
|
321
|
+
damage: 8,
|
|
322
|
+
knockback: true
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}]])
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
registry.submit()
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## 9. NativeEntity — 基于原版实体
|
|
332
|
+
|
|
333
|
+
`NativeEntity` 基于一个已有原版实体(如 `minecraft:zombie`)创建变种,自动继承其行为包和资源包数据。
|
|
334
|
+
|
|
335
|
+
```js
|
|
336
|
+
import { EntityAPI, registry } from '@sapdon/core'
|
|
337
|
+
|
|
338
|
+
const { behavior, resource } = EntityAPI.createNativeEntity(
|
|
339
|
+
'my_addon:native_zombie', // 新标识符
|
|
340
|
+
'minecraft:zombie' // 原版实体 ID
|
|
341
|
+
)
|
|
342
|
+
|
|
343
|
+
// 覆盖原版属性
|
|
344
|
+
behavior.addComponent(
|
|
345
|
+
EntityComponent.setHealth({ max: 100, value: 100 })
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
behavior.addComponent(
|
|
349
|
+
EntityComponent.setMovement(0.3)
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
// 修改纹理
|
|
353
|
+
resource.addTexture('default', 'textures/entity/native_zombie')
|
|
354
|
+
|
|
355
|
+
registry.submit()
|
|
356
|
+
```
|