---
sidebarDepth: 1
---
# 地图
## CanSee
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
判断起始对象是否可看见目标对象,基于对象的Head位置判断
- 参数
| 参数名 |
数据类型
| 说明 |
| :--- | :--- | :--- |
| fromId | str | 起始对象ID |
| targetId | str | 目标对象ID |
| viewRange | float | 视野距离,默认值8.0 |
| onlySolid | bool | 只判断固体方块遮挡,默认True; False则液体方块也会遮挡 |
| angleX | float | 视野X轴角度,默认值180.0度 |
| angleY | float | 视野Y轴角度,默认值180.0度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否可见 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
comp.CanSee(entityId,targetId,20.0,True,180.0,180.0)
```
## CheckBlockToPos
服务端
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
判断位置之间是否有方块
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| fromPos | tuple(float,float,float) | 起始位置 |
| toPos | tuple(float,float,float) | 终止位置 |
| dimensionId | int | 位置所在维度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | result -1:获取失败 0:没有方块 1:有方块 |
- 备注
- 支持判断对应维度的常加载区块内位置之间是否有方块
- 返回-1通常是由于传入维度不存在、传入错误参数、传入位置所在区块并未加载等
- 示例
```python
import mod.server.extraServerApi as serverApi
from mod_log import logger as logger
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId)
if comp.CheckBlockToPos((0, 0, 0), (1, 1, 1), 0):
logger.info("(0, 0, 0)与(1, 1, 1)之间有方块")
```
## CheckChunkState
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
判断指定位置的chunk是否加载完成
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| dimension | int | chunk所在维度 |
| pos | tuple(int,int,int) | 指定位置的坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 加载是否完成 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
comp.CheckChunkState(0, (0, 0, 0))
```
## CreateDimension
服务端
method in mod.server.component.dimensionCompServer.DimensionCompServer
- 描述
创建新的dimension
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| dimensionId | int | 维度,0/1/2维度是不需要创建的。创建大于20的维度,需要在dimension_config.json中注册,注意,维度21是不可用的 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否创建成功 |
- 备注
- 建议在mod初始化时统一调用
- 与维度相关的接口(SetUseLocalTime,SetDimensionUseLocalWeather等)会影响出生点的生成,如果要用主世界地形生成出生点,需要在mod初始化的时候优先调用一次CreateDimension(0)
- 示例
```python
comp = serverApi.GetEngineCompFactory().CreateDimension(levelId)
comp.CreateDimension(3)
```
## CreateExplosion
服务端
method in mod.server.component.explosionCompServer.ExplosionComponentServer
- 描述
用于生成爆炸
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| pos | tuple(float,float,float) | 爆炸位置 |
| radius | int | 爆炸威力,具体含义可参考[wiki](https://minecraft-zh.gamepedia.com/%E7%88%86%E7%82%B8)对爆炸的解释 |
| fire | bool | 是否带火 |
| breaks | bool | 是否破坏方块 |
| sourceId | str | 爆炸伤害源的实体id |
| playerId | str | 爆炸创造的实体id |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateExplosion(levelId)
comp.CreateExplosion((50,50,50),10,True,True,sourceId,playerId)
```
## DeleteAllArea
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
删除所有常加载区域
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 删除的区域数目,错误时为None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
comp.DeleteAllArea()
```
## DeleteArea
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
删除一个常加载区域
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| key | str | 常加载区域的名称 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 删除是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
comp.DeleteArea('Area0')
```
## DetectStructure
服务端
method in mod.server.component.portalCompServer.PortalComponentServer
- 描述
检测自定义门的结构
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| playerId | None | 该参数未使用,直接传入None即可 |
| pattern | list(str) | 传送门形状 |
| defines | dict | 传送门定义 |
| touchPos | list(tuple(int,int)) | 传送门可激活的位置(相对参数pattern中定义的位置) |
| pos | tuple(int,int,int) | 使用物品坐标 |
| dimensionId | int | 传送门所在维度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(bool,tuple(int,int,int),tuple(int,int,int)) | 检测结果,传送门起始位置,方向 |
- 示例
```python
#传送门定义
defines = {
'#': 'minecraft:glowstone',
'*': 'minecraft:air'
}
#传送门形状
pattern = [
'####',
'#**#',
'#**#',
'####',
]
# 最下面中间的两个位置点击激活
touchPos =[(3,1),(3,2)]
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePortal(levelId)
ret = comp.DetectStructure(None, pattern, defines, touchPos, (12, 1, 5), 0)
if ret[0]:
logger.info('自定义传送门构建成功')
else:
logger.info('自定义传送门构建失败')
```
## GetAllAreaKeys
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
获取所有常加载区域名称列表
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| list(str) | 名称列表list |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
comp.GetAllAreaKeys()
```
## GetBiomeName
服务端
method in mod.server.component.biomeCompServer.BiomeCompServer
- 描述
获取某一位置所属的生物群系信息
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 指定位置 |
| dimId | int | 维度id |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| str | 该位置所属生物群系name |
- 备注
- 支持获取未加载区块的群系。但对于未加载的区块,将使用地形生成器来计算群系,而非存档内保存的群系。因此对于使用地图修改器修改过群系的地图,获取未加载区块的群系,结果可能与实际不符,建议确认区块加载完毕后再获取。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBiome(levelId)
biomeName = comp.GetBiomeName((0, 80, 0), 0)
```
## GetBlockLightLevel
服务端
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
获取方块位置的光照等级
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 方块位置 |
| dimensionId | int | 方块所在维度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 光照等级 |
- 备注
- 仅能获取到已加载区块内方块位置的光照等级,支持获取对应维度的常加载区块内光照等级
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId)
lightlevel = comp.GetBlockLightLevel((x,y,z), 0)
```
## GetChunkEntites
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
获取指定位置的区块中,全部的实体和玩家的ID列表
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| dimension | int | 维度 |
| pos | tuple(int,int,int) | 指定位置的坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| None或list(str) | 实体和玩家的ID的列表,当指定位置的区块不存在或尚未加载时,返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
entityList = comp.GetChunkEntites(0, (0, 0, 0))
print "GetChunkEntites entityList={}".format(entityList)
```
## GetChunkMaxPos
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
获取某区块最大点的坐标
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| chunkPos | tuple(int,int) | 指定区块的坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| None或tuple(int,int,int) | 该区块最大点的坐标 |
- 备注
- 当传入的chunkPos类型不是tuple或者长度不为2时,返回值为None
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
maxPos = comp.GetChunkMaxPos((1, 3))
```
## GetChunkMinPos
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
获取某区块最小点的坐标
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| chunkPos | tuple(int,int) | 指定区块的坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| None或tuple(int,int,int) | 该区块最小点的坐标 |
- 备注
- 当传入的chunkPos类型不是tuple或者长度不为2时,返回值为None
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
minPos = comp.GetChunkMinPos((1, 3))
```
## GetChunkMobNum
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
获取某区块中的生物数量(不包括玩家,但包括盔甲架)
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| dimension | int | 区块所在维度 |
| chunkPos | tuple(int,int) | 指定区块的坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 该区块中的生物数量 |
- 备注
- 返回值为-1通常是由于该维度未加载、该区块未加载
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
mobNum = comp.GetChunkMobNum(0, (1, 3))
```
## GetChunkPosFromBlockPos
服务端客户端
### 服务端接口
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
通过方块坐标获得该方块所在区块坐标
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| blockPos | tuple(int,int,int) | 方块的坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| None或tuple(int,int) | 该方块所在区块的坐标 |
- 备注
- 当传入的blockPos类型不是tuple或者长度不为3时,返回值为None
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
chunkPos = comp.GetChunkPosFromBlockPos((90, 40, -4))
```
### 客户端接口
method in mod.client.component.chunkSourceCompClient.ChunkSourceCompClient
- 描述
通过方块坐标获得该方块所在区块坐标
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| blockPos | tuple(int,int,int) | 方块的坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| None或tuple(int,int) | 该方块所在区块的坐标 |
- 备注
- 当传入的blockPos类型不是tuple或者长度不为3时,返回值为None
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateChunkSource(LevelId)
chunkPos = comp.GetChunkPosFromBlockPos((90, 40, -4))
```
## GetCurrentDimension
客户端
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取客户端当前维度
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 维度id。客户端未登录完成或正在切维度时返回-1 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
dimId = comp.GetCurrentDimension()
```
## GetEntitiesAround
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取区域内的entity列表
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| entityId | str | 某个entityId |
| radius | int | 正方体区域半径 |
| filters | dict | 过滤设置字典 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| list(str) | 返回entityId的list |
- 备注
- 过滤器在对区域内的所有实体进行过滤时,会把每一个实体设置为other,同时把entityId对应的实体设置为self。关于过滤器的详细说明,用户可以查看基岩版wiki:https://bedrock.dev/zh/docs/stable/Entities#Filters
- 过滤器中"subject"表示过滤判断的实体类型,"subject"="self"表示对每个实体设置的self进行过滤判断,"subject"="other"表示对每个实体设置的other进行过滤判断
- 示例
```python
#利用过滤器获取玩家身边的entity
#样例中的过滤器表示满足“是玩家”或者“没有头戴南瓜帽”的entity
filters = {
"any_of": [
{
"subject" : "other",
"test" : "is_family",
"value" : "player"
},
{
"test" : "has_equipment",
"domain": "head",
"subject" : "other",
"operator" : "not",
"value" : "carved_pumpkin"
}
]
}
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
comp.GetEntitiesAround(entityId, 100, filters)
```
## GetEntitiesAroundByType
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取区域内的某类型的entity列表
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| entityId | str | 区域中心的entityId,如某个玩家的entityid |
| radius | int | 区域半径 |
| entityType | int | [EntityType枚举](../../枚举值/EntityType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| list(str) | 返回entityId的list |
- 示例
```python
import mod.server.extraServerApi as serverApi
# 获取身边10格内的掉落物
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.GetEntitiesAroundByType(entityId, 10, serverApi.GetMinecraftEnum().EntityType.ItemEntity)
```
## GetEntitiesInSquareArea
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取区域内的entity列表
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| entityId | None | 该参数已废弃 |
| startPos | tuple(int,int,int) | 初始位置 |
| endPos | tuple(int,int,int) | 结束位置 |
| dimensionId | int | 区域所在维度,可获取对应维度的常加载区块内的实体列表 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| list(str) | 返回entityId的list |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.GetEntitiesInSquareArea(None, (0,0,0), (100,100,100), 0)
```
## GetEntityInArea
客户端
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
返回区域内的实体,可获取到区域范围内已加载的实体列表
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| entityId | str或None | 实体Id |
| pos_a | tuple(int,int,int) | 起点 |
| pos_b | tuple(int,int,int) | 终点,终点应大于起点 |
| exceptEntity | bool | 返回结果中是否除去entityId, 默认为False,传入entityId为None时exceptEntity无作用 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| list(str) | 区域范围内已加载的entityId列表 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
entities = comp.GetEntityInArea(entityId, (0,0,0), (1,2,3))
```
## GetLevelId
服务端客户端
### 服务端接口
method in mod.server.extraServerApi
- 描述
获取levelId。某些组件需要levelId创建,可以用此接口获取levelId。其中level即为当前地图的游戏。
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| str | 当前地图的levelId |
- 示例
```python
import mod.server.extraServerApi as serverApi
ServerSystem = serverApi.GetServerSystemCls()
class FpsServerSystem(ServerSystem):
def ExtraDataTest(args):
extraDataComp = serverApi.GetEngineCompFactory().CreateExtraData(serverApi.GetLevelId())
extraDataComp.score = 100
```
### 客户端接口
method in mod.client.extraClientApi
- 描述
获取levelId。某些组件需要levelId创建,可以用此接口获取levelId。其中level即为当前地图的游戏。
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| str | 当前地图的levelId |
- 示例
```python
import mod.client.extraClientApi as clientApi
ClientSystem = clientApi.GetClientSystemCls()
class FpsClientSystem(ClientSystem):
def CameraCompTest(args):
cameraComp = clientApi.GetComponent(clientApi.GetLevelId(), 'Minecraft', 'camera')
cameraComp.fov = 60
```
## GetLoadedChunks
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
获取指定维度当前已经加载完毕的全部区块的坐标列表
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| dimension | int | 维度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| None或list(tuple(int,int)) | 区块坐标的列表(区块坐标为(x,z)),当指定维度不存在或尚未创建时,返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
result = comp.GetLoadedChunks(0)
print "dimension {} has chunk {}".format(0, result)
```
## GetSpawnDimension
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取世界出生维度
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 维度id |
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
spawnDimension = gameComp.GetSpawnDimension()
```
## GetSpawnPosition
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取世界出生点坐标
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(int,int,int) | 出生点坐标 |
- 备注
- 返回的坐标不一定是精确的出生点坐标,也不一定是安全的出生点,玩家出生时会在该坐标附近随机选取一个满足出生条件的坐标。
- 未使用setworldspawn指令设置过出生点位置时,返回坐标的y轴是32767
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
spawnPos = gameComp.GetSpawnPosition()
```
## IsChunkGenerated
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
获取某个区块是否生成过。
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| dimensionId | int | 区块所在维度 |
| chunkPos | tuple(int,int) | 指定区块的坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 该区块是否生成过 |
- 备注
- 玩家探索过(以玩家为中心,模拟距离(在游戏的设置页面内)为半径内的区块),或者使用SetAddArea设置常加载区块附近的区块,都是生成过的区块。这些区块会保存到存档里,再次探索时会从存档读取,不会重新生成。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
# 获取主世界(10000,0,10000)坐标所在的区块是否生成过
result = comp.IsChunkGenerated(0, comp.GetChunkPosFromBlockPos((10000, 0, 10000)))
```
## IsSlimeChunk
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
获取某个区块是否史莱姆区块。
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| dimensionId | int | 区块所在维度 |
| chunkPos | tuple(int,int) | 指定区块的坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 该区块是否史莱姆区块 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
result = comp.IsSlimeChunk(0, comp.GetChunkPosFromBlockPos((10000, 0, 10000)))
```
## LocateNeteaseFeatureRule
服务端
method in mod.server.component.featureCompServer.FeatureCompServer
- 描述
与[/locate指令](https://minecraft-zh.gamepedia.com/%E5%91%BD%E4%BB%A4/locate)相似,用于定位网易自定义特征规则
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| ruleName | str | 特征规则名称,形式为namespace:featureRuleIdentifier,如custombiomes:overworld_pumpkins_feature_rule |
| dimensionId | int | 查找维度,**要求该维度已加载** |
| pos | tuple(int,int,int) | 以该位置为中心来查找满足网易自定义特征规则分布条件的坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(float,float,float)或None | 最近的满足网易自定义特征规则分布条件的坐标,定位失败则返回None |
- 备注
- 定位失败通常是由于传入维度不存在、维度未加载、没有满足该自定义特征规则分布条件的坐标、目标坐标距离传入位置过远(以该位置为中心,半径100个区块内无法找到)等
- 若在feature rules中"conditions"内的"minecraft:biome_filter"中**填写了判断维度以外的过滤规则,将有概率无法定位到满足该自定义特征规则分布条件的坐标**。建议开发者在"distribution"的"iterations"中使用query.is_biome代替
- 定位原理是根据网易自定义特征规则分布条件寻找可能的位置,因此**有可能会定位到在PlaceNeteaseStructureFeatureEvent事件中被取消生成的结构位置**。开发者应注意甄别,尽量避免对可能在PlaceNeteaseStructureFeatureEvent事件中被取消放置的结构对应特征规则文件调用定位函数
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFeature(levelId)
pos = comp.LocateNeteaseFeatureRule("custombiomes:overworld_pumpkins_feature_rule", 0, (0, 64, 0))
```
## LocateStructureFeature
服务端
method in mod.server.component.featureCompServer.FeatureCompServer
- 描述
与[/locate指令](https://minecraft-zh.gamepedia.com/%E5%91%BD%E4%BB%A4/locate)相似,用于定位原版的部分结构,如海底神殿、末地城等。
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| featureType | int | 原版的结构类型,[StructureFeatureType](../../枚举值/StructureFeatureType.md)枚举 |
| dimensionId | int | 结构所在维度,**要求该维度已加载** |
| pos | tuple(int,int,int) | 以该位置为中心来查找最近的结构 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(float,float)或None | 最近的结构所在区块位置(x坐标,z坐标),y坐标不定,若定位失败则返回None |
- 备注
- 定位失败通常是由于该维度不存在、该维度未加载、该维度中不存在该结构、该结构距离传入位置过远等
- 该接口返回值为对应结构所在区块的坐标,与结构实际生成位置可能相距一定距离
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFeature(levelId)
pos = comp.LocateStructureFeature(serverApi.GetMinecraftEnum().StructureFeatureType.Village, 0, (0, 64, 0))
```
## MayPlace
服务端
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
判断方块是否可以放置
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| identifier | str | 方块identifier,如minecraft:wheat |
| blockPos | tuple(int,int,int) | 方块将要放置的坐标 |
| facing | int | 朝向,详见[Facing枚举](../../枚举值/Facing.md) |
| dimensionId | int | 维度,默认为主世界0 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 方块是否可以放置 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(levelId)
pos = (-1, 4, 34)
canPlace = comp.MayPlace("minecraft:wheat", pos, serverApi.GetMinecraftEnum().Facing.Up, 0)
```
## MayPlaceOn
服务端
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
判断物品是否可以放到指定的位置上
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| identifier | str | 物品标识,如minecraft:dye |
| auxValue | int | 物品的附加值 |
| blockPos | tuple(int,int,int) | 位置坐标 |
| facing | int | 朝向,详见[Facing枚举](../../枚举值/Facing.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否可以放置 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.MayPlaceOn("minecraft:dye", 3, (1,2,3), serverApi.GetMinecraftEnum().Facing.Up)
```
## MirrorDimension
服务端
method in mod.server.component.dimensionCompServer.DimensionCompServer
- 描述
复制不同dimension的地形
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| fromId | int | 原dimensionId |
| toId | int | 目标dimensionId |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 仅复制源维度已经生成的区块信息到新的维度,对于未生成的源维度区块无法完全复制生成逻辑,可能采用部分新维度自己的信息。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateDimension(levelId)
comp.MirrorDimension(0, 1)
```
## PlaceStructure
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
放置结构
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| playerId | None | 该参数已废弃 |
| pos | tuple(float,float,float) | 放置结构的位置 |
| structureName | str | 结构名称 |
| dimensionId | int | 希望放置结构的维度,可在对应维度的常加载区块放置结构,默认为-1 |
| rotation | int | 放置结构的旋转角度,默认为0(只可旋转90,180,270度) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否放置成功,True为放置成功,False为放置失败 |
- 备注
- 放置时需要确保所放置的区块都已加载,否则会放置失败或者部分缺失
- 该接口是同步执行的,请勿在一帧内放置大量结构,会造成游戏卡顿
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.PlaceStructure(None, (100, 70, 100), "test:structureName", 0, 0)
```
## SetAddArea
服务端
method in mod.server.component.chunkSourceComp.ChunkSourceCompServer
- 描述
设置区块的常加载
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| key | str | 常加载区域的名称 |
| dimensionId | int | 区块所在的维度 |
| minPos | tuple(int,int,int) | 加载区域的最小坐标 |
| maxPos | tuple(int,int,int) | 加载区域的最大坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- key必须唯一,若添加区域时key已存在将添加失败。
- 该方式创建的常加载区域不会tick,即实体,方块实体,随机刻都不会进行更新。若需要区域被tick,请使用原版[tickingarea指令](https://minecraft-zh.gamepedia.com/%E5%91%BD%E4%BB%A4/tickingarea)。
- 将当前未加载的区块设置为常加载区块时,不会从存档加载生物。但如果是当前已加载的区块,则玩家远离区块后,区块内的实体会一直保持加载。
- 常加载区块内可以使用api创建实体、放置方块、放置结构、修改方块实体数据。
- 由于区块加载算法的特性,不保证最小到最大坐标的区块完全加载并可用(即CheckChunkState接口返回True),建议将操作位置的四周外延80格的区域都设置为常加载,例如需要在(0,5,0)的位置生成生物/放置方块,需要将(-80,0,-80)到(80,0,80)的区域设置为常加载。
- 通过本接口添加的区块不被tick时,无法使用fill指令在区块内填充方块
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChunkSource(levelId)
comp.SetAddArea('Area0', 0, (0,0,0), (60,0,60))
```
## SetMergeSpawnItemRadius
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置新生成的物品是否合堆
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| radius | int | 合堆检测半径,范围可设置为0到5,初始为0。若为0代表不合堆,若大于0,则地图中生成一个物品时,会检测这个半径内是否有相同物品,若有且未达到堆叠上限,则不生成新物品,而是使地图上该物品的数量增加。 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | success True为设置成功,False为设置失败 |
- 备注
- 该接口主要应用于优化会一次性大量生成掉落物品的场景,使用此方式后生成结果就是一堆物品,不会先生成多个物品再进行合堆检测,可大大减少掉落物品实体数量,大幅提升性能。
- 该接口不会影响游戏本身的每帧合堆检测逻辑,手中丢弃的物品不受上述合堆逻辑影响。
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
gameComp.SetMergeSpawnItemRadius(5)
```
## SetSpawnDimensionAndPosition
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置世界出生点维度与坐标
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| dimensionId | int或None | 维度id |
| pos | tuple(int,int,int)或None | 出生点坐标 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否成功 |
- 备注
- 同时设置dimensionId与pos时,出生点被设置在对应维度的对应坐标。
只设置dimensionId,而pos为None时,出生点设置为对应维度,而坐标将通过[基岩版世界生成搜索](https://minecraft.fandom.com/zh/wiki/%E7%94%9F%E6%88%90#.E5.9F.BA.E5.B2.A9.E7.89.88.E4.B8.96.E7.95.8C.E7.94.9F.E6.88.90.E6.90.9C.E7.B4.A2)决定。
只设置pos,而dimensionId为None,则出生点设置为当前出生维度的对应坐标,与setworldspawn指令相同。
- 将pos的y轴设置为65535,表示出生到xz坐标轴的最高实心方块上。
- 当出生维度的类型是地狱和末地时,不会像主世界一样寻找一个安全的位置出生。
- 关于世界出生点与个人出生点的规则,详见[玩家的生成](https://minecraft.fandom.com/zh/wiki/%E7%94%9F%E6%88%90#.E7.8E.A9.E5.AE.B6.E7.9A.84.E7.94.9F.E6.88.90)
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
# 设置世界出生点到dm3维度的某个坐标
gameComp.SetSpawnDimensionAndPosition(3, (0, 60, 0))
```
## UpgradeMapDimensionVersion
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
提升指定地图维度的版本号,版本号不符的维度,地图存档信息将被废弃。使用后存档的地图版本均会同步提升至最新版本,假如希望使用此接口清理指定维度的地图存档,需要在保证该维度区块都没有被加载时调用。
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| dimension | int | 维度的数字ID,0代表主世界 |
| version | int | 维度地图的版本号,取值范围为1-999 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | success True为设置成功,False为设置失败 |
- 备注
- 对于本地游戏来说,由于引擎加载时机比mod早,因此可能出现区块加载比mod加载更早的情况,此时在初始化时使用该接口升级当前维度会出现失效的情况,建议本地游戏中先将玩家移出需要升级的维度,等区块卸载完成(可以使用CheckChunkState判断玩家离开前位置)后再升级该维度。
- 对于网络服游戏来说,因为服务端加载mod总是比玩家登录要早,因此可以在mod初始化时调用该接口升级指定维度。
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
success = gameComp.UpgradeMapDimensionVersion(0, 10)
```