--- sidebarDepth: 1 --- # 方块状态与附加值 ## GetBlockAuxValueFromStates 服务端 method in mod.server.component.blockStateCompServer.BlockStateComponentServer - 描述 根据方块名称和方块状态获取方块附加值AuxValue - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | blockName | str | 方块名称 | | states | dict | 方块状态 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | int | 方块附加值AuxValue,异常时为-1 | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockState(levelId) states = comp.GetBlockAuxValueFromStates("minecraft:hopper", {"facing_direction": 0, "toggle_bit": 0}) ``` ## GetBlockStates 服务端 method in mod.server.component.blockStateCompServer.BlockStateComponentServer - 描述 获取方块状态 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(float,float,float) | 方块位置 | | dimensionId | int | 方块所在维度 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 方块状态,异常时为None | - 备注 - 仅可获取到已加载区块内的方块状态,支持获取对应维度的常加载区块内方块状态 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockState(levelId) comp.GetBlockStates((4,4,3), 0) ``` ## GetBlockStatesFromAuxValue 服务端 method in mod.server.component.blockStateCompServer.BlockStateComponentServer - 描述 根据方块名称和方块附加值AuxValue获取方块状态 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | blockName | str | 方块名称 | | auxValue | int | 方块附加值AuxValue | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 方块状态,异常时为None | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockState(levelId) states = comp.GetBlockStatesFromAuxValue('minecraft:sapling', 9) ``` ## SetBlockStates 服务端 method in mod.server.component.blockStateCompServer.BlockStateComponentServer - 描述 设置方块状态 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(float,float,float) | 方块位置 | | data | dict | 方块状态 | | dimensionId | int | 方块所在维度 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置是否成功 | - 备注 - 仅可设置已加载区块内的方块状态,支持设置对应维度的常加载区块内方块状态 - 示例 ```python # 将白色羊毛设置为橙色羊毛 pos = (4,4,3) import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockState(levelId) state = comp.GetBlockStates(pos, 0) # state = { 'color': 'white' } state['color'] = 'orange' comp.SetBlockStates(pos, state, 0) ```