# 行为

# AddPlayerAroundEntityMotion

服务端

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
  • 备注

    • 该接口会在客户端和服务端同步进行,使用前请确保环绕的对象在客户端和服务端都已创建。
    • 该接口不屏蔽玩家控制的移动以及重力作用,当有玩家控制发生时,最终的表现结果可能与预期有差异。由于玩家的头部与相机控制相关,若需要使运动器控制玩家的头部,请使用DepartCamera分离玩家与摄像机。
    • 环绕运动器可叠加多个,且可与速度运动器互相叠加,每一帧的最终效果为各个运动器计算出的瞬时向量之和。
    • 由于引擎中有加载的区块限制以及客户端对实体管理进行了优化,建议将玩家与目标之间的半径控制在30以内。
  • 示例

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

# AddPlayerAroundPointMotion

服务端

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
  • 备注

    • 该接口不屏蔽玩家控制的移动以及重力作用,当有玩家控制发生时,最终的表现结果可能与预期有差异。由于玩家的头部与相机控制相关,若需要使运动器控制玩家的头部,请使用DepartCamera分离玩家与摄像机。
    • 环绕运动器可叠加多个,且可与速度运动器互相叠加,每一帧的最终效果为各个运动器计算出的瞬时向量之和。
    • 由于引擎中有加载的区块限制,建议将玩家的运动范围控制在当前位置±100内。
  • 示例

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

# AddPlayerTrackMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    给玩家添加轨迹运动器

  • 参数

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

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

    • 该接口不屏蔽玩家控制的移动,当有玩家控制发生时,最终的表现结果可能与预期有差异。由于玩家的头部与相机控制相关,若需要使运动器控制玩家的头部,请使用DepartCamera分离玩家与摄像机。
    • 轨迹运动器不可叠加,仅能添加一个。
    • 设置朝向后会根据相应的参数计算出最终朝向,若此时的targetRot > startRot,则会顺时针旋转,反之逆时针旋转。
  • 示例

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

# AddPlayerVelocityMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    给玩家添加速度运动器

  • 参数

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

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

    • 该接口不屏蔽玩家控制的移动以及重力作用,当有玩家控制发生时,最终的表现结果可能与预期有差异。由于玩家的头部与相机控制相关,若需要使运动器控制玩家的头部,请使用DepartCamera分离玩家与摄像机。
    • 速度运动器可叠加多个,且可与环绕运动器互相叠加。
    • 由于引擎中有加载的区块限制,建议将玩家的运动范围控制在当前位置±100内。
  • 示例

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

# BeginSprinting

客户端

method in mod.client.component.actorMotionCompClient.ActorMotionComponentClient

  • 描述

    使本地玩家进入并保持向前疾跑/冲刺状态

  • 参数

  • 返回值

  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorMotion(localPlayerId)
comp.BeginSprinting()

# ChangePlayerDimension

服务端

method in mod.server.component.dimensionCompServer.DimensionCompServer

  • 描述

    传送玩家

  • 参数

    参数名
    数据类型
    说明
    dimensionId int 维度,0-overWorld; 1-nether; 2-theEnd
    pos tuple(int,int,int) 传送的坐标
  • 返回值

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

    • 该接口在成功切换维度时pos位置为玩家头的位置,即比设定位置低1.62
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateDimension(playerId)
comp.ChangePlayerDimension(0, (0,4,0))

# ChangePlayerFlyState

服务端

method in mod.server.component.flyCompServer.FlyComponentServer

  • 描述

    给予/取消飞行能力, 并根据enterFly参数确定是否进入飞行状态

  • 参数

    参数名
    数据类型
    说明
    isFly bool 给予/取消飞行能力
    enterFly bool 是否进入飞行状态,当isFly为true时,该参数才有效,其他情况下均为false
  • 返回值

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

    • 不建议在OnGroundClientEvent事件回调中NotifyToServer,然后服务端收到数据后,调用ChangePlayerFlyState接口。 如果仍然需要这样调用,则建议在服务端收到数据后,用AddTimer延迟一帧后再调用ChangePlayerFlyState接口
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFly(playerId)
comp.ChangePlayerFlyState(True) # 给予飞行能力,并进入飞行状态
# comp.ChangePlayerFlyState(True, False)# 给予飞行能力,不进入飞行状态
# comp.ChangePlayerFlyState(False)# 取消飞行能力

# EnableKeepInventory

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    设置玩家死亡不掉落物品

  • 参数

    参数名
    数据类型
    说明
    enable bool True:不掉落,False:掉落
  • 返回值

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

    • 只有全局的“保留物品栏”规则关闭时,才会使用该设置控制玩家是否掉落。如果全局的“保留物品栏”规则是开启的,那么所有玩家死亡时都不会掉落。
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
succ = comp.EnableKeepInventory(True)

# EndSprinting

客户端

method in mod.client.component.actorMotionCompClient.ActorMotionComponentClient

  • 描述

    使本地玩家结束向前疾跑/冲刺状态

  • 参数

  • 返回值

  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorMotion(localPlayerId)
comp.EndSprinting()

# GetEntityRider

服务端客户端

# 服务端接口

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    获取骑乘者正在骑乘的实体的id。

  • 参数

  • 返回值

    数据类型
    说明
    str 骑乘者直接骑乘对象的实体id,假如骑乘者没有骑乘则返回“-1”
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
riderId = comp.GetEntityRider()

# 客户端接口

method in mod.client.component.rideCompClient.RideCompClient

  • 描述

    获取骑乘者正在骑乘的实体的id。

  • 参数

  • 返回值

    数据类型
    说明
    str 骑乘者直接骑乘对象的实体id,假如该骑乘者没有骑乘则返回“-1”
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateRide(entityId)
riderId = comp.GetEntityRider()

# GetInteracteCenterOffset

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    获取玩家服务端交互中心的偏移

  • 参数

  • 返回值

    数据类型
    说明
    tuple(float,float,float) 偏移量
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetInteracteCenterOffset()

# GetIsBlocking

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    获取玩家激活盾牌状态

  • 参数

  • 返回值

    数据类型
    说明
    bool 玩家盾牌状态是否激活
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetIsBlocking()

# GetPickCenterOffset

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    获取玩家设置的第三人称下客户端交互中心的偏移

  • 参数

  • 返回值

    数据类型
    说明
    tuple(float,float,float) 偏移量
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetPickCenterOffset()

# GetPickRange

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    获取玩家客户端的交互距离

  • 参数

  • 返回值

    数据类型
    说明
    float 交互范围
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetPickRange()

# GetPlayerExhaustionRatioByType

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    获取玩家某行为饥饿度消耗倍率

  • 参数

    参数名
    数据类型
    说明
    type int 行为枚举PlayerExhauseRatioType枚举
  • 返回值

    数据类型
    说明
    float 饥饿度消耗倍率值, -1为获取失败(例如在创造模式下)
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
jumpType = serverApi.GetMinecraftEnum().PlayerExhauseRatioType.JUMP
ratio = comp.GetPlayerExhaustionRatioByType(jumpType)

# GetPlayerInteracteRange

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    获取玩家服务端的交互距离

  • 参数

  • 返回值

    数据类型
    说明
    float 交互半径
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetPlayerInteracteRange()

# GetPlayerMotions

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    获取玩家身上的所有运动器

  • 参数

  • 返回值

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

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

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

# GetPlayerRespawnPos

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    获取玩家复活点

  • 参数

  • 返回值

    数据类型
    说明
    dict 复活点信息,包括维度和坐标
  • 备注

    • 使用spawnpoint指令设置玩家的出生点后,该接口可以获取到设置后的出生点
    • 未使用setworldspawn指令设置过出生点位置时,返回坐标的y轴是32767
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
print comp.GetPlayerRespawnPos()
#结果示例 {'dimensionId': 0, 'pos': (44, 32767, 4)}

# GetRelevantPlayer

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    获取附近玩家id列表

  • 参数

    参数名
    数据类型
    说明
    exceptList list(str) 排除的玩家id列表,默认值为None,不排除其他玩家及自身
  • 返回值

    数据类型
    说明
    list(str) 附近玩家id列表
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetRelevantPlayer(exceptId)

# IsEntityRiding

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    检查玩家是否骑乘。

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否骑乘
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
isRiding = comp.IsEntityRiding()

# IsPlayerCanFly

服务端

method in mod.server.component.flyCompServer.FlyComponentServer

  • 描述

    获取玩家能否飞行

  • 参数

  • 返回值

    数据类型
    说明
    bool True:是 False:否
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFly(playerId)
comp.IsPlayerCanFly()

# IsPlayerFlying

服务端

method in mod.server.component.flyCompServer.FlyComponentServer

  • 描述

    获取玩家是否在飞行

  • 参数

  • 返回值

    数据类型
    说明
    bool True:是 False:否
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFly(playerId)
comp.IsPlayerFlying()

# OpenWorkBench

服务端

method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer

  • 描述

    在玩家当前位置打开工作台UI,不依赖于工作台方块

  • 参数

  • 返回值

    数据类型
    说明
    bool 打开结果
  • 备注

    • 工作台有交互距离要求,太远了(与打开位置超过5格以上)打开工作台UI后会自动关闭
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId)  # 此处playerId为使用物品的玩家
comp.OpenWorkBench()

# PickUpItemEntity

服务端

method in mod.server.component.gameCompServer.GameComponentServer

  • 描述

    某个Player拾取物品ItemEntity

  • 参数

    参数名
    数据类型
    说明
    playerEntityId str 拾取者的playerEntityId
    itemEntityId str 要拾取的物品itemEntityId
  • 返回值

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

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.PickUpItemEntity(playerEntityId, itemEntityId)

# PlayerAttackEntity

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    玩家使用手持武器攻击某个生物

  • 参数

    参数名
    数据类型
    说明
    entityId str 生物entityId
  • 返回值

    数据类型
    说明
    bool 执行结果
  • 备注

    • 1.会触发PlayerAttackEntityEvent事件,并且可以被这个事件cancel
    • 2.此接口无视距离,但无法跨维度使用,同时需要目标区域已加载
    • 3.常加载区块的生物也不会执行tick,生物受伤cd不会减少,无法对生物多次造成伤害,通过SetHurtCD接口设置伤害间隔为0,可以解决这个问题
    • 4.此接口不会播放原版攻击动作,可以使用Swing接口来播放原版攻击动作
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)  # 此处playerId为发起攻击的玩家
suc = comp.PlayerAttackEntity("-123456")

# PlayerDestoryBlock

服务端

method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer

  • 描述

    使用手上工具破坏方块

  • 参数

    参数名
    数据类型
    说明
    pos tuple(int,int,int) 方块位置
    particle int 是否开启破坏粒子效果,默认为开
    sendInv bool 是否同步服务端背包信息,默认为不同步。因为破坏方块可能会造成手持物品耐久度降低等信息改变,不同步信息可能会造成后续一些逻辑异常,若大批量破坏方块,每次同步会有性能问题,建议前面的调用可令sendInv为False,在最后一次调用此函数时传入sendInv为True。
  • 返回值

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

    • 手上工具的附魔效果会生效,同时扣除耐久度
    • 会触发ServerPlayerTryDestroyBlockEvent事件,并且可以被这个事件cancel
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId)  # 此处playerId为block的破坏者
comp.PlayerDestoryBlock((0, 5, 0), 1, False)
comp.PlayerDestoryBlock((0, 6, 0), 1, True)

# 关闭破坏粒子效果
comp.PlayerDestoryBlock((0, 6, 0),0)

# PlayerUseItemToEntity

服务端

method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer

  • 描述

    玩家使用手上物品对某个生物使用

  • 参数

    参数名
    数据类型
    说明
    entityId str 生物entityId
  • 返回值

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

  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId)  # 此处playerId为使用物品的玩家
suc = comp.PlayerUseItemToEntity("-123456")

# PlayerUseItemToPos

服务端

method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer

  • 描述

    模拟玩家对某个坐标使用物品

  • 参数

    参数名
    数据类型
    说明
    pos tuple(int,int,int) 坐标
    posType int 物品所在的地方ItemPosType枚举
    slotPos int 槽位,获取INVENTORY及ARMOR时需要设置,其他情况写0即可
    facing int 朝向,详见Facing枚举
  • 返回值

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

    • 当使用抛射物时,只有在非创造模式下才会返回True;如果要对"盔甲架"等实体使用物品,请使用PlayerUseItemToEntity接口;只能对玩家周边200格以内的坐标使用
    • 模拟玩家使用物品时,最终效果和右键使用物品类似,会先触发方块交互,再触发物品使用。因此,该接口同时也可用作方块交互目的
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId)  # 此处playerId为使用物品的玩家
comp.PlayerUseItemToPos((0, 5, 0), serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 0, 1)

# RemovePlayerMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    移除玩家身上的运动器

  • 参数

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

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

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
motionComp.RemovePlayerMotion(mID)

# SetBanPlayerFishing

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    设置是否屏蔽玩家钓鱼功能,屏蔽后玩家可以正常抛甩鱼竿,但无法钓起任何物品

  • 参数

    参数名
    数据类型
    说明
    isBan bool 是否屏蔽玩家钓鱼功能,True为屏蔽,False为取消屏蔽
  • 返回值

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

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetBanPlayerFishing(True)

# SetInteracteCenterOffset

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    设置玩家服务端交互中心的偏移

  • 参数

    参数名
    数据类型
    说明
    offset tuple(float,float,float) 偏移量
  • 返回值

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

    • 该接口只修改服务端的交互中心,所以需要使用SetCameraAnchor修改客户端第一人称的交互中心,使用SetPickCenterOffset修改客户端第三人称的交互中心,否则客户端将无法选中方块,即无法发送正确的信息给服务端
    • 注:当前客户端能修改交互中心的有SetCameraAnchor修改第一人称,SetPickCenterOffset修改第三人称。服务端能使用SetInteracteCenterOffset修改玩家交互中心(服务端无第几人称概念)
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetInteracteCenterOffset(offset)

# SetPickCenterOffset

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    设置第三人称下,玩家客户端交互中心的偏移

  • 参数

    参数名
    数据类型
    说明
    offset tuple(float,float,float) 偏移量
  • 返回值

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

    • 该接口只修改第三人称,第一人称下需要使用SetCameraAnchor接口设置交互中心。
    • 该接口只修改客户端的交互中心,选中后客户端会将选中的消息发给服务端,所以需要使用SetInteracteCenterOffset修改服务端的的玩家交互中心,否则超出服务端允许的玩家可交互范围将被撤销。
    • 注:当前客户端能修改交互中心的有SetCameraAnchor修改第一人称,SetPickCenterOffset修改第三人称。服务端能使用SetInteracteCenterOffset修改玩家交互中心(服务端无第几人称概念)
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPickCenterOffset(offset)

# SetPickRange

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    设置玩家客户端的交互距离

  • 参数

    参数名
    数据类型
    说明
    pickRange float 交互半径
  • 返回值

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

    • 该接口只修改客户端的交互距离,选中后客户端会将选中的消息发给服务端,所以需要使用SetPlayerInteracteRange修改服务端玩家的交互距离,否则超出服务端允许的玩家可交互范围将被撤销。
  • 示例

import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPickRange(pickRange)

# SetPickUpArea

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    设置玩家的拾取物品范围,设置后该玩家的拾取物品范围会在原版拾取范围的基础上进行改变。

  • 参数

    参数名
    数据类型
    说明
    area tuple(float,float,float) 拾取物品范围,传入(0, 0, 0)时视作取消设置
  • 返回值

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

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
# 玩家拾取物品范围在X轴正负方向各增加5格,在Z轴正负方向各增加3格,在Y轴保持不变
succ = comp.SetPickUpArea((5, 0, 3))

# SetPlayerAttackSpeedAmplifier

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    设置玩家攻击速度倍数,1.0表示正常水平,1.2表示速度减益20%,0.8表示速度增益20%

  • 参数

    参数名
    数据类型
    说明
    amplifier float 攻击速度倍数,范围[0.5,2.0]
  • 返回值

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

    • 该接口影响接口SetHurtCD设置的全局受击间隔CD
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerAttackSpeedAmplifier(1.1)

# SetPlayerExhaustionRatioByType

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    设置玩家某行为饥饿度消耗倍率

  • 参数

    参数名
    数据类型
    说明
    type int 行为枚举PlayerExhauseRatioType枚举
    ratio float 倍率
  • 返回值

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

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
jumpType = serverApi.GetMinecraftEnum().PlayerExhauseRatioType.JUMP
ratio = comp.SetPlayerExhaustionRatioByType(jumpType, 20)

# SetPlayerInteracteRange

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    设置玩家服务端的交互距离

  • 参数

    参数名
    数据类型
    说明
    interacteRange float 交互半径
  • 返回值

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

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerInteracteRange(interacteRange)

# SetPlayerJumpable

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    设置玩家是否可跳跃

  • 参数

    参数名
    数据类型
    说明
    isJumpable bool 是否可跳跃,True允许跳跃,False禁止跳跃
  • 返回值

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

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerJumpable(False)

# SetPlayerMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    设置玩家的瞬时移动方向向量(可解决SetMotion闪现问题)

  • 参数

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

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

    • 在damageEvent事件里面使用该接口时,需把damageEvent事件回调的knock参数设置为False
    • SetMotion接口需要客户端服务端双端调用,但受限于网速、延迟等,会出现闪现情况,此接口可完美解决上述问题
  • 示例

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.SetPlayerMotion((x * 5, y * 5, z * 5))
# rot 和 世界坐标系关系
#               ^ x -90°
#               |
# 180°/-180  ----------> z 0°
#               | 90°

# SetPlayerMovable

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    设置玩家是否可移动

  • 参数

    参数名
    数据类型
    说明
    isMovable bool 是否可移动,True允许移动,False禁止移动
  • 返回值

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

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerMovable(False)

# SetPlayerRespawnPos

服务端

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    设置玩家复活的位置与维度

  • 参数

    参数名
    数据类型
    说明
    pos tuple(int,int,int) 复活点的位置坐标
    dimensionId int 复活点的维度,默认值为0(主世界),注意1:维度21是不可用的;注意2:不能在玩家死亡(PlayerDieEvent)之后设置复活点
  • 返回值

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

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
suc = comp.SetPlayerRespawnPos((0, 4, 0), 0)

# SetPlayerRideEntity

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    设置玩家骑乘生物(或者船与矿车)

  • 参数

    参数名
    数据类型
    说明
    playerId str 玩家id
    rideEntityId str 被骑乘生物id
    riderIndex int 指定玩家成为第n个骑乘者,范围为0~SeatCount-1,默认不指定
  • 返回值

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

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

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

# StartPlayerMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    启动玩家身上的某个运动器

  • 参数

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

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

    • 运动器控制的玩家会无视原生的碰撞逻辑而穿透方块,若需停止,请自行监听碰撞事件OnPlayerHitBlockServerEvent然后使用StopPlayerMotion停止
    • 由于玩家的运动器需要在客户端与服务端之间同步,所以请以EntityMotionStartServerEvent事件的触发作为真正的开始时机。
  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
motionComp.StartPlayerMotion(mID)

# StopEntityRiding

服务端

method in mod.server.component.rideCompServer.RideCompServer

  • 描述

    强制骑乘者下坐骑。

  • 参数

  • 返回值

    数据类型
    说明
    bool 当骑乘者当前正在骑乘并成功下坐骑返回True,否则返回False
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRide(entityId)
success = comp.StopEntityRiding()

# StopPlayerMotion

服务端

method in mod.server.component.actorMotionCompServer.ActorMotionComponentServer

  • 描述

    停止玩家身上的某个运动器

  • 参数

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

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

  • 示例

import mod.server.extraServerApi as serverApi
motionComp = serverApi.GetEngineCompFactory().CreateActorMotion(playerId)
motionComp.StopPlayerMotion(mID)

# isGliding

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    是否鞘翅飞行

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否鞘翅飞行
  • 示例

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isGliding()

# isInWater

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    是否在水中

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否在水中
  • 示例

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isInWater()

# isMoving

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    是否在行走

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否在行走
  • 示例

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isMoving()

# isRiding

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    是否骑乘

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否骑乘
  • 示例

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isRiding()

# isSneaking

服务端客户端

# 服务端接口

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    获取玩家是否处于潜行状态

  • 参数

  • 返回值

    数据类型
    说明
    bool 当前玩家是否处于潜行状态
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
is_sneaking = comp.isSneaking()

# 客户端接口

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    是否潜行

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否潜行
  • 示例

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isSneaking()

# isSprinting

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    是否在疾跑

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否在疾跑
  • 备注

    • 注意,只有当玩家在疾跑时,该接口才返回true,静止状态下,返回false
  • 示例

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isSprinting()

# isSwimming

服务端客户端

# 服务端接口

method in mod.server.component.playerCompServer.PlayerCompServer

  • 描述

    获取玩家是否处于游泳状态。

  • 参数

  • 返回值

    数据类型
    说明
    bool 当前玩家是否处于游泳状态
  • 示例

import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
is_swiming = comp.isSwimming()

# 客户端接口

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    是否游泳

  • 参数

  • 返回值

    数据类型
    说明
    bool 是否游泳
  • 示例

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.isSwimming()

# setMoving

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    设置是否行走,只能设置本地玩家(只适用于移动端)

  • 参数

  • 返回值

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

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.setMoving()

# setSneaking

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    设置是否潜行,只能设置本地玩家(只适用于移动端)

  • 参数

  • 返回值

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

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.setSneaking()

# setSprinting

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    设置行走模式为疾跑/冲刺,只能设置本地玩家(只适用于移动端)

  • 参数

  • 返回值

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

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.setSprinting()

# setUsingShield

客户端

method in mod.client.component.playerCompClient.PlayerCompClient

  • 描述

    激活盾牌状态

  • 参数

    参数名
    数据类型
    说明
    flag bool True使用盾牌,False取消使用盾牌
  • 返回值

    数据类型
    说明
    int 1设置成功,0设置失败,-1玩家未持盾
  • 示例

comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.setUsingShield(True)