# 行为

# AddActorComponentGroup

服务端

method in mod.server.component.entityEventCompServer.EntityEventComponentServer

  • 描述

    给指定实体添加实体json中配置的ComponentGroup

  • 参数

    参数名
    数据类型
    说明
    groupName str 实体行为包中定义的component_group的键名
  • 返回值

    数据类型
    说明
    bool 指令是否成功发出
  • 备注

    • 该接口不会判断生物的json是否具有传入的groupName,返回值的结果只代表指令是否正常发出
    • 在羊的entity json文件中component_groups字段下配置羊的颜色:
      "component_groups": {
          "minecraft:sheep_white": {
              "minecraft:color": {
              "value": 0
              }
          },
          "minecraft:sheep_brown": {
              "minecraft:color": {
              "value": 12
              }
          },
          "minecraft:sheep_black": {
              "minecraft:color": {
              "value": 15
              }
          },
          ......
          "minecraft:sheep_red": {
              "minecraft:color": {
              "value": 14
              }
          }
      }
      
  • 示例

#将羊变为红色
import mod.server.extraServerApi as serverApi
groupName = "minecraft:sheep_red"
comp = serverApi.GetEngineCompFactory().CreateEntityEvent(entityId)
comp.AddActorComponentGroup(groupName)

# AddEntityAroundEntityMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    给实体(不含玩家)添加对实体环绕运动器

  • 参数

    参数名
    数据类型
    说明
    eID str 要环绕的某个实体的ID
    angularVelocity float 圆周运动的角速度(弧度/秒)
    axis tuple(float,float,float) 圆周运动的轴,决定了在哪个平面上做圆周运动,默认为(0, 1, 0)
    lockDir bool 是否在运动器生效时锁定实体的朝向,不锁定则实体的朝向会随着运动而改变,默认为False。
    stopRad float 停止该运动器所需要的弧度,当stopRad为0时,该运动器会一直运行,默认为0
    radius float 环绕半径,当设置为-1时环绕运动器使用启动时与目标的距离作为半径,当设置为非负数时表示按设定的值作为环绕半径,默认为-1
  • 返回值

    数据类型
    说明
    int 运动器ID,添加失败时返回-1
  • 备注

    • 该接口不屏蔽生物本身的AI运动以及重力作用,当有AI运动发生时,最终的表现结果可能与预期有差异。
    • 环绕运动器可叠加多个,且可与速度运动器互相叠加,每一帧的最终效果为各个运动器计算出的瞬时向量之和。
    • 由于引擎中在加载的区块以外的实体时会停止一切活动,建议将实体的运动范围控制在玩家位置±100内。
    • 参数中环绕半径radius和角速度angularVelocity需要配合调整,避免最后得出的线速度过大造成运动不平滑。
  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
axis=(-1, 1, 1)
mID = motionComp.AddEntityAroundEntityMotion(eID, 1.0, axis, lockDir=False, stopRad=0, radius=2.0)

# AddEntityAroundPointMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    给实体(不含玩家)添加对点环绕运动器

  • 参数

    参数名
    数据类型
    说明
    center tuple(float,float,float) 要环绕的圆心点坐标
    angularVelocity float 圆周运动的角速度(弧度/秒)
    axis tuple(float,float,float) 圆周运动的轴,决定了在哪个平面上做圆周运动,默认为(0, 1, 0)
    lockDir bool 是否在运动器生效时锁定实体的朝向,不锁定则实体的朝向会随着运动而改变,默认为False。
    stopRad float 停止该运动器所需要的弧度,当stopRad为0时,该运动器会一直运行,默认为0
  • 返回值

    数据类型
    说明
    int 运动器ID,添加失败时返回-1
  • 备注

    • 该接口不屏蔽生物本身的AI运动以及重力作用,当有AI运动发生时,最终的表现结果可能与预期有差异。
    • 环绕运动器可叠加多个,且可与速度运动器互相叠加,每一帧的最终效果为各个运动器计算出的瞬时向量之和。
    • 由于引擎中在加载的区块以外的实体时会停止一切活动,建议将实体的运动范围控制在玩家位置±100内,同时避免线速度过大造成运动不平滑的现象。
  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
center = (0, 8, 0)
axis=(-1, 1, 1)
mID = motionComp.AddEntityAroundPointMotion(center, 1.0, axis, lockDir=False, stopRad=0)

# AddEntitySeat

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    增加坐骑座位

  • 参数

    参数名
    数据类型
    说明
    pos tuple(float,float,float) 座位位置
    rot float 座位旋转,默认为0
    lock_rot float 骑乘者允许旋转角度范围,默认不限制
  • 返回值

    数据类型
    说明
    int 当前最大座位序号,增加失败返回-1
  • 备注

    • 通常需要配合SetEntityRide、SetControl一起使用,需要被骑乘生物json中骑乘组件支持骑乘者的生物类型。
    • 非玩家实体即使所处座位的lock_rot参数为默认值,也不可360度旋转。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
seatIndex = comp.AddEntitySeat((1.0, 1.0, 1.0), 90.0, 90.0)

# AddEntityTrackMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    给实体(不含玩家)添加轨迹运动器

  • 参数

    参数名
    数据类型
    说明
    targetPos tuple(float,float,float) 轨迹终点
    duraTime float 到达终点所需要的时间
    startPos tuple(float,float,float) 轨迹起点,默认为None,表示以调用StartEntityMotion的位置作为起点。
    relativeCoord bool 是否使用相对坐标设置起点和终点的位置以及朝向,默认为False。
    isLoop bool 是否循环,若设为True,则实体会在起点和终点之间往复运动,默认为False。
    targetRot tuple(float,float) 实体到达targetPos时的朝向,受参数relativeCoord影响,默认为None,表示使用调用StartEntityMotion时的朝向。
    startRot tuple(float,float) 实体到达startPos时的朝向,受参数relativeCoord影响,默认为None,表示使用调用StartEntityMotion时的朝向。
    useVelocityDir bool 是否使用运动中的速度方向作为朝向,默认为False,若为True,则参数targetRot和startRot无效
    ease TimeEaseType 时间变化函数, 默认值为serverApi.GetMinecraftEnum().TimeEaseType.linear, 参数不在枚举值中也当作linear
  • 返回值

    数据类型
    说明
    int 运动器ID,添加失败时返回-1
  • 备注

    • 该接口不屏蔽生物本身的AI运动,并且生物在空中时会受到跌落伤害,当有AI运动发生时,最终的表现结果可能与预期有差异,建议将生物设置为NPC。
    • 轨迹运动器不可叠加,仅能添加一个。
    • 由于引擎中在加载的区块以外的实体时会停止一切活动,建议将运动范围控制在玩家位置±100内。
    • 设置朝向后会根据相应的参数计算出最终朝向,若此时的targetRot > startRot,则会顺时针旋转,反之逆时针旋转。
  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
target = (5, 0, 0)
rot1 = (0, 0)
rot2 = (0, 360)
mID = motionComp.AddEntityTrackMotion(target, 3.0, startPos=None, relativeCoord=True, isLoop=False, targetRot=rot1, startRot=rot2, useVelocityDir=True, ease = serverApi.GetMinecraftEnum().TimeEaseType.linear)

# AddEntityVelocityMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    给实体(不含玩家)添加速度运动器

  • 参数

    参数名
    数据类型
    说明
    velocity tuple(float,float,float) 速度,包含大小、方向
    accelerate tuple(float,float,float) 加速度,包含大小、方向,默认为None,表示没有加速度
    useVelocityDir bool 是否使用当前速度的方向作为此刻实体的朝向,默认为True
  • 返回值

    数据类型
    说明
    int 运动器ID,添加失败时返回-1
  • 备注

    • 该接口不屏蔽生物本身的AI运动以及重力作用,当有AI运动发生时,最终的表现结果可能与预期有差异。
    • 速度运动器可叠加多个,且可与环绕运动器互相叠加。
    • 由于引擎中在加载的区块以外的实体时会停止一切活动,建议将实体的运动范围控制在玩家位置±100内。
  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
velocity = (0, 0, 1)
accelerate = (0, 0, -1)
mID = motionComp.AddEntityVelocityMotion(velocity, accelerate, useVelocityDir=True)

# ChangeRiderSeat

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    设置骑乘者在当前坐骑上的序号

  • 参数

    参数名
    数据类型
    说明
    riderIndex int 指定实体成为第n个骑乘者,范围为0~SeatCount-1
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 通常需要配合SetEntityRide、SetControl一起使用,需要被骑乘生物json中骑乘组件支持骑乘者的生物类型。
    • 未通过SetEntityLockRider锁定的实体,退出存档重进或有新的骑乘者时会遵循原版逻辑重置实体上的骑乘者。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.ChangeRiderSeat(1)

# DeleteEntitySeat

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    删除坐骑座位

  • 参数

    参数名
    数据类型
    说明
    seatIndex int 座位序号,范围为0~最大座位序号
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 通常需要配合SetEntityRide、SetControl一起使用,需要被骑乘生物json中骑乘组件支持骑乘者的生物类型。
    • 只能删除通过接口AddEntitySeat添加的座位。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.DeleteEntitySeat(1)

# GetAttackTarget

服务端客户端

# 服务端接口

method in mod.server.component.actionCompServer.ActionCompServer

  • 描述

    获取仇恨目标

  • 参数

  • 返回值

    数据类型
    说明
    str 返回仇恨目标的实体id。如果传入的实体id所对应的实体没有仇恨目标,则返回-1。如果传入的实体id所对应的实体不存在,则返回None。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAction(entityId)
comp.GetAttackTarget()

# 客户端接口

method in mod.client.component.actionCompClient.ActionCompClient

  • 描述

    获取仇恨目标

  • 参数

  • 返回值

    数据类型
    说明
    str 返回仇恨目标的实体id。如果传入的实体id所对应的实体没有仇恨目标,则返回-1。如果传入的实体id所对应的实体不存在,则返回None。
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateAction(entityId)
comp.GetAttackTarget()

# GetBlockControlAi

服务端

method in mod.server.component.controlAiCompServer.ControlAiCompServer

  • 描述

    获取生物原生AI是否被屏蔽

  • 参数

  • 返回值

    数据类型
    说明
    bool AI是否保留。False为AI被屏蔽。
  • 备注

    • 屏蔽AI后的生物无法行动,不受重力且不会被推动。但是可以受到伤害,也可以被玩家交互(例如马被骑或村民被交易)
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateControlAi(entityId)
comp.GetBlockControlAi()

# GetCustomGoalCls

服务端

method in mod.server.extraServerApi

  • 描述

    用于获取服务器自定义行为节点的基类。实现新的行为节点时,需要继承该接口返回的类

  • 参数

  • 返回值

    数据类型
    说明
    type(CustomGoal) 服务端自定义行为节点类
  • 示例

import mod.server.extraServerApi as serverApi
CustomGoal = serverApi.GetCustomGoalCls()
class CustomGoalDemo(CustomGoal):
    def __init__(self, entityId, argsJson):
        CustomGoalCls.__init__(self, entityId, argsJson)

# GetEntityMotions

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    获取实体(不含玩家)身上的所有运动器

  • 参数

  • 返回值

    数据类型
    说明
    dict 运动器集合,key值代表运动器mID,value值代表运动器类型0:轨迹运动器、1:速度运动器、2:环绕运动器
  • 备注

    • 运动器非人为停止后会被移除。
  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
motions = motionComp.GetEntityMotions()
# motions = {
#   0:1,
#   1:2
# }

# GetJumpPower

服务端

method in mod.server.component.gravityCompServer.GravityComponentServer

  • 描述

    获取生物跳跃力度,0.42表示正常水平

  • 参数

  • 返回值

    数据类型
    说明
    float 返回生物跳跃力度
  • 备注

    • 生物跳跃力度影响生物跳跃高度。
    • 由于python浮点数值精度问题,返回的数据字典中的浮点数可能会带有小数点后多位的现象,例如跳跃力度原本为0.2,则返回的的值可能会变为0.20000000298,请注意。
    • 兔子无法在外部通过SetJumpPower设置跳跃力度,因此调用此接口时,获取到的为实际兔子的跳跃力度,而不是SetJumpPower设置的值
    • 使用指令,跳跃药水,跳跃箭等改变能跳跃高度,但并不影响jumpPower的值
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGravity(entityId)
comp.GetJumpPower()

# GetLeashHolder

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

    获取实体被使用拴绳牵引时牵引者的ID

  • 参数

  • 返回值

    数据类型
    说明
    str 牵引者ID,调用失败或者没有则返回 -1
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetLeashHolder()

# GetMotion

服务端客户端

# 服务端接口

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    获取生物(含玩家)的瞬时移动方向向量

  • 参数

  • 返回值

    数据类型
    说明
    tuple(float,float,float) 瞬时移动方向向量,异常时返回None
  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
motionComp.GetMotion()

# 客户端接口

method in mod.client.component.actorMotionCompClient.ActorMotionComponentClient

  • 描述

    获取生物的瞬时移动方向向量。与服务端不同,客户端不会计算摩擦等因素,获取到的是上一帧的向量,与服务器获取到的值会不相等

  • 参数

  • 返回值

    数据类型
    说明
    tuple(float,float,float) 瞬时移动方向向量,异常时返回None
  • 示例

import mod.client.extraClientApi as clientApi
motionComp = clientApi.GetEngineCompFactory().CreateActorMotion(entityId)
motionComp.GetMotion()

# GetOwnerId

服务端客户端

# 服务端接口

method in mod.server.component.tameCompServer.TameComponentServer

  • 描述

    获取驯服生物的主人id

  • 参数

  • 返回值

    数据类型
    说明
    str 主人id,不存在时返回None
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateTame(entityId)
oid = comp.GetOwnerId()

# 客户端接口

method in mod.client.component.tameCompClient.TameComponentClient

  • 描述

    获取驯服生物的主人id

  • 参数

  • 返回值

    数据类型
    说明
    str 主人id,不存在时返回None
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateTame(entityId)
oid = comp.GetOwnerId()

# GetRiders

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    获取坐骑上的骑乘者信息

  • 参数

  • 返回值

    数据类型
    说明
    list(str) 骑乘者信息,包括骑乘者的entityId,其在骑乘者列表中的序号riderIndex以及所坐的座位序号seatIndex
  • 备注

    • 通常需要配合SetEntityRide、SetControl一起使用,需要被骑乘生物json中骑乘组件支持骑乘者的生物类型。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
riders = comp.GetRiders()

# GetStepHeight

服务端

method in mod.server.component.attrCompServer.AttrCompServer

  • 描述

    返回玩家前进非跳跃状态下能上的最大台阶高度

  • 参数

  • 返回值

    数据类型
    说明
    float 台阶高度
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
print(comp.GetStepHeight())

# Hurt

服务端

method in mod.server.component.hurtCompServer.HurtCompServer

  • 描述

    设置实体伤害

  • 参数

    参数名
    数据类型
    说明
    damage int 伤害值
    cause str 伤害来源,详见Minecraft枚举值文档的ActorDamageCause枚举
    attackerId str 伤害来源的实体id,默认为None
    childAttackerId str 伤害来源的子实体id,默认为None,比如玩家使用抛射物对实体造成伤害,该值应为抛射物Id
    knocked bool 实体是否被击退,默认值为True
    customTag str 标识自定义伤害来源,只在cause为Custom生效,可在ActorHurtServerEvent、ActuallyHurtServerEvent、DamageEvent、PlayerHurtEvent、PlayerDieEvent、MobDieEvent监听到标识
  • 返回值

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

    • 当knocked设为True时,必须同时设置伤害源attackerId,knocked才会生效,击退方向根据攻击源与实体的位置计算。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateHurt(playerId)
comp.Hurt(10, serverApi.GetMinecraftEnum().ActorDamageCause.EntityAttack, attackerId, None, False)

# ImmuneDamage

服务端

method in mod.server.component.hurtCompServer.HurtCompServer

  • 描述

    设置实体是否免疫伤害(该属性存档)

  • 参数

    参数名
    数据类型
    说明
    immune bool 是否免疫伤害
  • 返回值

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

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateHurt(entityId)
comp.ImmuneDamage(True)

# IsEating

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

    判断非玩家实体是否在进食

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否在进食
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsEating()

# IsEntityOnFire

服务端

method in mod.server.component.attrCompServer.AttrCompServer

  • 描述

    获取实体是否着火

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否着火
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
isOnFire = comp.IsEntityOnFire()

# IsLootDropped

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

    获取生物是否生成掉落物

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否能生成战利品
  • 备注

    • 仅在开启战利品生成效果下生效
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsLootDropped()

# IsPersistent

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

    判断是否为持久性生物

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否为持久性生物
  • 备注

    • 当前几乎所有自然生成的生物在模拟距离为4时都会在距离玩家44格或更远时被清除。模拟距离为6或更高时,生物会在模拟距离边界处(距最近的玩家至多128格)被清除。
    • 所有鱼都会在距离玩家至少40格时被清除,无论模拟距离为何。
    • 如果生物在距最近的玩家32至44格处,其必须在30秒内没有受伤,然后就会有八百分之一的概率被清除。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsPersistent()

# IsRoaring

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

    判断是否处于咆哮状态,截止至网易2.9版本,仅对劫掠兽有效

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否处于咆哮状态
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsRoaring()

# IsStunned

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

    判断是否处于眩晕状态,截止至网易2.9版本,仅对劫掠兽有效

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否处于眩晕状态
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsStunned()

# RemoveActorComponentGroup

服务端

method in mod.server.component.entityEventCompServer.EntityEventComponentServer

  • 描述

    移除指定实体在实体json中配置的ComponentGroup

  • 参数

    参数名
    数据类型
    说明
    groupName str 实体行为包中定义的component_group的键名
  • 返回值

    数据类型
    说明
    bool 指令是否成功发出
  • 备注

    • 该接口不会判断生物的json是否具有传入的groupName,返回值的结果只代表指令是否正常发出
    • 在羊的entity json文件中component_groups字段下配置羊的大小:
      "component_groups": {
          "minecraft:sheep_baby": {
              "minecraft:is_baby": {
              },
              "minecraft:scale": {
                  "value": 0.5
              },
              "minecraft:ageable": {
                  "duration": 1200,
                  "feed_items": "wheat",
                  "grow_up": {
                      "event": "minecraft:ageable_grow_up",
                      "target": "self"
                  }
              },
              "minecraft:behavior.follow_parent": {
                  "priority": 6,
                  "speed_multiplier": 1.1
              }
          },
          "minecraft:sheep_adult": {
              "minecraft:experience_reward": {
                  "on_bred": "Math.Random(1,7)",
                  "on_death": "query.last_hit_by_player ? Math.Random(1,3) : 0"
              },
              "minecraft:behavior.breed": {
                  "priority": 3,
                  "speed_multiplier": 1.0
              },
              "minecraft:breedable": {
                  "require_tame": false,
                  "breeds_with": {
                      "mate_type": "minecraft:sheep",
                      "baby_type": "minecraft:sheep"
                  },
                  "breed_items": "wheat"
              }
          }
      }
      
  • 示例

#移除小羊group,添加大羊group
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityEvent(entityId)
comp.RemoveActorComponentGroup("minecraft:sheep_baby")
comp.AddActorComponentGroup("minecraft:sheep_adult")

# RemoveEntityMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    移除实体(不含玩家)身上的运动器

  • 参数

    参数名
    数据类型
    说明
    motionId int 要移除的某个运动器的ID
  • 返回值

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

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
motionComp.RemoveEntityMotion(mID)

# ResetAttackTarget

服务端

method in mod.server.component.actionCompServer.ActionCompServer

  • 描述

    清除仇恨目标

  • 参数

  • 返回值

    数据类型
    说明
    bool 设置结果
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAction(entityId)
comp.ResetAttackTarget()

# ResetMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    重置生物(不含玩家)的瞬时移动方向向量

  • 参数

  • 返回值

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

    • 该接口只能重置SetMotion所设置的瞬时移动方向向量,无法影响由生物本身的AI所产生的运动。
  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
motionComp.ResetMotion()

# ResetStepHeight

服务端

method in mod.server.component.attrCompServer.AttrCompServer

  • 描述

    恢复引擎默认玩家前进非跳跃状态下能上的最大台阶高度

  • 参数

  • 返回值

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

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.ResetStepHeight()

# SetActorCollidable

服务端

method in mod.server.component.actorCollidableCompServer.ActorCollidableCompServer

  • 描述

    设置实体是否可碰撞

  • 参数

    参数名
    数据类型
    说明
    isCollidable int 0:可碰撞 1:不可碰撞
  • 返回值

    数据类型
    说明
    bool True表示设置成功
  • 备注

    • 碰撞是指生物碰撞盒重叠
    • 参数isCollidable是由bool控制的所以传入其它非0的int时等同于传入1
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateActorCollidable(entityId)
success = comp.SetActorCollidable(1)

# SetActorPushable

服务端

method in mod.server.component.actorPushableCompServer.ActorPushableCompServer

  • 描述

    设置实体是否可推动

  • 参数

    参数名
    数据类型
    说明
    isPushable int 0:不可推动 1:可推动
  • 返回值

    数据类型
    说明
    bool True表示设置成功
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateActorPushable(entityId)
success = comp.SetActorPushable(1)

# SetAttackTarget

服务端

method in mod.server.component.actionCompServer.ActionCompServer

  • 描述

    设置仇恨目标

  • 参数

    参数名
    数据类型
    说明
    targetId str 目标实体id
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAction(entityId)
comp.SetAttackTarget(targetId)

# SetBlockControlAi

服务端

method in mod.server.component.controlAiCompServer.ControlAiCompServer

  • 描述

    设置屏蔽生物原生AI

  • 参数

    参数名
    数据类型
    说明
    isBlock bool 是否保留AI,False为屏蔽
    freezeAnim bool 屏蔽AI时是否冻结动作,默认为False,仅当isBlock为False时生效。重进世界会恢复成初始动作
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 屏蔽AI后的生物无法行动,不受重力且不会被推动,但是可以受到伤害,也可以被玩家交互(例如马被骑或村民被交易)
    • 对玩家无效
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateControlAi(entityId)
comp.SetBlockControlAi(False, True)

# SetCanOtherPlayerRide

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    设置其他玩家是否有权限骑乘,True表示每个玩家都能骑乘,False只有驯服者才能骑乘

  • 参数

    参数名
    数据类型
    说明
    tamedEntityId str 可骑乘生物id
    canRide bool 是否控制
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 示例

# 驯服生物
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.SetCanOtherPlayerRide(entityId,False)

# SetControl

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    设置该生物无需装备鞍就可以控制行走跳跃

  • 参数

    参数名
    数据类型
    说明
    tamedEntityId str 可骑乘生物id
    isControl bool 是否控制
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 该接口仅对已被驯服的可骑乘生物生效。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.SetControl(entityId,True)

# SetEntityInteractFilter

服务端

method in mod.server.component.interactCompServer.InteractComponentServer

  • 描述

    设置与生物可交互的条件

  • 参数

    参数名
    数据类型
    说明
    index int 交互列表下标
    interactFilter str 可交互的条件
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 该接口修改minecraft:interact->on_interact中的filters的定义
    • 仅当生物存在minecraft:interact组件时才能调用该接口,例如牛、羊驼、猪灵等
  • 示例

import mod.server.extraServerApi as serverApi
import json
comp = serverApi.GetEngineCompFactory().CreateInteract(entityId)
filterDict = {
    "filters": {
        "all_of": [
            { "test": "is_family", "subject" : "other", "value" :  "player"},
            { "test": "has_equipment", "domain": "hand", "subject": "other", "value": "bucket:0"}
        ]
    }
}
filterStr = json.dumps(filterDict)
comp.SetEntityInteractFilter(0, filterStr)

# SetEntityLockRider

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    设置坐骑上的实体是否锁定序号

  • 参数

    参数名
    数据类型
    说明
    isLock bool 是否锁定实体当前所处的序号
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 通常需要配合SetEntityRide、SetControl一起使用,需要被骑乘生物json中骑乘组件支持骑乘者的生物类型。
    • 锁定以后,该坐骑上某个实体停止骑乘后不会改变坐骑上其他实体当前所处的座位。
    • 解除锁定后,不会立刻改变坐骑上骑乘者的位置。
  • 示例

# 锁定骑乘者序号
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.SetEntityLockRider(True)

# SetEntityOnFire

服务端

method in mod.server.component.attrCompServer.AttrCompServer

  • 描述

    设置实体着火

  • 参数

    参数名
    数据类型
    说明
    seconds int 着火时间(单位:秒)
    burn_damage int 着火状态下每秒扣的血量,不传的话默认是1
  • 返回值

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

    • 在水中或者雨中不会生效,着火时间受生物装备、生物的状态影响。burn_damage取值范围是0~1000,小于0将取0,大于1000将取1000
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.SetEntityOnFire(1, 2)

# SetEntityRide

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    驯服可骑乘生物

  • 参数

    参数名
    数据类型
    说明
    playerId str 玩家id
    tamedEntityId str 要驯服的可骑乘生物id
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 驯服信息会被存盘
  • 示例

# 驯服生物
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.SetEntityRide(playerId,entityId)

# SetEntitySeat

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    设置坐骑座位的位置、旋转以及允许实体旋转范围

  • 参数

    参数名
    数据类型
    说明
    seatIndex int 座位序号,范围为0~最大座位序号
    pos tuple(float,float,float) 座位位置
    rot float 座位旋转,默认为0
    lock_rot float 骑乘者允许旋转角度范围,默认不限制
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 通常需要配合SetEntityRide、SetControl一起使用,需要被骑乘生物json中骑乘组件支持骑乘者的生物类型。
    • 只能修改通过接口AddEntitySeat添加的座位。
    • 非玩家实体即使所处座位的lock_rot参数为默认值,也不可360度旋转。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.SetEntitySeat(0, (1.0, 1.0, 1.0), 90.0, 90.0)

# SetEntityShareablesItems

服务端

method in mod.server.component.shareableCompServer.ShareableComponentServer

  • 描述

    设置生物可分享/可拾取的物品列表

  • 参数

    参数名
    数据类型
    说明
    items list(dict) 可分享/可拾取的物品列表
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 该接口修改minecraft:shareables的items定义
    • 仅当生物存在minecraft:shareables组件时才能调用该接口,例如狐狸、尸壳、猪灵等。若admire为True,则生物还需要有minecraft:admire_item组件。若barter为True,则生物还需有minecraft:behavior.barter行为。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateShareables(entityId)
shareableItems = []
shareableItems.append({
    "item": "minecraft:golden_sword",
    "auxValue": 0,
    "priority": 1,
    "pickupLimit": 1,
    "barter": True,
    "admire": True,
})
comp.SetEntityShareablesItems(shareableItems)

# SetEntityTamed

服务端

method in mod.server.component.tameCompServer.TameComponentServer

  • 描述

    设置生物驯服,需要配合 entityEvent组件使用。该类驯服不包含骑乘功能。

  • 参数

    参数名
    数据类型
    说明
    playerId str 驯服玩家Id
    tamedId str 被驯服的生物Id
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 驯服一个生物,需要按以下步骤:
      1. 搭配修改生物json文件,使其能够被驯服:
      - 添加minecraft:tameable组件
      - 添加一个component group,包含minecraft:is_tamed组件,以及其他驯服后的行为
      - 添加一个event,添加刚刚添加的component group,并移除不需要的component group
      
      1. 使用SetEntityTamed使目标生物被驯服
      2. 使用TriggerCustomEvent触发驯服event 如果是对原版可驯服生物使用,则无需按照第一步修改json,而是找到已有的event,在第三步中触发即可
    • 如修改苦力怕可被驯服,json做如下修改:
      {
          "format_version": "1.8.0",
          "minecraft:entity": {
          "description": {
            "identifier": "minecraft:creeper",
            "is_spawnable": true,
            "is_summonable": true,
            "is_experimental": false
          },
          "component_groups": {
              ...
              //增加驯服状态
              "netease:creeper_tame":{
                "minecraft:is_tamed": {
                },
                //跟随主人
                "minecraft:behavior.follow_owner": {
                  "priority": 4,  //优先级要高于其他移动行为
                  "speed_multiplier": 1.0,
                  "start_distance": 10,
                  "stop_distance": 2
                }
              }
            },
      
            "components": {
              ...
              //增加驯服组件,使用骨头驯服
              "minecraft:tameable": {
                "probability": 0.33,
                "tameItems": "bone",
                "tame_event": {
                  "event": "netease:on_tame",
                  "target": "self"
                }
              }
            },
      
            "events": {
              ...
              //增加驯服事件
              "netease:on_tame": {
                //移除掉所有跟爆炸有关的逻辑
                "remove": {
                  "component_groups": [
                    "minecraft:exploding",
                    "minecraft:charged_exploding",
                    "minecraft:forced_exploding",
                    "minecraft:forced_charged_exploding",
                    "minecraft:charged_creeper"
                  ]
                },
                //添加netease:creeper_tame
                "add": {
                  "component_groups": [
                    "netease:creeper_tame"
                  ]
                }
              }
            }
          }
      }
      
  • 示例

import mod.server.extraServerApi as serverApi
# 使tamedId被playerId驯服
tameComp = serverApi.GetEngineCompFactory().CreateTame(tamedId)
tameComp.SetEntityTamed(playerId,tamedId)
# 触发tamedId的netease:on_tame自定义event
envComp = serverApi.GetEngineCompFactory().CreateEntityEvent(tamedId)
envComp.TriggerCustomEvent(tamedId,'netease:on_tame')

# SetJumpPower

服务端

method in mod.server.component.gravityCompServer.GravityComponentServer

  • 描述

    设置生物跳跃力度,0.42表示正常水平

  • 参数

    参数名
    数据类型
    说明
    jumpPower float 跳跃力度,正常是0.42
  • 返回值

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

    • 生物跳跃力度影响生物跳跃高度;本接口调用时需要客户端加载完成,如在AddServerPlayer中,客户端还没加载完成,要延后执行才能生效
    • 兔子跳跃高度是内置的,无法通过SetJumpPower设置跳跃力度。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGravity(entityId)
comp.SetJumpPower(0.84)

# SetLeashHolder

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

    为实体添加牵引者,与原版拴绳的作用相同,详见基岩版栓绳介绍

  • 参数

    参数名
    数据类型
    说明
    holderId str 牵引者Id
  • 返回值

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

    • 如果牵引者和被牵者距离太远将会瞬间断开
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetLeashHolder(playerId)

# SetLootDropped

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

    设置生物是否生成掉落物

  • 参数

    参数名
    数据类型
    说明
    isLootDropped bool 设置生物是否生成掉落物
  • 返回值

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

    • 仅在开启战利品生成效果下生效,对玩家不生效,玩家可在设置界面设置死亡不掉
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetLootDropped(True)

# SetMobKnockback

服务端

method in mod.server.component.actionCompServer.ActionCompServer

  • 描述

    设置击退的初始速度,需要考虑阻力的影响

  • 参数

    参数名
    数据类型
    说明
    xd float x轴方向,用來控制角度
    zd float z轴方向,用來控制角度
    power float 用来控制水平方向的初速度
    height float 竖直方向的初速度
    heightCap float 向上速度阈值,当实体本身已经有向上的速度时需要考虑这个值,用来确保最终向上的速度不会超过heightCap
  • 返回值

    数据类型
    说明
    None 无返回值
  • 备注

    • 在damageEvent事件里面使用该接口时,需把damageEvent事件回调的knock参数设置为False
    • 该接口会触发OnKnockBackServerEvent事件,所以当需要在该事件中使用时,请编写逻辑避免循环调用
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAction(entityId)
comp.SetMobKnockback(0.1, 0.1, 1.0, 1.0, 1.0)

# SetMotion

服务端客户端

# 服务端接口

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    设置生物(不含玩家)的瞬时移动方向向量

  • 参数

    参数名
    数据类型
    说明
    motion tuple(float,float,float) 世界坐标系下的向量,该方向为世界坐标系下的向量,以x,z,y三个轴的正方向为正值,可以通过当前生物的rot组件判断目前玩家面向的方向,可在开发模式下打开F3观察数值变化。
  • 返回值

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

    • 在damageEvent事件里面使用该接口时,需把damageEvent事件回调的knock参数设置为False
  • 示例

import mod.server.extraServerApi as serverApi
# 使生物向准星的方向突进一段距离
rotComp = serverApi.GetEngineCompFactory().CreateRot(entityId)
rot = rotComp.GetRot()
x, y, z = serverApi.GetDirFromRot(rot)
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
motionComp.SetMotion((x * 5, y * 5, z * 5))
# rot 和 世界坐标系关系
#               ^ x -90°
#               |
# 180°/-180  ----------> z 0°
#               | 90°

# 客户端接口

method in mod.client.component.actorMotionCompClient.ActorMotionComponentClient

  • 描述

    设置瞬时的移动方向向量,用于本地玩家

  • 参数

    参数名
    数据类型
    说明
    motion tuple(float,float,float) 世界坐标系下的向量,该方向为世界坐标系下的向量,以x,z,y三个轴的正方向为正值,可以通过当前玩家的rot组件判断目前玩家面向的方向,可在开发模式下打开F3观察数值变化。
  • 返回值

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

    • 如果频繁快速修改本地玩家的瞬时移动向量,可能会触发引擎服务端的反作弊机制(例如掉落伤害),需要频繁快速修改时最好搭配服务端SetMotion同步修改
  • 示例

import mod.client.extraClientApi as clientApi
# 使玩家向准星的方向突进一段距离
localPlayerId = clientApi.GetLocalPlayerId()
rotComp = clientApi.GetEngineCompFactory().CreateRot(localPlayerId)
rot = rotComp.GetRot()
x, y, z = clientApi.GetDirFromRot(rot)
motionComp = clientApi.GetEngineCompFactory().CreateActorMotion(localPlayerId)
motionComp.SetMotion((x * 5, y * 5, z * 5))
# rot 和 世界坐标系关系
#               ^ x -90°
#               |
# 180°/-180  ----------> z 0°
#               | 90°

# SetMoveSetting

服务端

method in mod.server.component.moveToCompServer.MoveToComponentServer

  • 描述

    寻路组件

  • 参数

    参数名
    数据类型
    说明
    pos tuple(float,float,float) 寻路目标位置
    speed float 移动速度,指正常移动速度的倍率。如1.0表示正常速度,2.0表示两倍速
    maxIteration int 寻路算法最大迭代次数 默认200
    callback function 寻路结束回调函数
  • 返回值

  • 备注

    • 使用该接口时,需要在生物中配置有寻路的json组件。配置寻路json组件后,该接口会自动选择相应类型的寻路 目前支持的寻路json组件包括:
      • minecraft:navigation.walk 陆地寻路,与原版僵尸的寻路相同
      • minecraft:navigation.generic 水陆寻路,支持陆地与水中,与原版溺尸的寻路相同
      • minecraft:navigation.climb 陆地寻路,但是支持爬墙,与原版蜘蛛的寻路相同。这种寻路可能会被头顶方块阻挡,一直无法抵达目的地
      • minecraft:navigation.fly 空中寻路,与原版鹦鹉的寻路相同 以上的寻路都需要搭配一些其他json组件(例如movement)使用,具体可以参考NavigationMod的示例 上面没有提到的navigation类型暂不支持,例如minecraft:navigation.float(如原版恶魂),minecraft:navigation.hover(如原版蜜蜂)
    • 不同的生物拥有不同的默认最大跟随距离,若要寻路的目标点距离大于此值引擎会拒绝寻路,要修改该距离可以通过在entity的json中配置.
      {
        "format_version": "1.8.0",
        "minecraft:entity": {
            "components": {
                "minecraft:follow_range": {
                  "value": 48,
                  "max": 48
                }
            }
        }
      }
      
    • 关于maxIteration参数 该参数会影响实际寻到路径的长度。若寻路算法迭代一定次数后,未寻到目标点,会返回局部最优解,即生物只会走到半路。 在无大型障碍物的情况下,参数对应的参考寻路距离如下:该参数默认值200,最大值2000,请开发者根据实际情况选择。
      maxIteration 与目标点直线距离
      200 13
      500 20
      1000 30
      2000 43
    • 关于callback函数 该函数需要接受两个参数,第一个参数为寻路的entityId,类型str,第二个参数为寻路结果,类型int (玩家获取到的位置比地面会高1.62格,若以玩家位置为目标点需要先把y轴减去1.62,否则callback会一直返回1)
      结果 说明
      -3 寻路失败,大于跟随距离,或者生物周围没有可行走位置,或者对正在寻路的飞行系生物使用
      -2 寻路失败,生物没有寻路组件(指minecraft:navigation)
      -1 寻路失败,参数错误,或生物不存在
      0 寻路完成。到达设定的目标点
      1 寻路完成,但未到达目标点(可能由于maxIteration参数偏小)
      2 寻路中断。中途遇到障碍物被阻碍
      3 寻路中断。被生物原版寻路行为覆盖,或寻路未结束时重复调用moveTo组件。
      若生物的移速太低(真实速度小于0.3格每秒),也会被当成寻路被卡住,返回该错误码
    • 对于各种类型寻路的生物,还需要满足以下初始条件:
      1. 陆地寻路,水陆寻路与爬墙寻路:需要满足以下任一条件:
        • 生物着地
        • 生物正在骑乘,并且骑乘物着地
        • 生物在液体中
        • 生物是凋零
      2. 飞行寻路:需要满足以下任一条件:
        • 不在骑乘状态
        • 在液体中
        • 生物着地
        • json配置中的can_path_from_air属性为true
    • demo简介: 聊天栏输入walk/generic/climb/fly会原地生成一个使用对应navigation json组件的生物,然后跑到其他位置,再输入go,会将刚才生成的生物导航到玩家当前位置。 这4种示例生物的行为json可以在NavigationMod_behavior/entities目录查看。 4种示例生物的最大寻路距离都设置为了48格。
  • 示例

from mod_log import logger as logger
def myCallback(entityId, result):
    if result in (-1,-2,-3):
        logger.info('[error] [SetMoveSetting] failed')
    elif result==0:
        logger.info('[info] [SetMoveSetting] success')
    elif result in (1,2,3):
        logger.info('[warn] [SetMoveSetting] terminated')

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateMoveTo(entityId)
comp.SetMoveSetting((x,y,z),2.0,200,myCallback)

# SetPersistence

服务端

method in mod.server.component.persistenceCompServer.PersistenceCompServer

  • 描述

    设置实体是否持久化。

  • 参数

    参数名
    数据类型
    说明
    isPersistent bool True为设置实体持久化,False为设置实体不持久化。
  • 返回值

  • 备注

    • 游戏中,实体默认持久化,若设置不持久化,则实体会在区块卸载和退出存档时被删除,不会存档。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePersistence(entityId)
comp.SetPersistence(True)

# SetRidePos

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    设置生物骑乘位置

  • 参数

    参数名
    数据类型
    说明
    tamedEntityId str 可骑乘生物id
    pos tuple(float,float,float) 骑乘时挂接点
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.SetRidePos(entityId,(1,1,1))

# SetRiderRideEntity

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    设置实体骑乘生物(或者船与矿车)

  • 参数

    参数名
    数据类型
    说明
    riderId str 骑乘生物id
    riddenEntityId str 被骑乘生物id。要求被骑乘生物的定义中具有minecraft:rideable组件,且组件中family_types含有可骑乘者的类型声明
    riderIndex int 指定实体成为第n个骑乘者,范围为0~SeatCount-1,默认不指定
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 通常需要配合SetEntityRide、SetControl一起使用,需要被骑乘生物json中骑乘组件支持骑乘者的生物类型 当被控制的entity有多个位置时且开发者想要添加多个玩家时,第一个被添加的玩家会被引擎默认设置为控制者(riderIndex参数为默认值时)。
    • 当控制位为空,实体设置到控制位时,无论后座是否还有玩家,实体仍为控制者。
    • 未通过SetEntityLockRider锁定的实体,退出存档重进或有新的骑乘者时会遵循原版逻辑重置实体上的骑乘者。
  • 示例

# 骑上坐骑
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.SetRiderRideEntity(playerId,rideEntityId)

# SetStepHeight

服务端

method in mod.server.component.attrCompServer.AttrCompServer

  • 描述

    设置玩家前进非跳跃状态下能上的最大台阶高度, 默认值为0.5625,1的话表示能上一个台阶

  • 参数

    参数名
    数据类型
    说明
    stepHeight float 最大高度,需要大于0
  • 返回值

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

    • 为了避免因浮点数误差导致错误,设置的时候通常会增加1/16个方块大小,即0.0625。所以此处我们设置2.0625。游戏中默认值是0.5625,即半格高度。
    • 只对玩家生效,无法修改其它实体该属性
    • 修改后不影响跳跃逻辑及跳跃高度,并不会因此而跳到更高,因此在某些特定情况下,你可以走上方块但跳不上去。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
#如果前面放置有两格高的方块,玩家按前进能直接上去,无须跳跃
comp.SetStepHeight(2.0625)

# StartEntityMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    启动实体(不含玩家)身上的某个运动器

  • 参数

    参数名
    数据类型
    说明
    motionId int 要启动的某个运动器的ID
  • 返回值

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

    • 运动器控制的实体会无视原生的碰撞逻辑而穿透方块,若需停止,请自行监听碰撞事件OnMobHitBlockServerEvent然后使用StopEntityMotion停止
  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
motionComp.StartEntityMotion(mID)

# StopEntityMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    停止实体(不含玩家)身上的某个运动器

  • 参数

    参数名
    数据类型
    说明
    motionId int 要停止的某个运动器的ID
  • 返回值

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

  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
motionComp.StopEntityMotion(mID)

# TriggerCustomEvent

服务端

method in mod.server.component.entityEventCompServer.EntityEventComponentServer

  • 描述

    触发生物自定义事件

  • 参数

    参数名
    数据类型
    说明
    entityId str 生物Id
    eventName str 事件名称
  • 返回值

    数据类型
    说明
    bool 设置结果
  • 备注

    • 触发苦力怕爆炸 在苦力怕的entity json文件中events字段下增加如下事件,然后在mod中运行示例代码:
      "netease:custom_exploading":{
                "sequence": [
                  {
                    "filters": {
                  "test": "has_component",
                      "operator": "!=",
                      "value": "minecraft:is_charged"
                    },
                    "add": {
                      "component_groups": [
                        "minecraft:forced_exploding"
                      ]
                    }
                  },
                  {
                    "filters": {
                      "test": "has_component",
                      "value": "minecraft:is_charged"
                    },
                    "add": {
                      "component_groups": [
                        "minecraft:forced_charged_exploding"
                      ]
                    }
                  }
                ]
              }
      
    • 触发事件所添加或移除的component_groups,会在下一帧才真正生效。
  • 示例

import mod.server.extraServerApi as serverApi
#触发entity自定义event
eventName = "netease:custom_exploading"
comp = serverApi.GetEngineCompFactory().CreateEntityEvent(entityId)
comp.TriggerCustomEvent(entityId,eventName)

AddActorComponentGroup

AddEntityAroundEntityMotion

AddEntityAroundPointMotion

AddEntitySeat

AddEntityTrackMotion

AddEntityVelocityMotion

ChangeRiderSeat

DeleteEntitySeat

GetAttackTarget

服务端接口

客户端接口

GetBlockControlAi

GetCustomGoalCls

GetEntityMotions

GetJumpPower

GetLeashHolder

GetMotion

服务端接口

客户端接口

GetOwnerId

服务端接口

客户端接口

GetRiders

GetStepHeight

Hurt

ImmuneDamage

IsEating

IsEntityOnFire

IsLootDropped

IsPersistent

IsRoaring

IsStunned

RemoveActorComponentGroup

RemoveEntityMotion

ResetAttackTarget

ResetMotion

ResetStepHeight

SetActorCollidable

SetActorPushable

SetAttackTarget

SetBlockControlAi

SetCanOtherPlayerRide

SetControl

SetEntityInteractFilter

SetEntityLockRider

SetEntityOnFire

SetEntityRide

SetEntitySeat

SetEntityShareablesItems

SetEntityTamed

SetJumpPower

SetLeashHolder

SetLootDropped

SetMobKnockback

SetMotion

服务端接口

客户端接口

SetMoveSetting

SetPersistence

SetRidePos

SetRiderRideEntity

SetStepHeight

StartEntityMotion

StopEntityMotion

TriggerCustomEvent