Skip to content

行为 ​

AddActorComponent ​

服务端实体组件 组件添加 行为配置开发补充

为指定实体添加行为定义组件。

服务端

method in mod.server.component.entityEventCompServer.EntityEventComponentServer

  • 描述

给指定实体自定义添加实体Component

  • 参数
参数名数据类型说明
componentNamestr实体行为包中定义的component的键名
componentValuestr实体行为包中定义的component的值的json
  • 返回值
数据类型说明
bool指令是否成功发出
  • 备注

  • 该接口不会判断生物的json是否具有传入的Component,返回值的结果只代表指令是否正常发出

  • 重复添加component,会覆盖原有的值(包括AddActorComponentGroup)

  • AddActorComponent、AddActorComponentGroup、RemoveActorComponent、RemoveActorComponentGroup之间会互相影响,结果依据执行顺序而定

  • 示例

python
#将实体攻击改成99
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityEvent(entityId)
comp.AddActorComponent("minecraft:attack", '{"damage": 99}')

AddActorComponentGroup ​

服务端实体组件 组件群添加 行为配置开发补充

为实体添加资源定义中配置的组件群。

服务端

method in mod.server.component.entityEventCompServer.EntityEventComponentServer

  • 描述

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

  • 参数
参数名数据类型说明
groupNamestr实体行为包中定义的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
        }
    }
}
  • 示例
python
#将羊变为红色
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

  • 描述

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

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

  • 该接口不屏蔽生物本身的AI运动以及重力作用,当有AI运动发生时,最终的表现结果可能与预期有差异。

  • 环绕运动器可叠加多个,且可与速度运动器互相叠加,每一帧的最终效果为各个运动器计算出的瞬时向量之和。

  • 由于引擎中在加载的区块以外的实体时会停止一切活动,建议将实体的运动范围控制在玩家位置±100内。

  • 参数中环绕半径radius和角速度angularVelocity需要配合调整,避免最后得出的线速度过大造成运动不平滑。

  • 示例

python
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)
#启动该运动器
motionComp.StartEntityMotion(mID)

AddEntityAroundPointMotion ​

服务端实体运动 定点环绕 运动器创建开发补充

为非玩家实体添加环绕固定位置的运动器。

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

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

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

  • 该接口不屏蔽生物本身的AI运动以及重力作用,当有AI运动发生时,最终的表现结果可能与预期有差异。

  • 环绕运动器可叠加多个,且可与速度运动器互相叠加,每一帧的最终效果为各个运动器计算出的瞬时向量之和。

  • 由于引擎中在加载的区块以外的实体时会停止一切活动,建议将实体的运动范围控制在玩家位置±100内,同时避免线速度过大造成运动不平滑的现象。

  • 示例

python
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)
#启动该运动器
motionComp.StartEntityMotion(mID)

AddEntitySeat ​

服务端实体骑乘 座位添加 座位配置开发补充

为坐骑增加座位。

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

增加坐骑座位

  • 参数
参数名数据类型说明
postuple(float,float,float)座位位置
rotfloat座位旋转,默认为0
lock_rotfloat骑乘者允许旋转角度范围,默认不限制
  • 返回值
数据类型说明
int当前最大座位序号,增加失败返回-1
  • 备注

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

  • 非玩家实体即使所处座位的lock_rot参数为默认值,也不可360度旋转。

  • 示例

python
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

  • 描述

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

  • 参数
参数名数据类型说明
targetPostuple(float,float,float)轨迹终点
duraTimefloat到达终点所需要的时间
startPostuple(float,float,float)轨迹起点,默认为None,表示以调用StartEntityMotion的位置作为起点。
relativeCoordbool是否使用相对坐标设置起点和终点的位置以及朝向,默认为False。
isLoopbool是否循环,若设为True,则实体会在起点和终点之间往复运动,默认为False。
targetRottuple(float,float)实体到达targetPos时的朝向,受参数relativeCoord影响,默认为None,表示使用调用StartEntityMotion时的朝向。
startRottuple(float,float)实体到达startPos时的朝向,受参数relativeCoord影响,默认为None,表示使用调用StartEntityMotion时的朝向。
useVelocityDirbool是否使用运动中的速度方向作为朝向,默认为False,若为True,则参数targetRot和startRot无效
easeTimeEaseType时间变化函数, 默认值为serverApi.GetMinecraftEnum().TimeEaseType.linear, 参数不在枚举值中也当作linear
  • 返回值
数据类型说明
int运动器ID,添加失败时返回-1
  • 备注

  • 该接口不屏蔽生物本身的AI运动,并且生物在空中时会受到跌落伤害,当有AI运动发生时,最终的表现结果可能与预期有差异,建议将生物设置为NPC。

  • 轨迹运动器不可叠加,仅能添加一个。

  • 由于引擎中在加载的区块以外的实体时会停止一切活动,建议将运动范围控制在玩家位置±100内。

  • 设置朝向后会根据相应的参数计算出最终朝向,若此时的targetRot > startRot,则会顺时针旋转,反之逆时针旋转。

  • 示例

python
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

  • 描述

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

  • 参数
参数名数据类型说明
velocitytuple(float,float,float)速度,包含大小、方向
acceleratetuple(float,float,float)加速度,包含大小、方向,默认为None,表示没有加速度
useVelocityDirbool是否使用当前速度的方向作为此刻实体的朝向,默认为True
  • 返回值
数据类型说明
int运动器ID,添加失败时返回-1
  • 备注

  • 该接口不屏蔽生物本身的AI运动以及重力作用,当有AI运动发生时,最终的表现结果可能与预期有差异。

  • 速度运动器可叠加多个,且可与环绕运动器互相叠加。

  • 由于引擎中在加载的区块以外的实体时会停止一切活动,建议将实体的运动范围控制在玩家位置±100内。

  • 示例

python
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)
#启动该运动器
motionComp.StartEntityMotion(mID)

ChangeRiderSeat ​

服务端实体骑乘 座位切换 骑乘顺序开发补充

调整骑乘者在当前坐骑上的座位序号。

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

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

  • 参数
参数名数据类型说明
riderIndexint指定实体成为第n个骑乘者,范围为0~SeatCount-1
  • 返回值
数据类型说明
bool设置结果
  • 备注

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

  • 未通过SetEntityLockRider锁定的实体,退出存档重进或有新的骑乘者时会遵循原版逻辑重置实体上的骑乘者。

  • 示例

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

DeleteEntitySeat ​

服务端实体骑乘 座位删除 座位配置开发补充

删除坐骑上的指定座位。

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

删除坐骑座位

  • 参数
参数名数据类型说明
seatIndexint座位序号,范围为0~最大座位序号
  • 返回值
数据类型说明
bool设置结果
  • 备注

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

  • 只能删除通过接口AddEntitySeat添加的座位。

  • 示例

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

GetAttackTarget ​

服务端仇恨目标 攻击目标 目标读取开发补充

读取生物当前仇恨目标。

关联接口:SetAttackTarget (server)

客户端仇恨目标 攻击目标 目标读取开发补充

读取生物当前仇恨目标。

服务端客户端

服务端接口 ​

method in mod.server.component.actionCompServer.ActionCompServer

  • 描述

获取仇恨目标

  • 参数

无

  • 返回值
数据类型说明
str返回仇恨目标的实体id。如果传入的实体id所对应的实体没有仇恨目标,则返回-1。如果传入的实体id所对应的实体不存在,则返回None。
  • 示例
python
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。
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateAction(entityId)
comp.GetAttackTarget()

GetBlockControlAi ​

服务端生物行为 原生智能 屏蔽状态开发补充

查询生物原生行为是否被屏蔽。

关联接口:SetBlockControlAi (server)

服务端

method in mod.server.component.controlAiCompServer.ControlAiCompServer

  • 描述

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

  • 参数

无

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

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

  • 示例

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

GetComponents ​

服务端实体组件 生效组件 组件枚举开发补充

读取实体当前生效的行为定义组件。

服务端

method in mod.server.component.entityEventCompServer.EntityEventComponentServer

  • 描述

获取指定实体的生效Components

  • 参数

无

  • 返回值
数据类型说明
dict指定实体的生效Components
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityEvent(entityId)
print(comp.GetComponents())

GetCustomGoalCls ​

服务端行为节点 节点基类 自定义行为开发补充

获取自定义行为节点需继承的基类。

服务端

method in mod.server.extraServerApi

  • 描述

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

  • 参数

无

  • 返回值
数据类型说明
type(CustomGoal)服务端自定义行为节点类
  • 示例
python
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:环绕运动器
  • 备注

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

  • 示例

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

GetJumpPower ​

服务端生物跳跃 跳跃力度 参数读取开发补充

读取生物跳跃力度。

关联接口:SetJumpPower (server)

服务端

method in mod.server.component.gravityCompServer.GravityComponentServer

  • 描述

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

  • 参数

无

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

  • 生物跳跃力度影响生物跳跃高度。

  • 由于python浮点数值精度问题,返回的数据字典中的浮点数可能会带有小数点后多位的现象,例如跳跃力度原本为0.2,则返回的的值可能会变为0.20000000298,请注意。

  • 兔子无法在外部通过SetJumpPower设置跳跃力度,因此调用此接口时,获取到的为实际兔子的跳跃力度,而不是SetJumpPower设置的值

  • 使用指令,跳跃药水,跳跃箭等改变能跳跃高度,但并不影响jumpPower的值

  • 示例

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

GetLeashHolder ​

服务端实体牵引 拴绳关系 牵引者查询开发补充

读取通过拴绳牵引实体的对象标识。

关联接口:SetLeashHolder (server)

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

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

  • 参数

无

  • 返回值
数据类型说明
str牵引者ID,调用失败或者没有则返回 -1
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetLeashHolder()

GetMotion ​

服务端实体运动 运动读取 方向向量开发补充

读取生物或玩家的瞬时运动向量;速度大小和方向需根据向量另行计算。

  • 异常返回 None;本接口只读取,不设置速度。

关联接口:SetPlayerMotion (server) · SetMotion (server)

客户端实体运动 运动向量 向量读取开发补充

读取客户端上一帧的运动向量;与服务端包含摩擦计算的值可能不同。

关联接口:SetMotion (client)

服务端客户端

服务端接口 ​

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

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

  • 参数

无

  • 返回值
数据类型说明
tuple(float,float,float)瞬时移动方向向量,异常时返回None
  • 示例
python
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
  • 示例
python
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
  • 示例
python
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
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateTame(entityId)
oid = comp.GetOwnerId()

GetRiders ​

服务端实体骑乘 骑乘者列表 关系查询开发补充

读取坐骑上的骑乘者信息。

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

获取坐骑上的骑乘者信息

  • 参数

无

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

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

  • 示例

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

GetStepHeight ​

服务端玩家移动 台阶高度 参数读取开发补充

读取玩家不跳跃时可跨越的最大台阶高度。

关联接口:SetStepHeight (server)

服务端

method in mod.server.component.attrCompServer.AttrCompServer

  • 描述

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

  • 参数

无

  • 返回值
数据类型说明
float台阶高度
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
print(comp.GetStepHeight())

Hurt ​

服务端实体伤害 伤害来源 击退控制开发补充

能力:伤害 · 伤害来源 · 实体

作用对象:实体

向实体施加指定伤害并设置伤害来源;产生击退时需提供攻击者实体。

关联接口:DamageEvent (server) · MobDieEvent (server) · ActorDamageCause (common)

服务端

method in mod.server.component.hurtCompServer.HurtCompServer

  • 描述

设置实体伤害

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

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

  • 示例

python
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

  • 描述

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

  • 参数
参数名数据类型说明
immunebool是否免疫伤害
  • 返回值
数据类型说明
bool是否设置成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateHurt(entityId)
comp.ImmuneDamage(True)

IsEating ​

服务端生物行为 进食状态 状态查询开发补充

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

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

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

  • 参数

无

  • 返回值
数据类型说明
bool是否在进食
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsEating()

IsEntityOnFire ​

服务端实体着火 燃烧状态 状态查询开发补充

判断实体是否正在燃烧。

服务端

method in mod.server.component.attrCompServer.AttrCompServer

  • 描述

获取实体是否着火

  • 参数

无

  • 返回值
数据类型说明
bool是否着火
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
isOnFire = comp.IsEntityOnFire()

IsLootDropped ​

服务端生物掉落 掉落开关 状态查询开发补充

查询生物是否允许产生掉落物。

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

获取生物是否生成掉落物

  • 参数

无

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

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

  • 示例

python
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秒内没有受伤,然后就会有八百分之一的概率被清除。

  • 示例

python
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是否处于咆哮状态
  • 示例
python
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是否处于眩晕状态
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsStunned()

RemoveActorComponent ​

服务端实体组件 组件移除 行为配置开发补充

从实体移除指定行为定义组件。

服务端

method in mod.server.component.entityEventCompServer.EntityEventComponentServer

  • 描述

删除指定实体的指定Component

  • 参数
参数名数据类型说明
componentNamestr实体行为包中定义的component的键名
  • 返回值
数据类型说明
bool指令是否成功发出
  • 备注

  • 该接口不会判断生物的json是否具有传入的Component,返回值的结果只代表指令是否正常发出

  • AddActorComponent、AddActorComponentGroup、RemoveActorComponent、RemoveActorComponentGroup之间会互相影响,结果依据执行顺序而定

  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityEvent(entityId)
comp.RemoveActorComponent("minecraft:attack")

RemoveActorComponentGroup ​

服务端实体组件 组件群移除 行为配置开发补充

从实体移除资源定义中的指定组件群。

服务端

method in mod.server.component.entityEventCompServer.EntityEventComponentServer

  • 描述

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

  • 参数
参数名数据类型说明
groupNamestr实体行为包中定义的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"
        }
    }
}
  • 示例
python
#移除小羊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

  • 描述

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

  • 参数
参数名数据类型说明
motionIdint要移除的某个运动器的ID
  • 返回值
数据类型说明
bool是否成功移除
  • 示例
python
import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
motionComp.RemoveEntityMotion(mID)

ResetAttackTarget ​

服务端仇恨目标 目标清除 攻击行为开发补充

清除生物当前仇恨目标。

服务端

method in mod.server.component.actionCompServer.ActionCompServer

  • 描述

清除仇恨目标

  • 参数

无

  • 返回值
数据类型说明
bool设置结果
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAction(entityId)
comp.ResetAttackTarget()

ResetMotion ​

服务端实体运动 向量重置 运动控制开发补充

重置非玩家生物的瞬时运动向量。

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

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

  • 参数

无

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

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

  • 示例

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

ResetStepHeight ​

服务端玩家移动 台阶高度 参数重置开发补充

恢复玩家不跳跃跨越台阶高度的引擎默认值。

服务端

method in mod.server.component.attrCompServer.AttrCompServer

  • 描述

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

  • 参数

无

  • 返回值
数据类型说明
bool是否设置成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.ResetStepHeight()

SetActorCollidable ​

服务端实体碰撞 碰撞开关 物理状态开发补充

控制实体是否可以发生碰撞。

服务端

method in mod.server.component.actorCollidableCompServer.ActorCollidableCompServer

  • 描述

设置实体是否可碰撞

  • 参数
参数名数据类型说明
isCollidableint0:可碰撞 1:不可碰撞
  • 返回值
数据类型说明
boolTrue表示设置成功
  • 备注

  • 碰撞是指生物碰撞盒重叠

  • 参数isCollidable是由bool控制的所以传入其它非0的int时等同于传入1

  • 示例

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

SetActorPushable ​

服务端实体碰撞 推动开关 物理状态开发补充

控制实体是否可以被推动。

服务端

method in mod.server.component.actorPushableCompServer.ActorPushableCompServer

  • 描述

设置实体是否可推动

  • 参数
参数名数据类型说明
isPushableint0:不可推动 1:可推动
  • 返回值
数据类型说明
boolTrue表示设置成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateActorPushable(entityId)
success = comp.SetActorPushable(1)

SetAttackTarget ​

服务端仇恨目标 攻击目标 目标设置开发补充

设置生物的仇恨目标。

关联接口:GetAttackTarget (server)

服务端

method in mod.server.component.actionCompServer.ActionCompServer

  • 描述

设置仇恨目标

  • 参数
参数名数据类型说明
targetIdstr目标实体id
  • 返回值
数据类型说明
bool设置结果
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAction(entityId)
comp.SetAttackTarget(targetId)

SetBlockControlAi ​

服务端生物行为 原生智能 行为屏蔽开发补充

控制是否屏蔽生物原生行为。

关联接口:GetBlockControlAi (server)

服务端

method in mod.server.component.controlAiCompServer.ControlAiCompServer

  • 描述

设置屏蔽生物原生AI

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

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

  • 对玩家无效

  • 示例

python
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只有驯服者才能骑乘

  • 参数
参数名数据类型说明
tamedEntityIdstr可骑乘生物id
canRidebool是否控制
  • 返回值
数据类型说明
bool设置结果
  • 示例
python
# 驯服生物
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
comp.SetCanOtherPlayerRide(entityId,False)

SetControl ​

服务端实体骑乘 移动控制 鞍具限制开发补充

允许生物无需装备鞍即可受控行走和跳跃。

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

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

  • 参数
参数名数据类型说明
tamedEntityIdstr可骑乘生物id
isControlbool是否控制
  • 返回值
数据类型说明
bool设置结果
  • 备注

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

  • 示例

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

SetEntityInteractFilter ​

服务端实体交互 交互过滤 条件设置开发补充

设置允许与生物交互的条件。

服务端

method in mod.server.component.interactCompServer.InteractComponentServer

  • 描述

设置与生物可交互的条件

  • 参数
参数名数据类型说明
indexint交互列表下标
interactFilterstr可交互的条件
  • 返回值
数据类型说明
bool设置结果
  • 备注

  • 该接口修改minecraft:interact->on_interact中的filters的定义

  • 仅当生物存在minecraft:interact组件时才能调用该接口,例如牛、羊驼、猪灵等

  • 示例

python
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

  • 描述

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

  • 参数
参数名数据类型说明
isLockbool是否锁定实体当前所处的序号
  • 返回值
数据类型说明
bool设置结果
  • 备注

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

  • 锁定以后,该坐骑上某个实体停止骑乘后不会改变坐骑上其他实体当前所处的座位。

  • 解除锁定后,不会立刻改变坐骑上骑乘者的位置。

  • 示例

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

SetEntityOnFire ​

服务端实体着火 燃烧状态 状态设置开发补充

能力:燃烧 · 实体

设置实体燃烧状态及相关参数。

  • seconds 是整数秒,不是 Bukkit 的游戏 tick;转换时明确取整策略。seconds 小于等于 0 用于灭火。

服务端

method in mod.server.component.attrCompServer.AttrCompServer

  • 描述

设置实体着火

  • 参数
参数名数据类型说明
secondsint着火时间(单位:秒),当传入参数seconds小于等于0时,将让着火的实体灭火
burn_damageint着火状态下每秒扣的血量,不传的话默认是1
  • 返回值
数据类型说明
bool是否设置成功
  • 备注

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

  • 示例

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

SetEntityRide ​

服务端生物驯服 可骑乘生物 主人设置开发补充

能力:实体 · 驯服主人 · 玩家 · 骑乘 · 已驯服生物 · 驯服

作用对象:已驯服生物

适用限定:驯服

为玩家驯服可骑乘生物;驯服信息会存档。

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

驯服可骑乘生物

  • 参数
参数名数据类型说明
playerIdstr玩家id
tamedEntityIdstr要驯服的可骑乘生物id
  • 返回值
数据类型说明
bool设置结果
  • 备注

  • 驯服信息会被存盘

  • 示例

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

SetEntitySeat ​

服务端实体骑乘 座位位置 旋转范围开发补充

设置坐骑座位位置、朝向和允许的旋转范围。

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

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

  • 参数
参数名数据类型说明
seatIndexint座位序号,范围为0~最大座位序号
postuple(float,float,float)座位位置
rotfloat座位旋转,默认为0
lock_rotfloat骑乘者允许旋转角度范围,默认不限制
  • 返回值
数据类型说明
bool设置结果
  • 备注

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

  • 只能修改通过接口AddEntitySeat添加的座位。

  • 非玩家实体即使所处座位的lock_rot参数为默认值,也不可360度旋转。

  • 示例

python
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

  • 描述

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

  • 参数
参数名数据类型说明
itemslist(dict)可分享/可拾取的物品列表
  • 返回值
数据类型说明
bool设置结果
  • 备注

  • 该接口修改minecraft:shareables的items定义

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

  • 示例

python
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组件使用。该类驯服不包含骑乘功能。

  • 参数
参数名数据类型说明
playerIdstr驯服玩家Id
tamedIdstr被驯服的生物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"
            ]
          }
        }
      }
    }
}
  • 示例
python
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 ​

服务端生物跳跃 跳跃力度 参数设置开发补充

设置生物跳跃力度。

关联接口:GetJumpPower (server)

服务端

method in mod.server.component.gravityCompServer.GravityComponentServer

  • 描述

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

  • 参数
参数名数据类型说明
jumpPowerfloat跳跃力度,正常是0.42
  • 返回值
数据类型说明
bool是否设置成功
  • 备注

  • 生物跳跃力度影响生物跳跃高度;本接口调用时需要客户端加载完成,如在AddServerPlayer中,客户端还没加载完成,要延后执行才能生效

  • 兔子跳跃高度是内置的,无法通过SetJumpPower设置跳跃力度。

  • 示例

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

SetLeashHolder ​

服务端实体牵引 拴绳关系 牵引者设置开发补充

为实体设置拴绳牵引者。

关联接口:GetLeashHolder (server)

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

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

  • 参数
参数名数据类型说明
holderIdstr牵引者Id
  • 返回值
数据类型说明
bool是否成功
  • 备注

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

  • 示例

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

SetLootDropped ​

服务端生物掉落 掉落开关 状态设置开发补充

控制生物是否产生掉落物。

服务端

method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer

  • 描述

设置生物是否生成掉落物

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

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

  • 示例

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

SetMobKnockback ​

服务端实体击退 初始速度 运动控制开发补充

能力:实体 · 击退

设置击退初始速度;后续运动仍受阻力影响。

服务端

method in mod.server.component.actionCompServer.ActionCompServer

  • 描述

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

  • 参数
参数名数据类型说明
xdfloatx轴方向,用來控制角度
zdfloatz轴方向,用來控制角度
powerfloat用来控制水平方向的初速度
heightfloat竖直方向的初速度
heightCapfloat向上速度阈值,当实体本身已经有向上的速度时需要考虑这个值,用来确保最终向上的速度不会超过heightCap
  • 返回值
数据类型说明
None无返回值
  • 备注

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

  • 该接口会触发OnKnockBackServerEvent事件,所以当需要在该事件中使用时,请编写逻辑避免循环调用

  • 示例

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

SetMotion ​

服务端实体运动 瞬时运动 方向向量 击退控制开发补充

能力:实体 · 击退 · 非玩家实体 · 运动速度

设置非玩家生物的瞬时运动向量;持续运动需另行控制。

  • 服务端此接口不适用于玩家;在伤害事件中使用需关闭该回调原有击退。

关联接口:DamageEvent (server) · SetRot (server)

客户端玩家运动 瞬时向量 本地控制开发补充

能力:实体 · 击退 · 非玩家实体 · 运动速度

设置本地玩家的瞬时运动向量。

关联接口:GetMotion (client)

服务端客户端

服务端接口 ​

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

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

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

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

  • 示例

python
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

  • 描述

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

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

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

  • 示例

python
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

  • 描述

寻路组件

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

无

  • 备注

  • 使用该接口时,需要在生物中配置有寻路的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与目标点直线距离
20013
50020
100030
200043
  • 关于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. 陆地寻路,水陆寻路与爬墙寻路:需要满足以下任一条件:
  • 生物着地

  • 生物正在骑乘,并且骑乘物着地

  • 生物在液体中

  • 生物是凋零

  1. 飞行寻路:需要满足以下任一条件:
  • 不在骑乘状态

  • 在液体中

  • 生物着地

  • json配置中的can_path_from_air属性为true

  • demo简介: 聊天栏输入walk/generic/climb/fly会原地生成一个使用对应navigation json组件的生物,然后跑到其他位置,再输入go,会将刚才生成的生物导航到玩家当前位置。 这4种示例生物的行为json可以在NavigationMod_behavior/entities目录查看。 4种示例生物的最大寻路距离都设置为了48格。

  • 示例

python
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

  • 描述

设置实体是否持久化。

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

无

  • 备注

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

  • 示例

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

SetRidePos ​

服务端实体骑乘 骑乘位置 位置设置开发补充

设置生物骑乘位置。

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

设置生物骑乘位置

  • 参数
参数名数据类型说明
tamedEntityIdstr可骑乘生物id
postuple(float,float,float)骑乘时挂接点
  • 返回值
数据类型说明
bool设置结果
  • 示例
python
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

  • 描述

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

  • 参数
参数名数据类型说明
riderIdstr骑乘生物id
riddenEntityIdstr被骑乘生物id。要求被骑乘生物的定义中具有minecraft:rideable组件,且组件中family_types含有可骑乘者的类型声明
riderIndexint指定实体成为第n个骑乘者,范围为0~SeatCount-1,默认不指定
  • 返回值
数据类型说明
bool设置结果
  • 备注

  • 通常需要配合SetEntityRide、SetControl一起使用,需要被骑乘生物json中骑乘组件支持骑乘者的生物类型 当被控制的entity有多个位置时且开发者想要添加多个玩家时,第一个被添加的玩家会被引擎默认设置为控制者(riderIndex参数为默认值时)。

  • 当控制位为空,实体设置到控制位时,无论后座是否还有玩家,实体仍为控制者。

  • 未通过SetEntityLockRider锁定的实体,退出存档重进或有新的骑乘者时会遵循原版逻辑重置实体上的骑乘者。

  • 示例

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

SetStepHeight ​

服务端玩家移动 台阶高度 参数设置开发补充

调整玩家不跳跃时可跨越的最大台阶高度。

关联接口:GetStepHeight (server)

服务端

method in mod.server.component.attrCompServer.AttrCompServer

  • 描述

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

  • 参数
参数名数据类型说明
stepHeightfloat最大高度,需要大于0
  • 返回值
数据类型说明
bool是否设置成功
  • 备注

  • 为了避免因浮点数误差导致错误,设置的时候通常会增加1/16个方块大小,即0.0625。所以此处我们设置2.0625。游戏中默认值是0.5625,即半格高度。

  • 只对玩家生效,无法修改其它实体该属性

  • 修改后不影响跳跃逻辑及跳跃高度,并不会因此而跳到更高,因此在某些特定情况下,你可以走上方块但跳不上去。

  • 设置的步长值较大时,可能会存在可以跨到方块顶部,却走不到方块中间空隙的特殊情况。

  • 示例

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

StartEntityMotion ​

服务端实体运动 运动器启动 运动控制开发补充

启动非玩家实体上的指定运动器。

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

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

  • 参数
参数名数据类型说明
motionIdint要启动的某个运动器的ID
  • 返回值
数据类型说明
bool是否成功启动
  • 备注

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

  • 示例

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

StopEntityMotion ​

服务端实体运动 运动器停止 运动控制开发补充

停止非玩家实体上的指定运动器。

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

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

  • 参数
参数名数据类型说明
motionIdint要停止的某个运动器的ID
  • 返回值
数据类型说明
bool是否成功停止
python
import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId)
motionComp.StopEntityMotion(mID)

StopEntityRiding ​

服务端实体骑乘 强制下骑 关系解除开发补充

能力:结束骑乘 · 实体 · 骑乘

作用对象:实体

适用限定:结束骑乘

让骑乘者退出当前坐骑。

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

强制骑乘者下坐骑。

  • 参数

无

  • 返回值
数据类型说明
bool当骑乘者当前正在骑乘并成功下坐骑返回True,否则返回False
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
success = comp.StopEntityRiding()

TriggerCustomEvent ​

服务端实体事件 自定义事件 行为触发开发补充

触发生物资源定义中的自定义事件。

服务端

method in mod.server.component.entityEventCompServer.EntityEventComponentServer

  • 描述

触发生物自定义事件

  • 参数
参数名数据类型说明
entityIdstr生物Id
eventNamestr事件名称
  • 返回值
数据类型说明
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,会在下一帧才真正生效。

  • 示例

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