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

30 KiB
Raw Blame History

sidebarDepth
sidebarDepth
1

渲染

AddActorAnimation

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    增加生物渲染动画

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 实体identifier
    animationKey str 动画键
    animationName str 动画名称
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
comp.AddActorAnimation("minecraft:pig", "custom_move", "animation.pig.custom_move")

AddActorAnimationController

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    增加生物渲染动画控制器

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 生物的identifier
    animationControllerKey str 动画控制器键
    animationControllerName str 动画控制器名称
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(entityId)
comp.AddActorAnimationController("minecraft:skeleton", "controller__use_item_progress", "controller.animation.humanoid.use_item_progress")

AddActorBlockGeometry

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    为实体添加方块几何体模型。

  • 参数

    参数名
    数据类型
    说明
    geometryName str 几何体模型的名称用于标识每个几何体模型相当于是该模型的id
    offset tuple(float,float,float) 方块几何体模型相对实体的位置偏移值,可选参数,默认为(0, 0, 0)。
    rotation tuple(float,float,float) 方块几何体模型相对实体的旋转角度,可选参数,默认为(0, 0, 0)分别表示绕x,y,z轴的旋转角度旋转顺序按z,x,y顺序旋转。
  • 返回值

    数据类型
    说明
    bool 添加是否成功成功返回True失败返回False。如果实体已经拥有了相同名称的模型则也会返回True
  • 备注

    • 请在确保世界已经初始化完成后例如监听UiInitFinished事件再调用该接口否则过早调用会导致接口执行失败。
  • 示例

import mod.client.extraClientApi as clientApi
blockGeometryComp = clientApi.GetEngineCompFactory().CreateBlockGeometry(levelId)
actorRenderComp = clientApi.GetEngineCompFactory().CreateActorRender("-4294967295")
# 合并方块并转换为名叫"my_block_geometry"的方块几何体模型
geometryName = blockGeometryComp.CombineBlockFromPosListToGeometry([(200,64,200),(201,65,202)],"my_block_geometry")
# 添加到实体id为-4294967295的实体中
print actorRenderComp.AddActorBlockGeometry(geometryName)

AddActorGeometry

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    增加生物渲染几何体

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 生物实体identifier
    geometryKey str 渲染几何体键如default
    geometryName str 渲染几何体名称如熊猫几何体geometry.panda
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 备注

    • 调用该接口后需要调用RebuildActorRender才会生效 动画和贴图都是与几何体密切相关的,改变几何体也需要改变动画与贴图。建议先修改生物的动画以及动画控制器后再修改生物的几何。
    • 某些生物受初始动画影响,几何体会有初始偏移,会导致修改几何体后表现异常。若修改后的几何体没有当前动画需要的骨骼时,会触发报错。
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
comp.AddActorGeometry("minecraft:sheep", "default", "geometry.panda")

AddActorParticleEffect

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    增加生物特效资源

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 实体identifier
    effectKey str 特效资源Key如bee.entity.json中的nectar_dripping
    effectName str 特效资源名称如minecraft:nectar_drip_particle
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
comp.AddActorParticleEffect("minecraft:villager", "nectar_dripping", "minecraft:nectar_drip_particle")

AddActorRenderController

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    增加生物渲染控制器

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 生物identifier
    renderControllerName str 渲染控制器名称
    condition str 渲染控制器条件当该条件成立时renderControllerName指向的渲染控制器才会生效
  • 返回值

    数据类型
    说明
    bool 添加是否成功
  • 备注

    • 调用该接口后需要调用RebuildActorRender才会生效
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
comp.AddActorRenderController('minecraft:villager', 'custom_render_controller_name', 'query.mod.condition')

AddActorRenderControllerArray

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    增加生物渲染控制器列表中字典arrays元素

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 实体identifier
    renderControllerName str 实体生物渲染控制器名称
    arrayType int 渲染控制器arrays类型(渲染控制器arrays类型枚举)
    arrayName str 数组名称
    expression str 待添加元素表达式
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 备注

    • 该接口增加render_controller->arrays—>materials/textures/geometries->array.***中的元素
    • 调用该接口后需要调用RebuildActorRender才会生效
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(entityId)
comp.AddActorRenderControllerArray("minecraft:pig", "controller.render.pig", clientApi.GetMinecraftEnum().RenderControllerArrayType.Texture, "Array.skins", "Texture.test")

AddActorRenderMaterial

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    增加生物渲染需要的材质

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 生物的identifier
    materialKey str 材质key
    materialName str 材质名称
  • 返回值

    数据类型
    说明
    bool 添加是否成功
  • 备注

    • 调用该接口后需要调用RebuildActorRender才会生效
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(playerId)
comp.AddActorRenderMaterial('minecraft:villager', 'custom_material_key', 'custom_material_name')

AddActorScriptAnimate

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    在生物的客户端实体定义minecraft:client_entityjson中的scripts/animate节点添加动画/动画控制器

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 实体identifier
    animateName str 动画/动画控制器名称如look_at_target
    condition str 动画/动画控制器控制表达式默认为空如query.mod.index > 0
    autoReplace bool 是否覆盖已存在的动画/动画控制器默认值为False
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 备注

    • 对于已经存在的生物在调用CreateActorRender时需要传生物Id才能马上生效对于不存在的生物直接传levelId即可。
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(entityId)
comp.AddActorAnimationController("minecraft:pig", "animation_controller_short_name", "controller.animation.pig.custom_animation_controller")
comp.AddActorScriptAnimate("minecraft:pig", "animation_controller_short_name", "query.mod.index > 0")

AddActorSoundEffect

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    增加生物音效资源

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 实体identifier
    soundKey str 音效资源Key
    soundName str 音效资源名称
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 备注

    • 目前只支持在动作(animation)中播放音效,不支持在动作控制器(animation controller)中播放音效。
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
comp.AddActorSoundEffect("minecraft:villager", "sound_thunder", "ambient.weather.thunder")

AddActorTexture

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    增加生物渲染贴图

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 生物实体identifier
    textureKey str 贴图键
    texturePath str 贴图路径
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 备注

    • 调用该接口后需要调用RebuildActorRender才会生效
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
comp.AddActorTexture("minecraft:sheep", "default", "textures/entity/panda/panda")

BindEntityToEntity

客户端

method in mod.client.component.modelCompClient.ModelComponentClient

  • 描述

    绑定骨骼模型跟随其他entity,摄像机也跟随其他entity

  • 参数

    参数名
    数据类型
    说明
    bindEntityId str 绑定跟随的实体Id
  • 返回值

    数据类型
    说明
    bool False表示失败True表示成功
  • 备注

    • 本接口只实现视觉效果本质上实体还是在原地因此需要调用接口设置实体的位置到其他entity的位置上否则当实体本身不在摄像机范围内的时候就会不进行渲染了。
  • 示例

import mod.client.extraClientApi as clientApi
# 将entityId的实体绑定至bindEntityId的实体
comp = clientApi.GetEngineCompFactory().CreateModel(entityId)
comp.BindEntityToEntity(bindEntityId)

ClearActorBlockGeometry

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    删除实体中所有的方块几何体模型。

  • 参数

  • 返回值

    数据类型
    说明
    bool 删除是否成功成功返回True失败返回False。
  • 示例

import mod.client.extraClientApi as clientApi
blockGeometryComp = clientApi.GetEngineCompFactory().CreateBlockGeometry(levelId)
actorRenderComp = clientApi.GetEngineCompFactory().CreateActorRender("-4294967295")
# 合并方块并转换为名叫"my_block_geometry"的方块几何体模型
geometryName = blockGeometryComp.CombineBlockFromPosListToGeometry([(200,64,200),(201,65,202)],"my_block_geometry")
# 添加到实体id为-4294967295的实体中
print actorRenderComp.AddActorBlockGeometry(geometryName)
# 清空实体中所有的方块几何体
print actorRenderComp.ClearActorBlockGeometry()

DeleteActorBlockGeometry

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    删除实体中指定方块几何体模型。

  • 参数

    参数名
    数据类型
    说明
    geometryName str 几何体模型的名称用于标识每个几何体模型相当于是该模型的id
  • 返回值

    数据类型
    说明
    bool 删除是否成功成功返回True失败返回False。
  • 示例

import mod.client.extraClientApi as clientApi
blockGeometryComp = clientApi.GetEngineCompFactory().CreateBlockGeometry(levelId)
actorRenderComp = clientApi.GetEngineCompFactory().CreateActorRender("-4294967295")
# 合并方块并转换为名叫"my_block_geometry"的方块几何体模型
geometryName = blockGeometryComp.CombineBlockFromPosListToGeometry([(200,64,200),(201,65,202)],"my_block_geometry")
# 添加到实体id为-4294967295的实体中
print actorRenderComp.AddActorBlockGeometry(geometryName)
# 删除刚才添加的方块几何体
print actorRenderComp.DeleteActorBlockGeometry(geometryName)

GetNotRenderAtAll

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    获取实体是否不渲染

  • 参数

  • 返回值

    数据类型
    说明
    bool True表示不渲染
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(entityId)
notRender = comp.GetNotRenderAtAll()

RebuildActorRender

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    重建生物的数据渲染器该接口不支持玩家玩家请使用RebuildPlayerRender

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 实体identifier
  • 返回值

    数据类型
    说明
    bool 重建是否成功
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
comp.RebuildActorRender('minecraft:villager')

RemoveActorAnimationController

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    移除生物渲染动画控制器

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 生物的identifier
    animationControllKey str 动画控制器键注意该值需要在json中动画控制器键加上前缀“controller__”
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(entityId)
comp.RemoveActorAnimationController("minecraft:villager", "controller__use_item_progress")

RemoveActorGeometry

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    删除生物渲染几何体

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 生物实体identifier
    geometryKey str 渲染几何体名称如熊猫几何体geometry.panda
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 备注

    • 调用该接口后需要调用RebuildActorRender才会生效 动画和贴图都是与几何体密切相关的,改变几何体也需要改变动画与贴图
  • 示例

import mod.client.extraClientApi as clientApi
# geometry definition in panda.entity.json
# "geometry": {
#     "default": "geometry.panda"
# },
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
comp.RemoveActorGeometry("minecraft:panda", "default")

RemoveActorRenderController

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    删除生物渲染控制器

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 生物identifier
    renderControllerName str 渲染控制器名称
  • 返回值

    数据类型
    说明
    bool 删除是否成功
  • 备注

    • 调用该接口后需要调用RebuildActorRender才会生效
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
comp.RemoveActorRenderController('minecraft:villager', 'custom_render_controller_name')

RemoveActorTexture

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    删除生物渲染贴图

  • 参数

    参数名
    数据类型
    说明
    actorIdentifier str 生物实体identifier
    textureKey str 贴图键如default
  • 返回值

    数据类型
    说明
    bool 是否成功
  • 备注

    • 调用该接口后需要调用RebuildActorRender才会生效
  • 示例

import mod.client.extraClientApi as clientApi
# texture definition in panda.entity.json
# "textures": {
#     "default": "textures/entity/panda/panda",
#     "lazy": "textures/entity/panda/panda_lazy",
#     "worried": "textures/entity/panda/panda_worried",
#     "playful": "textures/entity/panda/panda_playful",
#     "brown": "textures/entity/panda/panda_brown",
#     "weak": "textures/entity/panda/panda_sneezy",
#     "aggressive": "textures/entity/panda/panda_aggressive"
# }
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
comp.RemoveActorTexture("minecraft:panda", "default")

ResetBindEntity

客户端

method in mod.client.component.modelCompClient.ModelComponentClient

  • 描述

    取消目标entity的绑定实体取消后不再跟随任何其他entity

  • 参数

  • 返回值

    数据类型
    说明
    bool False表示失败True表示成功
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateModel(entityId)
comp.ResetBindEntity()

SetActorAllBlockGeometryVisible

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    设置实体中所有的方块几何体模型是否显示。

  • 参数

    参数名
    数据类型
    说明
    visible bool 设置是否显示或隐藏True表示显示False表示隐藏
  • 返回值

    数据类型
    说明
    bool 设置是否成功成功返回True失败返回False。
  • 示例

import mod.client.extraClientApi as clientApi
blockGeometryComp = clientApi.GetEngineCompFactory().CreateBlockGeometry(levelId)
actorRenderComp = clientApi.GetEngineCompFactory().CreateActorRender("-4294967295")
# 合并方块并转换为名叫"my_block_geometry"的方块几何体模型
geometryName = blockGeometryComp.CombineBlockFromPosListToGeometry([(200,64,200),(201,65,202)],"my_block_geometry")
# 添加到实体id为-4294967295的实体中
print actorRenderComp.AddActorBlockGeometry(geometryName)
# 隐藏所有的方块几何体
print actorRenderComp.SetActorAllBlockGeometryVisible(False)

SetActorBlockGeometryVisible

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    设置实体中指定的方块几何体模型是否显示。

  • 参数

    参数名
    数据类型
    说明
    geometryName str 几何体模型的名称用于标识每个几何体模型相当于是该模型的id
    visible bool 设置是否显示或隐藏True表示显示False表示隐藏
  • 返回值

    数据类型
    说明
    bool 设置是否成功成功返回True失败返回False。
  • 示例

import mod.client.extraClientApi as clientApi
blockGeometryComp = clientApi.GetEngineCompFactory().CreateBlockGeometry(levelId)
actorRenderComp = clientApi.GetEngineCompFactory().CreateActorRender("-4294967295")
# 合并方块并转换为名叫"my_block_geometry"的方块几何体模型
geometryName = blockGeometryComp.CombineBlockFromPosListToGeometry([(200,64,200),(201,65,202)],"my_block_geometry")
# 添加到实体id为-4294967295的实体中
print actorRenderComp.AddActorBlockGeometry(geometryName)
# 隐藏刚才添加的方块几何体
print actorRenderComp.SetActorBlockGeometryVisible(geometryName, False)

SetAlwaysShowName

客户端

method in mod.client.component.nameCompClient.NameComponentClient

  • 描述

    设置生物名字是否一直显示,瞄准点不指向生物时也能显示

  • 参数

    参数名
    数据类型
    说明
    show bool True为显示
  • 返回值

    数据类型
    说明
    bool 返回是否设置成功
  • 备注

    • 该接口只对普通生物生效,对玩家设置不起作用
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateName(entityId)
# 不显示头上的名字
comp.SetAlwaysShowName(False)

SetColor

客户端

method in mod.client.component.healthCompClient.HealthComponentClient

  • 描述

    设置血条的颜色及背景色

  • 参数

    参数名
    数据类型
    说明
    front tuple(float,float,float,float) 血条颜色的RGBA值范围0-1
    back tuple(float,float,float,float) 背景颜色的RGBA值范围0-1
  • 返回值

  • 备注

    • 必须用game组件设置ShowHealthBar时才能显示血条
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateHealth(entityId)
comp.SetColor((0, 0, 0, 1), (1, 1, 1, 1))

SetHealthBarDeviation

客户端

method in mod.client.component.healthCompClient.HealthComponentClient

  • 描述

    设置某个entity血条的相对高度

  • 参数

    参数名
    数据类型
    说明
    health_bar_deviation float 血条的相对高度
  • 返回值

    数据类型
    说明
    bool 是否设置成功
  • 备注

    • 必须用game组件设置ShowHealthBar时才能显示血条血条默认在生物AABB上方1.5高度处
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateHealth(entityId)
# 设置血条的相对高度
comp.SetHealthBarDeviation(1.0)

SetNameDeeptest

客户端

method in mod.client.component.gameCompClient.GameComponentClient

  • 描述

    设置名字是否透视

  • 参数

    参数名
    数据类型
    说明
    deeptest bool True为不透视。默认情况下为透视
  • 返回值

    数据类型
    说明
    bool 设置是否成功
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
# 设置为不透视
comp.SetNameDeeptest(True)

SetNotRenderAtAll

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

    设置是否关闭实体渲染

  • 参数

    参数名
    数据类型
    说明
    notRender bool True表示不渲染该实体
  • 返回值

    数据类型
    说明
    bool 设置是否成功
  • 示例

import mod.client.extraClientApi as clientApi
# 不渲染单个实体 entityId
comp = clientApi.GetEngineCompFactory().CreateActorRender(entityId)
comp.SetNotRenderAtAll(True)
# 重新开始渲染该实体
comp.SetNotRenderAtAll(False)

SetRenderLocalPlayer

客户端

method in mod.client.component.gameCompClient.GameComponentClient

  • 描述

    设置本地玩家是否渲染

  • 参数

    参数名
    数据类型
    说明
    render bool True为渲染
  • 返回值

    数据类型
    说明
    bool 设置是否成功
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
# 不渲染本地玩家
comp.SetRenderLocalPlayer(False)

SetShowName

客户端

method in mod.client.component.nameCompClient.NameComponentClient

  • 描述

    设置生物名字是否按照默认游戏逻辑显示

  • 参数

    参数名
    数据类型
    说明
    show bool True为显示
  • 返回值

    数据类型
    说明
    bool 返回是否设置成功
  • 备注

    • 当设置为True时生物的名字显示遵循游戏默认的渲染逻辑即普通生物需要中心点指向生物才显示名字玩家则是会一直显示名字
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateName(entityId)
# 不显示头上的名字
comp.SetShowName(False)

ShowHealth

客户端

method in mod.client.component.healthCompClient.HealthComponentClient

  • 描述

    设置某个entity是否显示血条默认为显示

  • 参数

    参数名
    数据类型
    说明
    show bool 设置是否显示
  • 返回值

  • 备注

    • 必须用game组件设置ShowHealthBar时才能显示血条
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateHealth(entityId)
# 设置该entity不显示血条
comp.ShowHealth(False)

ShowHealthBar

客户端

method in mod.client.component.gameCompClient.GameComponentClient

  • 描述

    设置是否显示血条

  • 参数

    参数名
    数据类型
    说明
    show bool True为显示。开启后可用health组件单独设置某个实体的血条颜色及是否显示
  • 返回值

    数据类型
    说明
    bool 设置是否成功
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
comp.ShowHealthBar(True)