Files
netease-modsdk-wiki/docs/mcdocs/1-ModAPI/接口/方块/渲染.md
2025-03-17 13:24:39 +08:00

296 lines
11 KiB
Markdown
Raw 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.

---
sidebarDepth: 1
---
# 渲染
## ChangeBlockTextures
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
替换方块贴图
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| blockName | str | 方块标识符,格式[namespace:name:auxvalue]auxvalue默认为0; 只支持普通的没有特殊渲染逻辑的方形方块,否则可能会显示异常 |
| tileName | str | 原贴图在图集中对应的名字对应terrain_texture.json中的配置 |
| texturePath | str | 打算替换成的贴图的路径 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功(因为采用延迟加载,此处返回成功不代表贴图路径正确,路径错误会导致渲染时贴图丢失显示异常) |
- 备注
- 对纹理会动态变化的方块无效
- 调用此接口后tileName不会发生变化后续如果想恢复设置依旧需要用这个tileName
- 贴图的分辨率高度需要为宽度的整数倍
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
#设置朝上的面的贴图为work_block_other
print(comp.ChangeBlockTextures("myblock:work_block:0", "myblock:work_block_faceup", "textures/blocks/work_block_other"))
#恢复朝上的面的贴图
#print(comp.ChangeBlockTextures("myblock:work_block:0", "myblock:work_block_faceup", "textures/blocks/work_block_faceup"))
```
## GetBlockTextures
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
获取方块的初始贴图信息
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| blockName | str | 方块标识符,格式[namespace:name] |
| face | int | 需要获取的方块面,参考[Facing枚举](../../枚举值/Facing.md)face默认值为6此时获取方块所有面的贴图信息 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | 方块的贴图信息textureInfoDict获取错误如特殊方块门、床等则返回为None |
- 备注
- name为贴图在图集中对应的名字方块所用的贴图名字见blocks.json
- 每一个贴图名name在terrain_texture.json中可能存在多个路径因此该接口也会返回同样多的路径。
- 该接口只作为校验用获取到的贴图信息为游戏加载后的初始信息ChangeBlockTextures修改后该接口返回的仍是初始信息。
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
textureInfoDict = comp.GetBlockTextures("customblocks:customblocks_test_ore")
# textureInfoDict 信息如下
# {
# 'North': {'paths': ['textures/blocks/customblocks_ore'], 'name': 'customblocks:customblocks_test_ore'},
# 'West': {'paths': ['textures/blocks/customblocks_ore'],'name': 'customblocks:customblocks_test_ore'},
# 'Up': {'paths': ['textures/blocks/customblocks_ore'], 'name': 'customblocks:customblocks_test_ore'},
# 'Down': {'paths': ['textures/blocks/customblocks_ore'], 'name': 'customblocks:customblocks_test_ore'},
# 'East': {'paths': ['textures/blocks/customblocks_ore'], 'name': 'customblocks:customblocks_test_ore'},
# 'South': {'paths': ['textures/blocks/customblocks_ore'], 'name': 'customblocks:customblocks_test_ore'}
# }
```
## SetBlockEntityFramePosOffset
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
设置自定义方块实体中序列帧特效位置偏移值,用于调整序列帧特效相对于方块位置的偏移。与特效/序列帧/SetPos接口不同该接口调整的是相对于方块位置的位置偏移值而不是世界坐标。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块所在位置 |
| frameKeyName | str | 该序列帧特效的自定义键值名称。 |
| effectPosOffset | tuple(int,int,int) | 序列帧特效相对于方块位置的xyz方向的偏移值 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
# 调整序列帧特效的位置,在方块的位置上向+x轴方向偏移1, +y轴方向偏移2, +z轴方向偏移1
comp.SetBlockEntityFramePosOffset(pos, "my_frame1", (1,2,1))
```
## SetBlockEntityModelPosOffset
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
设置自定义方块实体的实体模型位置偏移值用于调整实体模型相对于方块位置的偏移。可通过该接口来调整自定义方块实体的实体模型的位置。只有自定义方块实体定义实体模型才生效实体模型在resource_pack/entity/下定义,详细可参考自定义方块实体动画的教学文档。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块所在位置 |
| modelPosOffset | tuple(int,int,int) | 实体模型相对于方块位置的xyz方向的偏移值 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- 在调整实体模型的位置时,注意不要设置模型位置离方块实体的位置过远。如果设置过远,在玩家将屏幕移动到其他地方而看不到方块实体时,实体模型会由于玩家屏幕里不存在该方块实体而停止渲染。在这种情况下,每当玩家屏幕里看不到这个方块实体所在的位置时,实体模型都会消失。
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
# 调整模型的位置,偏移值为向+x轴方向偏移1, +y轴方向偏移2, +z轴方向偏移1
comp.SetBlockEntityModelPosOffset(pos, (1,2,1))
```
## SetBlockEntityModelRotation
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
设置自定义方块实体的实体模型在各个轴上的旋转值可通过该接口来调整自定义方块实体的实体模型的旋转。只有自定义方块实体定义实体模型才生效实体模型在resource_pack/entity/下定义,详细可参考自定义方块实体动画的教学文档。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块所在位置 |
| angles | float | 旋转角度,范围为[-360,360]。 |
| rotateAxis | str | 旋转轴,绕该轴进行旋转,该参数仅支持填写以下三个值之一: "x", "y", "z",大小写均可。 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- 在调整旋转角度时,注意旋转的顺序和角度的设置,避免出现万向锁的问题。
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
# 调整模型旋转绕x轴旋转30度
comp.SetBlockEntityModelRotation(pos, 30, "x")
# 调整模型旋转绕y轴旋转30度
comp.SetBlockEntityModelRotation(pos, 30, "y")
# 调整模型旋转绕z轴旋转30度
comp.SetBlockEntityModelRotation(pos, 30, "z")
```
## SetBlockEntityModelScale
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
设置自定义方块实体的实体模型大小的缩放值可通过该接口来调整自定义方块实体的实体模型的大小。只有自定义方块实体定义实体模型才生效实体模型在resource_pack/entity/下定义,详细可参考自定义方块实体动画的教学文档。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块所在位置 |
| scale | tuple(int,int,int) | 实体模型在x,y,z各个轴上的缩放值。支持负值当某一轴的缩放值为负值时表示模型将会在这个轴上进行以另外两个轴为对称平面的镜像变换。 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- 模型的大小可以通过两个方式来调整:
(1) 在entity.json中scripts字段下定义scale如下所示
"minecraft:client_entity": {
...
"scripts":{
// 整体模型大小缩放值,定义了"scale"之后scalexscaleyscalez将无效
"scale" : "0.9375",
// 对三个轴方向的缩放值。注释掉上方"scale", 以下三个缩放值将生效。
"scalex": "0.9375",
"scaley": "0.9375",
"scalez": "0.9375",
...
}
}
(2) 使用本接口SetBlockEntityModelScale来设置模型缩放值。
以上两种方式,第一种方式是对所有的使用这个模型的方块实体生效,第二种方式是对指定的方块实体的模型生效。如果同时使用了第一种方式以及第二种方式来调整模型大小,则模型会先按照第一种方式来进行缩放,再按照第二种方式来进行缩放。
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
# 调整模型大小为x轴方向放大为原来的2倍y轴方向放大为原来的2倍z轴方向缩小为原来的0.5倍
comp.SetBlockEntityModelScale(pos, (2,2,0.5))
```
## SetBlockEntityParticlePosOffset
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
设置自定义方块实体中粒子特效位置偏移值,用于调整粒子特效相对于方块位置的偏移。与特效/粒子/SetPos接口不同该接口调整的是相对于方块位置的位置偏移值而不是世界坐标。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块所在位置 |
| particleKeyName | str | 该粒子特效的自定义键值名称。 |
| effectPosOffset | tuple(int,int,int) | 粒子特效相对于方块位置的xyz方向的偏移值 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
# 调整粒子特效的位置,在方块的位置上向+x轴方向偏移1, +y轴方向偏移2, +z轴方向偏移1
comp.SetBlockEntityParticlePosOffset(pos, "my_particle1", (1,2,1))
```