--- sidebarDepth: 1 --- # 行为 ## 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 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | int | 运动器ID,添加失败时返回-1 | - 备注 - 该接口不屏蔽生物本身的AI运动以及重力作用,当有AI运动发生时,最终的表现结果可能与预期有差异。 - 环绕运动器可叠加多个,且可与速度运动器互相叠加。 - 由于引擎中在加载的区块以外的实体时会停止一切活动,建议将实体的运动范围控制在玩家位置±100内。 - 示例 ```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) ``` ## 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内。 - 示例 ```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) ``` ## AddEntityTrackMotion 服务端 method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer - 描述 给实体(不含玩家)添加轨迹运动器 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | targetPos | tuple(float,float,float) | 轨迹终点 | | duraTime | float | 到达终点所需要的时间 | | startPos | tuple(float,float,float) | 轨迹起点,默认为None,表示以调用[StartEntityMotion](#StartEntityMotion)的位置作为起点。 | | relativeCoord | bool | 是否使用相对坐标设置起点和终点,默认为False。 | | isLoop | bool | 是否循环,若设为True,则实体会在起点和终点之间往复运动。 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | int | 运动器ID,添加失败时返回-1 | - 备注 - 该接口不屏蔽生物本身的AI运动,并且生物在空中时会受到跌落伤害,当有AI运动发生时,最终的表现结果可能与预期有差异,建议将生物设置为NPC。 - 轨迹运动器不可叠加,仅能添加一个。 - 由于引擎中在加载的区块以外的实体时会停止一切活动,建议将运动范围控制在玩家位置±100内。 - 示例 ```python import mod.server.extraServerApi as serverApi motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId) target = (5, 0, 0) mID = motionComp.AddEntityTrackMotion(target, 3.0, startPos=None, relativeCoord=True, isLoop=False) ``` ## 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内。 - 示例 ```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) ``` ## GetAttackTarget 服务端 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() ``` ## GetBlockControlAi 服务端 method in mod.server.component.controlAiCompServer.ControlAiCompServer - 描述 获取生物原生AI是否被屏蔽 - 参数 无 - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | AI是否保留。False为AI被屏蔽。 | - 备注 - 屏蔽AI后的生物无法行动,不受重力且不会被推动。但是可以受到伤害,也可以被玩家交互(例如马被骑或村民被交易) - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateControlAi(entityId) comp.GetBlockControlAi() ``` ## 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 # } ``` ## GetMotion 服务端客户端 ### 服务端接口 method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer - 描述 获取生物(含玩家)的瞬时移动方向向量 - 参数 无 - 返回值 |
数据类型
| 说明 | | :--- | :--- | | tuple(int,int,int) | 瞬时移动方向向量,异常时返回None | - 示例 ```python import mod.server.extraServerApi as serverApi motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(entityId) motionComp.GetMotion() ``` ### 客户端接口 method in mod.client.component.actorMotionCompClient.ActorMotionComponentClient - 描述 获取生物的瞬时移动方向向量 - 参数 无 - 返回值 |
数据类型
| 说明 | | :--- | :--- | | tuple(int,int,int) | 瞬时移动方向向量,异常时返回None | - 示例 ```python import mod.client.extraClientApi as clientApi comp = 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() ``` ## GetStepHeight 服务端 method in mod.server.component.attrCompServer.AttrCompServer - 描述 返回玩家前进非跳跃状态下能上的最大台阶高度 - 参数 无 - 返回值 |
数据类型
| 说明 | | :--- | :--- | | float | 台阶高度 | - 示例 ```python 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枚举](../../枚举值/ActorDamageCause.md) | | attackerId | str | 伤害来源的实体id,默认为None | | childAttackerId | str | 伤害来源的子实体id,默认为None,比如玩家使用抛射物对实体造成伤害,该值应为抛射物Id | | knocked | bool | 实体是否被击退,默认值为True | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 是否设置成功 | - 示例 ```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 - 描述 设置实体是否免疫伤害(该属性存档) - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | immune | bool | 是否免疫伤害 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 是否设置成功 | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateHurt(entityId) comp.ImmuneDamage(True) ``` ## IsEntityOnFire 服务端 method in mod.server.component.attrCompServer.AttrCompServer - 描述 获取实体是否着火 - 参数 无 - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 是否着火 | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateAttr(entityId) isOnFire = comp.IsEntityOnFire() ``` ## RemoveEntityMotion 服务端 method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer - 描述 移除实体(不含玩家)身上的运动器 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | motionId | int | 要移除的某个运动器的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.client.component.actorCollidableCompClient.ActorCollidableCompClient - 描述 设置实体是否可碰撞 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | isCollidable | int | 0:不可碰撞 1:可碰撞 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | True表示设置成功 | - 示例 ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateActorCollidable(entityId) success = comp.SetActorCollidable(1) ``` ## SetActorPushable 服务端 method in mod.server.component.actorPushableCompServer.ActorPushableCompServer - 描述 设置实体是否可推动 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | isPushable | int | 0:不可推动 1:可推动 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | True表示设置成功 | - 示例 ```python 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 | 设置结果 | - 示例 ```python 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后的生物无法行动,不受重力且不会被推动,但是可以受到伤害,也可以被玩家交互(例如马被骑或村民被交易) - 对玩家无效 - 示例 ```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只有驯服者才能骑乘 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | tamedEntityId | str | 可骑乘生物id | | canRide | bool | 是否控制 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | 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 - 描述 设置该生物无需装备鞍就可以控制行走跳跃 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | tamedEntityId | str | 可骑乘生物id | | isControl | bool | 是否控制 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 备注 - 该接口仅对已被驯服的可骑乘生物生效,若使用SetEntityRide接口驯服生物,需间隔一定帧数后再调用本接口。 - 示例 ```python 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组件时才能调用该接口,例如牛、羊驼、猪灵等 - 示例 ```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) ``` ## SetEntityOnFire 服务端 method in mod.server.component.attrCompServer.AttrCompServer - 描述 设置实体着火 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | seconds | int | 着火时间(单位:秒) | | burn_damage | int | 着火状态下每秒扣的血量,不传的话默认是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 - 描述 驯服可骑乘生物 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | playerId | str | 玩家id | | tamedEntityId | str | 要驯服的可骑乘生物id | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 备注 - 驯服信息会被存盘 - 示例 ```python # 驯服生物 import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateRide(entityId) comp.SetEntityRide(playerId,entityId) ``` ## SetEntityShareablesItems 服务端 method in mod.server.component.shareableCompServer.ShareableComponentServer - 描述 设置生物可分享/可拾取的物品列表 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | items | list(itemdict) | 可分享/可拾取的物品列表 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | 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组件使用。该类驯服不包含骑乘功能。 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | playerId | str | 驯服玩家Id | | tamedId | str | 被驯服的生物Id | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 备注 - 驯服一个生物,需要按以下步骤: 1. 搭配修改生物json文件,使其能够被驯服: - 添加minecraft:tameable组件 - 添加一个component group,里面放驯服后的行为 - 添加一个event,添加刚刚添加的component group,并移除不需要的component group 2. 使用SetEntityTamed使目标生物被驯服 3. 使用TriggerCustomEvent触发驯服event 如果是对原版可驯服生物使用,则无需按照第一步修改json,而是找到已有的event,在第三步中触发即可 - 如修改苦力怕可被驯服,json做如下修改: ```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 服务端 method in mod.server.component.gravityCompServer.GravityComponentServer - 描述 设置生物跳跃力度,0.42表示正常水平 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | jumpPower | float | 跳跃力度,正常是0.42 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 是否设置成功 | - 备注 - 生物跳跃力度影响生物跳跃高度;本接口调用时需要客户端加载完成,如在AddServerPlayer中,客户端还没加载完成,要延后执行才能生效 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateGravity(entityId) comp.SetJumpPower(0.84) ``` ## 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事件,所以当需要在该事件中使用时,请编写逻辑避免循环调用 - 示例 ```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 服务端客户端 ### 服务端接口 method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer - 描述 设置生物(不含玩家)的瞬时移动方向向量 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | motion | tuple(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 - 描述 设置瞬时的移动方向向量,用于本地玩家 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | motion | tuple(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 - 描述 寻路组件 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | 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中配置. ```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格。 - 示例 ```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 - 描述 设置实体是否持久化。 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | isPersistent | bool | True为设置实体持久化,False为设置实体不持久化。 | - 返回值 无 - 备注 - 游戏中,实体默认持久化,若设置不持久化,则实体会在区块卸载和退出存档时被删除,不会存档。 - 示例 ```python 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 | 设置结果 | - 示例 ```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 - 描述 设置实体骑乘生物(或者船与矿车) - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | riderId | str | 骑乘生物id | | riddenEntityId | str | 被骑乘生物id。要求被骑乘生物的定义中具有minecraft:rideable组件,且组件中family_types含有可骑乘者的类型声明 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 备注 - 通常需要配合SetEntityRide、SetControl一起使用,需要被骑乘生物json中骑乘组件支持骑乘者的生物类型 当被控制的entity有多个位置时且开发者想要添加多个玩家时,第一个被添加的玩家会被引擎默认设置为控制者 - 示例 ```python # 骑上坐骑 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,即半格高度。 - 只对玩家生效,无法修改其它实体该属性 - 修改后不影响跳跃逻辑及跳跃高度,并不会因此而跳到更高,因此在某些特定情况下,你可以走上方块但跳不上去。 - 示例 ```python 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 | 是否成功启动 | - 示例 ```python 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 | 是否成功停止 | - 备注 - 调用该接口不会触发事件[EntityMotionStopServerEvent](../../事件/实体.md#EntityMotionStopServerEvent)。 - 示例 ```python 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中运行示例代码: ```json "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) ```