Files
netease-modsdk-wiki/docs/mcdocs/1-ModAPI/接口/方块/渲染.md
2025-03-18 14:46:12 +08:00

552 lines
20 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
---
# 渲染
## AddDropItemToWorld
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.itemCompClient.ItemCompClient
- 描述
在客户端添加一个掉落物渲染
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| itemDict | dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a> |
| dimension_id | int | 生成的掉落物所在维度 |
| position | tuple(float,float,float) | 生成的掉落物所在位置 |
| bobSpeed | float | 单位时间上下移动的距离负数为向下移动填2即为原版两倍上下移动速度不填默认为0 |
| spinSpeed | float | 单位时间旋转的速度,负数为反方向,填-2即为原版两倍反方向旋转速度不填默认为0 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| str | 返回该掉落物的entityId |
- 备注
- 当掉落物是可合堆时若count大于1会渲染已合堆的掉落物
- 示例
```python
import mod.client.extraClientApi as clientApi
itemDict = {
'itemName': 'minecraft:bow',
'count': 1,
'enchantData': [(clientApi.GetMinecraftEnum().EnchantType.BowDamage, 1),],
'auxValue': 0,
}
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 即在维度为0位置为(10,10,10),生成一个不会上下移动,旋转方向与原版相反,旋转速度为原版两倍的附魔弓
comp.AddDropItemToWorld(itemDict, 0, (10,10,10), 0, -2)
```
## 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"))
```
## DeleteClientDropItemEntity
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.itemCompClient.ItemCompClient
- 描述
删除AddDropItemToWorld创建的客户端掉落物
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| entityId | str | 掉落物的entityIdentityId可在调用[AddDropItemToWorld](#AddDropItemToWorld)时保存返回值,或者通过[GetClientDropItemEntityIdList](#GetClientDropItemEntityIdList)接口获取list |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否成功 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
print comp.DeleteClientDropItemEntity(entityId)
```
## GetBlockEntityExtraUniforms
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
获取在自定义方块实体的shader当中使用的自定义变量的值该自定义变量总共可设置EXTRA_ACTOR_UNIFORM1,EXTRA_ACTOR_UNIFORM2,EXTRA_ACTOR_UNIFORM3,EXTRA_ACTOR_UNIFORM4总共4组每组为一个vec4(float, float, float ,float)类型的向量。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块实体所在位置 |
| uniformIndex | int | 需要设置的自定义变量的下标值范围为1~4。分别对应EXTRA_ACTOR_UNIFORM1,EXTRA_ACTOR_UNIFORM2,EXTRA_ACTOR_UNIFORM3,EXTRA_ACTOR_UNIFORM4。 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| tuple(float,float,float,float) | 返回的对应自定义变量的值。获取失败则返回None。 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
# 获取坐标位于(100,66,100)的自定义方块实体的自定义变量EXTRA_ACTOR_UNIFORM2的值
print comp.GetBlockEntityExtraUniforms((100,66,100), 2)
# 获取坐标位于(100,66,101)的自定义方块实体的自定义变量EXTRA_ACTOR_UNIFORM4的值
print comp.SetBlockEntityExtraUniforms((100,66,101), 4)
```
## GetBlockRenderDistance
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
获取玩家周围的可渲染距离
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| float | 玩家周围的可渲染距离,未设置过渲染距离时,返回的是原版能见度对应的渲染距离。 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
print comp.GetBlockRenderDistance()
```
## 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'}
# }
```
## GetClientDropItemEntityIdList
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.itemCompClient.ItemCompClient
- 描述
获得所有通过AddDropItemToWorld创建的entityId的list
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| list(str) | 返回所有通过AddDropItemToWorld创建的entityId的list |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
print comp.GetClientDropItemEntityIdList()
```
## SetBlockEntityExtraUniforms
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
设置可在自定义方块实体的shader当中使用的自定义变量的值该自定义变量总共可设置EXTRA_ACTOR_UNIFORM1,EXTRA_ACTOR_UNIFORM2,EXTRA_ACTOR_UNIFORM3,EXTRA_ACTOR_UNIFORM4总共4组每组为一个vec4(float, float, float ,float)类型的向量,向量的默认值为(1.0,1.0,1.0,1.0)。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块实体所在位置 |
| uniformIndex | int | 需要设置的自定义变量的下标值范围为1~4。分别对应EXTRA_ACTOR_UNIFORM1,EXTRA_ACTOR_UNIFORM2,EXTRA_ACTOR_UNIFORM3,EXTRA_ACTOR_UNIFORM4。 |
| data | tuple(float,float,float,float) | 需要设置的自定义变量的值。 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功成功返回True否则返回False |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
# 对坐标位于(100,66,100)的自定义方块实体设置自定义变量EXTRA_ACTOR_UNIFORM1的值
print comp.SetBlockEntityExtraUniforms((100,66,100), 1, (2.5,2.5,2.5,2.5))
# 对坐标位于(100,66,101)的自定义方块实体设置自定义变量EXTRA_ACTOR_UNIFORM3的值
print comp.SetBlockEntityExtraUniforms((100,66,101), 3, (2.5,2.5,2.5,2.5))
# 接下来我们找到这个自定义方块实体所使用的材质在其中定义的vertex shader或是fragment shader中做如下声明及使用
#
# // .. 省略其他代码
# // 声明这两个自定义变量
# uniform vec4 EXTRA_ACTOR_UNIFORM1;
# uniform vec4 EXTRA_ACTOR_UNIFORM3;
#
# void main() {
# vec4 my_custom_value = EXTRA_ACTOR_UNIFORM1;
# vec4 my_custom_value = EXTRA_ACTOR_UNIFORM3;
# // .. do what you want ..
# }
```
## 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))
```
## SetBlockRenderDistance
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
设置玩家周围方块的可渲染距离
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| distance | float | 区块的可渲染距离有效值范围为大于等于16传入无效值则使用原版游戏内的能见度能见度区块数x与渲染距离dis的换算方法约为dis = x*16 + 13.8564。 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功成功返回True失败返回False。 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
# 设置方块的可渲染距离为48
print comp.SetBlockRenderDistance(48)
```