--- sidebarDepth: 1 --- # 方块管理 ## GetBlock 客户端 method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient - 描述 获取某一位置的block - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(float,float,float) | 方块位置 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | tuple(str,int) | 参数1:方块的名称,参数2:方块的附加值AuxValue | - 备注 - 已经加载的地形才设置、获取方块信息 - 示例 ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId) comp.GetBlock((x,y,z)) ``` ## GetBlockClip 服务端客户端 ### 服务端接口 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 获取某一位置方块当前clip的aabb - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 方块位置 | | dimensionId | int | 方块所在维度,不填时默认为-1 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 方块clip的aabb字典 | - 备注 - 已经加载的地形才能获取方块信息,支持获取对应维度的常加载区块内方块信息 - 由于方块的碰撞盒可以随临近方块改变而改变,因此该接口返回的是调用时方块clip的aabb - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId) blockDict = comp.GetBlockClip((0, 5, 0), 0) ``` ### 客户端接口 method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient - 描述 获取指定位置方块当前clip的aabb - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 方块位置 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 方块aabb字典 | - 备注 - 由于方块的碰撞盒可以随临近方块改变而改变,因此该接口返回的是调用时方块clip的aabb - 示例 ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId) comp.GetBlockClip((x,y,z)) ``` ## GetBlockCollision 服务端客户端 ### 服务端接口 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 获取某一位置方块当前collision的aabb - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 方块位置 | | dimensionId | int | 方块所在维度,不填时默认为-1 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 方块aabb字典 | - 备注 - 已经加载的地形才能获取方块信息,支持获取对应维度的常加载区块内方块信息 - 由于方块的碰撞盒可以随临近方块改变而改变,因此该接口返回的是调用时方块collision的aabb - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId) blockDict = comp.GetBlockCollision((0, 5, 0), 0) ``` ### 客户端接口 method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient - 描述 获取指定位置方块当前collision的aabb - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 方块位置 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 方块aabb字典 | - 备注 - 由于方块的碰撞盒可以随临近方块改变而改变,因此该接口返回的是调用时方块collision的aabb - 示例 ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId) comp.GetBlockCollision((x,y,z)) ``` ## GetBlockNew 服务端 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 获取某一位置的block - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 方块位置 | | dimensionId | int | 方块所在维度 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 方块信息字典 | - 备注 - 已经加载的地形才能获取方块信息,支持获取对应维度的常加载区块内方块信息 - 对于有多种状态的方块,aux计算比较复杂,推荐使用GetBlockStates获取方块状态字典 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId) blockDict = comp.GetBlockNew((0, 5, 0), 0) ``` ## GetDestroyTotalTime 服务端客户端 ### 服务端接口 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 获取使用物品破坏方块需要的时间 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | blockName | str | 方块标识符,格式[namespace:name:auxvalue],auxvalue默认为0 | | itemName | str | 物品标识符,格式[namespace:name:auxvalue],auxvalue默认为0,默认为None(不使用物品) | | miningArgs | dict | 挖掘参数,包含以下字段:急迫等级haste、潮涌能量等级conduit_power、挖掘疲劳mining_fatigue以及挖掘效率等级mining_efficiency,默认为None(所有参数为0) | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | float | 需要消耗的时间 | - 备注 - 挖掘参数 miningArgs | 关键字 | 数据类型 | 说明 | | ----------| --------------------- | ---------| | haste | int | 急迫等级,模拟玩家获得急迫状态效果 | | conduit_power | int | 潮涌能量等级,模拟玩家获得潮涌能量状态效果 | | mining_fatigue | int | 挖掘疲劳等级,模拟玩家获得挖掘疲劳状态效果 | | mining_efficiency | int | 挖掘效率等级,模拟工具获得效率附魔 | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId) args = { "haste": 1, "conduit_power": 1, "mining_fatigue": 1, "mining_efficiency": 1 } comp.GetDestroyTotalTime("minecraft:diamond_block", "minecraft:stone_pickaxe", args) ``` ### 客户端接口 method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient - 描述 获取使用物品破坏方块需要的时间 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | blockName | str | 方块标识符,格式[namespace:name:auxvalue],auxvalue默认为0 | | itemName | str | 物品标识符,格式[namespace:name:auxvalue],auxvalue默认为0,默认为None(不使用物品) | | miningArgs | dict | 挖掘参数,包含以下字段:急迫等级haste、潮涌能量等级conduit_power、挖掘疲劳mining_fatigue以及挖掘效率等级mining_efficiency,默认为None(所有参数为0) | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | float | 需要消耗的时间 | - 备注 - 挖掘参数 miningArgs | 关键字 | 数据类型 | 说明 | | ----------| --------------------- | ---------| | haste | int | 急迫等级,模拟玩家获得急迫状态效果 | | conduit_power | int | 潮涌能量等级,模拟玩家获得潮涌能量状态效果 | | mining_fatigue | int | 挖掘疲劳等级,模拟玩家获得挖掘疲劳状态效果 | | mining_efficiency | int | 挖掘效率等级,模拟工具获得效率附魔 | - 示例 ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId) args = { "haste": 1, "conduit_power": 1, "mining_fatigue": 1, "mining_efficiency": 1 } comp.GetDestroyTotalTime("minecraft:diamond_block", "minecraft:stone_pickaxe", args) ``` ## GetLiquidBlock 服务端 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 获取某个位置的方块所含流体的信息 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 方块位置 | | dimensionId | int | 方块所在维度 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 方块信息字典 | - 备注 - 已经加载的地形才能获取方块信息,支持获取对应维度的常加载区块内方块信息 - 对于不含水或者不是流体的方块,则返回None。对于一个含水的方块,如含水的橡木栅栏,GetLiquidBlock会返回其含有的流体的信息(包括自定义流体),GetBlockNew则会返回橡木栅栏的信息。而对于一般的水方块(包括自定义流体),GetLiquidBlock和GetBlockNew则都会返回水的信息(包括自定义流体)。因此可以用GetLiquidBlock和GetBlockNew判断某个方块是否流体 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId) liquidBlockDict = comp.GetLiquidBlock((0, 5, 0), 0) ``` ## GetTopBlockHeight 服务端客户端 ### 服务端接口 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 获取某一位置最高的非空气方块的高度 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int) | x轴与z轴位置 | | dimension | int | 维度id,默认为0,可在获取常加载区块内最高非空气方块高度 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | int或None | 高度。若区块未加载返回None | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId) height = comp.GetTopBlockHeight((5, 5), 0) ``` ### 客户端接口 method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient - 描述 获取当前维度某一位置最高的非空气方块的高度 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int) | x轴与z轴位置 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | int或None | 高度。若区块未加载返回None | - 示例 ```python import mod.client.extraClientApi as clientApi comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId) height = comp.GetTopBlockHeight((5, 5)) ``` ## SetBlockNew 服务端 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 设置某一位置的方块 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 方块位置 | | blockDict | dict | 方块信息字典 | | oldBlockHandling | int | 0:替换,1:销毁,2:保留,默认为0 | | dimensionId | int | 方块所在维度,必需参数 | | isLegacy | bool | 是否设置为传统的aux,建议设置为True,即aux对应的state不随着版本迭代而变化。默认为False | | updateNeighbors | bool | 是否给相邻的方块触发[方块更新](https://zh.minecraft.wiki/w/%E6%96%B9%E5%9D%97%E6%9B%B4%E6%96%B0)以及BlockNeighborChangedServerEvent事件。默认为True触发。若选择不触发可节省约30%的性能消耗。 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 方块是否发生了改变,是则返回True,否则返回False | - 备注 - 已经加载的地形才能设置方块,支持在对应维度的常加载区块内设置方块 - 若设置前后为同一个方块(方块名和附加值都相同),则接口返回False - 若设置前后方块实体类型相同时(方块名相同),箱子、熔炉等容器内的物品将被清空(尽管前后附加值也相同时接口会返回False),而告示牌、物品展示框、自定义方块实体的内容会被保留(如果希望清空,可以先设置为空气再设置相应方块)。 - 随着版本更新,aux值对应的方块state会发生改变,对于有多种状态的方块,aux计算方式比较复杂,推荐先通过GetBlockAuxValueFromStates获取传统aux值再进行设置。 - 若调用SetBlockNew接口后立即调用其它会影响客户端表现的服务端接口,并且这个表现和此方块有关系(比如使用SetBlockNew放置一个箱子,并立即调用PlayerUseItemToPos接口打开这个箱子),可能会出现异常表现,如有类似需求,建议在下一帧对方块进行操作 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockState(levelId) # GetBlockAuxValueFromStates 只需要调用一次,得到的auxValue可以缓存以来以供后续使用 auxValue = comp.GetBlockAuxValueFromStates("minecraft:wool", { 'color': 'orange' }) blockDict = { 'name': 'minecraft:wool', 'aux': auxValue } comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId) comp.SetBlockNew((0, 5, 0), blockDict, 0, 0, True) # updateNeighbors置为False,则不会触发相邻方块的更新。例如将耕地替换成泥土,其上方的小麦不会掉落。 comp.SetBlockNew((0, 6, 0), blockDict, 0, 0, True, False) ``` ## SetJigsawBlock 服务端 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 在某一位置放置拼图方块 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 方块位置 | | blockDict | dict | 拼图方块的方块信息字典 | | dimensionId | int | 方块所在维度,必需参数 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 备注 - 已经加载的地形才能设置方块,支持在对应维度的常加载区块内设置方块 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockState(serverApi.GetLevelId()) # GetBlockAuxValueFromStates 只需要调用一次,得到的auxValue可以缓存以来以供后续使用 auxValue = comp.GetBlockAuxValueFromStates("minecraft:jigsaw", { "facing_direction":1 }) print auxValue blockDict = { 'name': 'minecraft:jigsaw', 'aux': auxValue, 'jigsaw_name':"minecraft:empty", 'jigsaw_target_name' : "minecraft:empty", 'jigsaw_target_pool' : "minecraft:empty", 'jigsaw_final_block' : 'minecraft:empty', 'jigsaw_join_type' : 0 #"jigsaw_join_type"的值只能为0或1(0表示设置拼图方块的接点类型为"可滚动";1表示设置拼图方块的接点类型为"一致") } comp = serverApi.GetEngineCompFactory().CreateBlockInfo(serverApi.GetLevelId()) print comp.SetJigsawBlock((0, 100, 0), blockDict, 0) ``` ## SetLiquidBlock 服务端 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 设置某一位置的方块的extraBlock,可在此设置方块含水等 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 方块位置 | | blockDict | dict | 流体方块的方块信息字典 | | dimensionId | int | 方块所在维度,必需参数 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 备注 - 已经加载的地形才能设置方块,支持在对应维度的常加载区块内设置方块 - dimensionId需要是playerId对应玩家所在的维度;如果dimensionId是-1则默认使用playerId对应玩家所在的维度 - 示例 ```python import mod.server.extraServerApi as serverApi blockDict = { 'name': 'minecraft:water', 'aux': 5 } comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId) comp.SetLiquidBlock((0, 5, 0), blockDict, 0) ``` ## SetSnowBlock 服务端 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 设置某一位置的方块含雪 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 方块位置 | | dimensionId | int | 方块所在维度,必需参数 | | height | int | 雪块的高度,默认是1 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 备注 - 已经加载的地形才能设置方块,支持在对应维度的常加载区块内设置方块 - dimensionId需要是playerId对应玩家所在的维度;如果dimensionId是-1则默认使用playerId对应玩家所在的维度 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId) comp.SetSnowBlock((0, 5, 0), 0, 1) ```