跳到主要内容

世界-World

包含了一系列关于世界(mc环境,维度等)的操作

参考链接:微软文档 World

属性

afterEvents

只读 包含了一系列事件,这些事件已经发生并完成

Details

类型:

WorldAfterEvents

示例:

world.afterEvents.entityDie.subscribe(callback)

示例中使用的事件参见事件列表

方法

getAllPlayers

返回当前所有玩家

Details

getAllPlayers()

返回值类型:

List[Player]

示例:

players = world.getAllPlayers()

getPlayers

返回满足特定条件的玩家,参数留空则为返回全部玩家

Details

getPlayers(options?)

参数:

返回值类型:

List[Player]

示例:

players = world.getPlayers({"name": "Jincarrot"})

getEntity

通过实体运行id获取实体

Details

getEntity(id)

参数:

  • id
    • 实体的运行id(uid)
    • 类型:str

返回值类型:

Entity

示例:

entityId = serverApi.GetOnlinePlayers()[0] 
# 举例通过modsdk获取玩家的uid(玩家也是实体)
entity = world.getEntity(entityId)

getDimension

获取维度

Details

getDimension(dimensionId)

参数:

  • dimensionId
    • 维度名称,可填overworld, nether, the_end
    • 类型:str

返回值类型:

Dimension

示例:

dim = world.getDimension("overworld")

setDynamicProperty

设置动态属性(即自定义属性)

Details

setDynamicProperty(identifier, value)

参数:

  • identifier
    • 动态属性名称
    • 类型:str
  • value
    • 存入的数据
    • 类型:Any(限python基本数据类型)

无返回值

示例:

world.setDynamicProperty("customName", 1)

getDynamicProperty

获取动态属性(即自定义属性)

Details

getDynamicProperty(identifier)

参数:

  • identifier
    • 动态属性名称
    • 类型:str

返回值类型:

Any | None (先前存入的数据类型,没有存储过则返回None)

示例:

world.getDynamicProperty("customName")

getTimeOfDay

获取一天中的时间

Details

getTimeOfDay()

返回值类型:

int(范围从0-24000,单位:刻)

示例:

world.getTimeOfDay()