Files
2025-08-25 18:36:29 +08:00

61 lines
5.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
front: https://nie.res.netease.com/r/pic/20211104/69055361-2e7a-452f-8b1a-f23e1262a03a.jpg
hard: 高级
time: 15分钟
---
# 了解方块实体外观
在行为包定义了方块实体的组件之后,我们还可以在客户端定义方块实体所使用的客户端实体。
## 定义实体及其外观
我们像第八章中讲的实体那样制作一个客户端实体定义文件,包括实体的各种资源,然后将其准备在资源包中。为了让实体挂接在方块实体上,我们需要修改资源包根目录下的`blocks.json`文件。
```json
{
"format_version": [ 1, 1, 0 ],
///...
"customblocks:custom_block_entity": {
"sound": "grass",
// 可与netease_model字段一起使用定义方块的方块模型
"netease_model": "customblocks:customblocks_model_decoration",
// --- 实体模型配置 ---
// 这个方块实体将会使用到实体模型
"client_entity": {
// 对应custom_block_entity.entity.json里面的identifier
"identifier": "customblocks:custom_block_entity",
// 这个方块实体的手持模型或掉落时模型是否使用该实体模型。
"hand_model_use_client_entity": true,
// 这个方块实体的物品icon贴图
"block_icon": "test_block_icon",
// 方块实体被破坏时使用的贴图
"destoryed_textures":"destroy_entity"
},
},
///...
}
```
这是一个示例的方块实体的实体挂接定义。我们可以看到,`client_entity`字段将负责将实体挂接到方块上。
- `identifier`:字符串,实体的标识符,需要与实体的客户端定义中标识符相一致。
- `hand_model_use_client_entity`:可选,布尔值,玩家的手持模型和该方块的掉落物模型是否适用实体的模型,若为`false`,则仅仅在方块被放置在世界中时使用实体的模型,其余情况(手持和掉落物)使用`netease_model`定义的模型或原版的方块形状。
- `block_icon`:可选,字符串,方块在物品栏中作为物品时的图标纹理的短名称。事实上,由于游戏机制,物品的图标并不能渲染一个实体,因而对于方块来说只能渲染一个平面图标、按照微软方块形状渲染或按照自定义的方块模型渲染。如果这里没有定义,则会自动渲染`netease_model`定义的方块模型或原版方块形状作为图标。短名称在资源包的纹理图集定义文件`textures/terrain_texture.json`中定义。
- `destoryed_textures`:可选,字符串,方块破坏粒子的纹理短名称。方块被破坏时会产生旧版粒子(介绍见第二章)中的`terrain`粒子,而`terrain`粒子会从方块的地形图集定义见第十章中指定UV处选取纹理作为其贴图。这里可以通过更改地形图集中的短名称来变相地指定产生的`terrain`粒子的纹理UV。若未定义则自动依次检测`block_icon`字段中定义的纹理、`netease_model`字段中定义的模型中定义的纹理、`textures`字段中定义的纹理的存在性并使用最先检测到的那个。该字段的短名称也在资源包的纹理图集定义文件`textures/terrain_texture.json`中定义。
至此,我们便定义好了方块实体对应的实体,而方块实体的包括模型在内的各种资源将交由该实体来进行控制,这样,我们便可以将我们的方块玩出更多的“花样”。
## 连接模组SDK
方块实体的服务端实体定义完成后,我们又多出了很多接口来对接这个实体。与上一节中的接口不同的是,针对于方块实体的实体部分的接口全都位于客户端。这也很容易理解,毕竟这是在代表客户端的资源包中定义的实体。
| 接口 | 所属端 | 用处 |
| ------------------------------------------------------------ | -------------------------------------------------------- | ---------------------------------------------- |
| <a href="../../../mcdocs/1-ModAPI/接口/方块/渲染.html#setblockentitymodelposoffset" rel="noopenner"> `SetBlockEntityModelPosOffset` </a> | <span style="display:inline;color:#7575f9">客户端</span> | 设置自定义方块实体的实体模型的位置偏移。 |
| <a href="../../../mcdocs/1-ModAPI/接口/方块/渲染.html#setblockentitymodelrotation" rel="noopenner"> `SetBlockEntityModelRotation` </a> | <span style="display:inline;color:#7575f9">客户端</span> | 设置自定义方块实体的实体模型在各个轴上的旋转。 |
| <a href="../../../mcdocs/1-ModAPI/接口/方块/渲染.html#setblockentitymodelscale" rel="noopenner"> `SetBlockEntityModelScale` </a> | <span style="display:inline;color:#7575f9">客户端</span> | 设置自定义方块实体的实体模型的尺度。 |
| <a href="../../../mcdocs/1-ModAPI/接口/方块/渲染.html#setenableblockentityanimations" rel="noopenner"> `SetEnableBlockEntityAnimations` </a> | <span style="display:inline;color:#7575f9">客户端</span> | 设置是否开启自定义方块实体的动画。 |
| <a href="../../../mcdocs/1-ModAPI/接口/方块/渲染.html#setblockentitymolangvalue" rel="noopenner"> `SetBlockEntityMolangValue` </a> | <span style="display:inline;color:#7575f9">客户端</span> | 设置自定义方块实体的Molang变量的值。 |
| <a href="../../../mcdocs/1-ModAPI/接口/方块/渲染.html#getblockentitymolangvalue" rel="noopenner"> `GetBlockEntityMolangValue` </a> | <span style="display:inline;color:#7575f9">客户端</span> | 获取自定义方块实体的Molang变量的值。 |