Files
netease-modsdk-wiki/docs/mcdocs/1-ModAPI/接口/世界/方块管理.md
2025-06-27 23:59:47 +08:00

617 lines
19 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
sidebarDepth: 1
---
# 方块管理
## GetBlock
<span style="display:inline;color:#7575f9">客户端</span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
获取某一位置的block
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(float,float,float) | 方块位置 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| tuple(str,int) | 参数1:方块的名称参数2:方块的附加值AuxValue |
- 备注
- 已经加载的地形才设置、获取方块信息
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
comp.GetBlock((x,y,z))
```
## GetBlockClip
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
获取某一位置方块当前<a href="../../../../mcguide/20-玩法开发/15-自定义游戏内容/2-自定义方块/1-JSON组件.html#netease-aabb">clip的aabb</a>
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
| dimensionId | int | 方块所在维度,不填时默认为-1 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | 方块clip的aabb字典 |
- 备注
- 已经加载的地形才能获取方块信息,支持获取对应维度的常加载区块内方块信息
- 由于方块的碰撞盒可以随临近方块改变而改变因此该接口返回的是调用时方块clip的aabb
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId)
blockDict = comp.GetBlockClip((0, 5, 0), 0)
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
获取指定位置方块当前clip的aabb
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | 方块aabb字典 |
- 备注
- 由于方块的碰撞盒可以随临近方块改变而改变因此该接口返回的是调用时方块clip的aabb
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
comp.GetBlockClip((x,y,z))
```
## GetBlockCollision
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
获取某一位置方块当前collision的aabb
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
| dimensionId | int | 方块所在维度,不填时默认为-1 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | 方块aabb字典 |
- 备注
- 已经加载的地形才能获取方块信息,支持获取对应维度的常加载区块内方块信息
- 由于方块的碰撞盒可以随临近方块改变而改变因此该接口返回的是调用时方块collision的aabb
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId)
blockDict = comp.GetBlockCollision((0, 5, 0), 0)
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
获取指定位置方块当前collision的aabb
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | 方块aabb字典 |
- 备注
- 由于方块的碰撞盒可以随临近方块改变而改变因此该接口返回的是调用时方块collision的aabb
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
comp.GetBlockCollision((x,y,z))
```
## GetBlockNew
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
获取某一位置的block
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
| dimensionId | int | 方块所在维度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#方块信息字典">方块信息字典</a> |
- 备注
- 已经加载的地形才能获取方块信息,支持获取对应维度的常加载区块内方块信息
- 对于有多种状态的方块aux计算比较复杂推荐使用GetBlockStates获取方块状态字典
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId)
blockDict = comp.GetBlockNew((0, 5, 0), 0)
```
## GetDestroyTotalTime
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
获取使用物品破坏方块需要的时间
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| 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 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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)
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
获取使用物品破坏方块需要的时间
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| 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 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
获取某个位置的方块所含流体的信息
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
| dimensionId | int | 方块所在维度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#方块信息字典">方块信息字典</a> |
- 备注
- 已经加载的地形才能获取方块信息,支持获取对应维度的常加载区块内方块信息
- 对于不含水或者不是流体的方块则返回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
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
获取某一位置最高的非空气方块的高度
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int) | x轴与z轴位置 |
| dimension | int | 维度id默认为0可在获取常加载区块内最高非空气方块高度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int或None | 高度。若区块未加载返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId)
height = comp.GetTopBlockHeight((5, 5), 0)
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.blockInfoCompClient.BlockInfoComponentClient
- 描述
获取当前维度某一位置最高的非空气方块的高度
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int) | x轴与z轴位置 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int或None | 高度。若区块未加载返回None |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateBlockInfo(levelId)
height = comp.GetTopBlockHeight((5, 5))
```
## SetBlockNew
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
设置某一位置的方块
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
| blockDict | dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#方块信息字典">方块信息字典</a> |
| 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%的性能消耗。 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
在某一位置放置拼图方块
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
| blockDict | dict | 拼图方块的方块信息字典 |
| dimensionId | int | 方块所在维度,必需参数 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
设置某一位置的方块的extraBlock可在此设置方块含水等
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
| blockDict | dict | 流体方块的<a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#方块信息字典">方块信息字典</a> |
| dimensionId | int | 方块所在维度,必需参数 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
设置某一位置的方块含雪
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
| dimensionId | int | 方块所在维度,必需参数 |
| height | int | 雪块的高度默认是1 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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)
```