跳到主要内容

维度-Dimension

表示世界中特定维度(如下界、末地等)的类

参考链接:微软文档 Dimension

属性

id

只读 维度的标识符

Details

类型:

str

示例:

dim_id = dimension.id

dimId

只读 维度的数字ID

Details

类型:

int

示例:

dim_num = dimension.dimId

方法

getBlock

返回给定位置的方块实例

Details

getBlock(location)

参数:

  • location
    • 位置坐标
    • 类型:dict | Vector3

返回值类型:

Block

示例:

block = dimension.getBlock({"x": 100, "y": 64, "z": 200})

getEntities

获取维度中的实体

Details

getEntities(options=EntityQueryOptions)

参数:

  • options
    • 实体查询选项
    • 类型:dict | EntityQueryOptions

返回值类型:

list[Entity]

示例:

# 获取所有实体
entities = dimension.getEntities()

# 根据条件获取实体
entities = dimension.getEntities({"type": "minecraft:zombie"})

getEntitiesAtBlockLocation

返回特定位置的一组实体

Details

getEntitiesAtBlockLocation(location)

参数:

  • location
    • 位置坐标
    • 类型:dict | Vector3

返回值类型:

list[Entity]

示例:

entities = dimension.getEntitiesAtBlockLocation({"x": 100, "y": 64, "z": 200})

getPlayers

获取维度中的玩家

Details

getPlayers(options=EntityQueryOptions)

参数:

  • options
    • 玩家查询选项
    • 类型:dict | EntityQueryOptions

返回值类型:

list[Player]

示例:

# 获取所有玩家
players = dimension.getPlayers()

# 根据名称获取玩家
players = dimension.getPlayers({"name": "Jincarrot"})

getPlayer

根据ID获取玩家

Details

getPlayer(playerId)

参数:

  • playerId
    • 玩家ID
    • 类型:int | str

返回值类型:

Player

示例:

player = dimension.getPlayer("player_id_123")

runCommand

在维度的上下文中同步运行命令

Details

runCommand(commandString)

参数:

  • commandString
    • 要执行的命令
    • 类型:str

返回值类型:

CommandResult

示例:

result = dimension.runCommand("say 在维度中执行命令")

spawnEntity

在指定位置创建新实体(如生物)

Details

spawnEntity(identifier, location, options=SpawnEntityOptions)

参数:

  • identifier
    • 实体标识符
    • 类型:str
  • location
    • 生成位置
    • 类型:dict | Vector3
  • options
    • 生成选项
    • 类型:dict | SpawnEntityOptions

返回值类型:

Entity

示例:

# 生成僵尸
zombie = dimension.spawnEntity("minecraft:zombie", {"x": 100, "y": 64, "z": 200})

# 使用选项生成实体
options = {
"initialRotation": 45,
"spawnEvent": "minecraft:entity_born"
}
entity = dimension.spawnEntity("minecraft:cow", {"x": 100, "y": 64, "z": 200}, options)

spawnItem

在指定位置将新物品堆叠创建为实体

Details

spawnItem(itemStack, location)

参数:

  • itemStack
    • 物品堆叠
    • 类型:ItemStack
  • location
    • 生成位置
    • 类型:Vector3 | dict

返回值类型:

Entity

示例:

# 创建物品实体
item_entity = dimension.spawnItem(item_stack, {"x": 100, "y": 64, "z": 200})

createExplosion

在指定位置创建爆炸

Details

createExplosion(location, radius, explosionOptions={})

参数:

  • location
    • 爆炸位置
    • 类型:Vector3 | dict
  • radius
    • 爆炸半径
    • 类型:float
  • explosionOptions
    • 爆炸选项
    • 类型:dict | ExplosionOptions

返回值类型:

bool

示例:

# 创建简单爆炸
success = dimension.createExplosion({"x": 100, "y": 64, "z": 200}, 5.0)

# 创建带选项的爆炸
options = {
"causesFire": True,
"breaksBlocks": False
}
success = dimension.createExplosion({"x": 100, "y": 64, "z": 200}, 3.0, options)

fillBlocks

填充方块(暂未实现)

Details

fillBlocks(volume, block, options)

参数:

  • volume
    • 方块体积
    • 类型:BlockVolumeBase
  • block
    • 方块
    • 类型:BlockPermutation | str
  • options
    • 填充选项
    • 类型:Any

返回值类型:

Any

示例:

# 方法暂未实现

setBlock

设置方块(暂未实现)

Details

setBlock(type)

参数:

  • type
    • 方块类型
    • 类型:Any

无返回值

示例:

# 方法暂未实现

DimensionLocation类

表示世界中的精确坐标,包括其维度和位置

属性

dimension

维度对象

Details

类型:

Dimension

示例:

# 获取维度
dim = dim_location.dimension

# 设置维度
dim_location.dimension = new_dimension

x

X坐标

Details

类型:

float

示例:

# 获取X坐标
x_pos = dim_location.x

# 设置X坐标
dim_location.x = 100.5

y

Y坐标

Details

类型:

float

示例:

# 获取Y坐标
y_pos = dim_location.y

# 设置Y坐标
dim_location.y = 64.0

z

Z坐标

Details

类型:

float

示例:

# 获取Z坐标
z_pos = dim_location.z

# 设置Z坐标
dim_location.z = 200.3