sapdon 3.2.1 → 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 +3 -1
- package/prod/cli/index.js +1 -1
- package/prod/cli/start.js +1 -1457
- 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
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# 扩展模块 API 参考
|
|
2
|
+
|
|
3
|
+
本文档涵盖 Sapdon 框架的扩展模块 API,包括客户端实体外观(ClientEntityApperance)和基础载具(BaseVehicle)。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ClientEntityApperance
|
|
8
|
+
|
|
9
|
+
客户端实体外观管理器,用于为客户端实体添加纹理、材质和渲染控制器。通过 `decorate()` 方法将配置应用到指定实体。
|
|
10
|
+
|
|
11
|
+
### 属性
|
|
12
|
+
|
|
13
|
+
| 属性 | 类型 | 说明 |
|
|
14
|
+
|------|------|------|
|
|
15
|
+
| `textures` | `Record<string, string>` | 纹理映射表 |
|
|
16
|
+
| `materials` | `Record<string, string>` | 材质映射表,默认 `{ '*': 'material.default' }` |
|
|
17
|
+
| `renderControllers` | `string[]` | 渲染控制器名称列表 |
|
|
18
|
+
|
|
19
|
+
### 方法
|
|
20
|
+
|
|
21
|
+
#### `addTexture(name, source)`
|
|
22
|
+
|
|
23
|
+
添加一个纹理。
|
|
24
|
+
|
|
25
|
+
| 参数 | 类型 | 说明 |
|
|
26
|
+
|------|------|------|
|
|
27
|
+
| `name` | `string` | 纹理名称 |
|
|
28
|
+
| `source` | `string` | 纹理路径 |
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
import { ClientEntityApperance } from "@sapdon/core";
|
|
32
|
+
|
|
33
|
+
const apperance = new ClientEntityApperance();
|
|
34
|
+
apperance.addTexture("layer0", "textures/entity/ruby_golem");
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
#### `removeTexture(name)`
|
|
38
|
+
|
|
39
|
+
移除一个纹理。
|
|
40
|
+
|
|
41
|
+
| 参数 | 类型 | 说明 |
|
|
42
|
+
|------|------|------|
|
|
43
|
+
| `name` | `string` | 要移除的纹理名称 |
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
apperance.removeTexture("layer0");
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### `addMaterial(name, source)`
|
|
50
|
+
|
|
51
|
+
添加一个材质。
|
|
52
|
+
|
|
53
|
+
| 参数 | 类型 | 说明 |
|
|
54
|
+
|------|------|------|
|
|
55
|
+
| `name` | `string` | 材质名称 |
|
|
56
|
+
| `source` | `string` | 材质资源路径 |
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
apperance.addMaterial("*", "material.default");
|
|
60
|
+
apperance.addMaterial("overlay", "material.entity_overlay");
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### `removeMaterial(name)`
|
|
64
|
+
|
|
65
|
+
移除一个材质。
|
|
66
|
+
|
|
67
|
+
| 参数 | 类型 | 说明 |
|
|
68
|
+
|------|------|------|
|
|
69
|
+
| `name` | `string` | 要移除的材质名称 |
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
apperance.removeMaterial("overlay");
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### `addRenderController(controller)`
|
|
76
|
+
|
|
77
|
+
添加一个渲染控制器。控制器会自动注册到全局渲染控制器组。
|
|
78
|
+
|
|
79
|
+
| 参数 | 类型 | 说明 |
|
|
80
|
+
|------|------|------|
|
|
81
|
+
| `controller` | `AddonRenderController` | 渲染控制器实例 |
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
import { AddonRenderController } from "@sapdon/core";
|
|
85
|
+
|
|
86
|
+
const controller = new AddonRenderController("ruby_golem_controller", "geometry.ruby_golem", "textures/entity/ruby_golem");
|
|
87
|
+
apperance.addRenderController(controller);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### `removeRenderController(controllerId)`
|
|
91
|
+
|
|
92
|
+
移除一个渲染控制器。
|
|
93
|
+
|
|
94
|
+
| 参数 | 类型 | 说明 |
|
|
95
|
+
|------|------|------|
|
|
96
|
+
| `controllerId` | `string` | 渲染控制器的名称/ID |
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
apperance.removeRenderController("ruby_golem_controller");
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### `decorate(entityId)`
|
|
103
|
+
|
|
104
|
+
将当前外观配置应用到指定的客户端实体上。
|
|
105
|
+
|
|
106
|
+
| 参数 | 类型 | 说明 |
|
|
107
|
+
|------|------|------|
|
|
108
|
+
| `entityId` | `string` | 目标实体 ID |
|
|
109
|
+
|
|
110
|
+
如果指定实体不存在,会抛出 `Error`。
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
apperance.decorate("sapdon:ruby_golem");
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 完整示例
|
|
117
|
+
|
|
118
|
+
```javascript
|
|
119
|
+
import { ClientEntityApperance, AddonRenderController } from "@sapdon/core";
|
|
120
|
+
|
|
121
|
+
const apperance = new ClientEntityApperance();
|
|
122
|
+
|
|
123
|
+
apperance.addTexture("layer0", "textures/entity/ruby_golem");
|
|
124
|
+
apperance.addMaterial("*", "material.default");
|
|
125
|
+
|
|
126
|
+
const controller = new AddonRenderController(
|
|
127
|
+
"ruby_golem_controller",
|
|
128
|
+
"geometry.ruby_golem",
|
|
129
|
+
"textures/entity/ruby_golem"
|
|
130
|
+
);
|
|
131
|
+
apperance.addRenderController(controller);
|
|
132
|
+
|
|
133
|
+
apperance.decorate("sapdon:ruby_golem");
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## BaseVehicle
|
|
139
|
+
|
|
140
|
+
基础载具类,用于定义可骑乘实体(载具)的座位、碰撞箱和驾驶行为。
|
|
141
|
+
|
|
142
|
+
### 构造函数
|
|
143
|
+
|
|
144
|
+
#### `new BaseVehicle(id)`
|
|
145
|
+
|
|
146
|
+
| 参数 | 类型 | 说明 |
|
|
147
|
+
|------|------|------|
|
|
148
|
+
| `id` | `string` | 载具实体标识符 |
|
|
149
|
+
|
|
150
|
+
### 属性
|
|
151
|
+
|
|
152
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
153
|
+
|------|------|--------|------|
|
|
154
|
+
| `seats` | `RideableSeat[]` | `[]` | 座位数组 |
|
|
155
|
+
| `collisionBox` | `{ width: number, height: number }` | `{ width: 1, height: 1 }` | 碰撞箱尺寸 |
|
|
156
|
+
| `riderControlled` | `boolean` | `true` | 是否由骑手控制移动 |
|
|
157
|
+
| `autoStep` | `number` | `1.1` | 自动跨步高度 |
|
|
158
|
+
|
|
159
|
+
### 方法
|
|
160
|
+
|
|
161
|
+
#### `addSeat(seat)`
|
|
162
|
+
|
|
163
|
+
添加一个座位。
|
|
164
|
+
|
|
165
|
+
| 参数 | 类型 | 说明 |
|
|
166
|
+
|------|------|------|
|
|
167
|
+
| `seat` | `RideableSeat` | 座位配置对象 |
|
|
168
|
+
|
|
169
|
+
返回 `this` 以支持链式调用。
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
import { BaseVehicle } from "@sapdon/core";
|
|
173
|
+
|
|
174
|
+
const vehicle = new BaseVehicle("sapdon:ruby_jeep");
|
|
175
|
+
|
|
176
|
+
vehicle.addSeat({
|
|
177
|
+
position: [0, 0, 0],
|
|
178
|
+
lock_rider_rotation: 0
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### `removeSeat(index)`
|
|
183
|
+
|
|
184
|
+
移除指定索引的座位。
|
|
185
|
+
|
|
186
|
+
| 参数 | 类型 | 说明 |
|
|
187
|
+
|------|------|------|
|
|
188
|
+
| `index` | `number` | 座位索引 |
|
|
189
|
+
|
|
190
|
+
返回 `this` 以支持链式调用。
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
vehicle.removeSeat(0);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### `getSeat(index)`
|
|
197
|
+
|
|
198
|
+
获取指定索引的座位配置。
|
|
199
|
+
|
|
200
|
+
| 参数 | 类型 | 说明 |
|
|
201
|
+
|------|------|------|
|
|
202
|
+
| `index` | `number` | 座位索引 |
|
|
203
|
+
|
|
204
|
+
返回 `RideableSeat | undefined`。
|
|
205
|
+
|
|
206
|
+
```javascript
|
|
207
|
+
const seat = vehicle.getSeat(0);
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### 完整示例
|
|
211
|
+
|
|
212
|
+
```javascript
|
|
213
|
+
import { BaseVehicle } from "@sapdon/core";
|
|
214
|
+
|
|
215
|
+
const vehicle = new BaseVehicle("sapdon:ruby_jeep");
|
|
216
|
+
|
|
217
|
+
vehicle.collisionBox = { width: 1.5, height: 1.2 };
|
|
218
|
+
vehicle.riderControlled = true;
|
|
219
|
+
vehicle.autoStep = 1.1;
|
|
220
|
+
|
|
221
|
+
vehicle.addSeat({
|
|
222
|
+
position: [0, 0.5, 0],
|
|
223
|
+
lock_rider_rotation: 0
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// 第二个座位(乘客)
|
|
227
|
+
vehicle.addSeat({
|
|
228
|
+
position: [0, 0.5, -0.8],
|
|
229
|
+
lock_rider_rotation: 0
|
|
230
|
+
});
|
|
231
|
+
```
|