---
sidebarDepth: 1
---
# 游戏规则
## AddBannedItem
服务端
method in mod.server.component.itemBannedCompServer.ItemBannedCompServer
- 描述
增加禁用物品
- 参数
| 参数名 |
数据类型
| 说明 |
| :--- | :--- | :--- |
| itemName | str | 物品标识符,格式[namespace:name:auxvalue],auxvalue默认为0,auxvalue为*时候匹配任意auxvalue值。例如:minecraft:egg(也可以通过填写配置文件config/banned_items.json进行启动禁用) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否增加成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItemBanned(levelId)
comp.AddBannedItem("minecraft:egg")
```
## AddBlockProtectField
仅Apollo可用
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置一个方块无法被玩家/实体破坏的区域
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| dimensionId | int | 不可破坏区域所在维度 |
| startPos | tuple(int,int,int) | 初始位置,不可破坏区域AABB包围盒的最小点 |
| endPos | tuple(int,int,int) | 结束位置,不可破坏区域AABB包围盒的最大点 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 成功时返回区域的唯一ID,可用于取消不可破坏区域,失败时返回-1 |
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
field = gameComp.AddBlockProtectField(0, (-20, 0, -20), (20, 255, 20))
if field > 0:
print "AddBlockProtectField success field={}".format(field)
else:
print "AddBlockProtectField fail"
```
## CleanBlockProtectField
仅Apollo可用
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
取消全部已设置的方块无法被玩家/实体破坏的区域
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | success True为取消成功,False为取消失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
suc = gameComp.CleanBlockProtectField()
print "CleanBlockProtectField suc={}".format(suc)
```
## ClearBannedItems
服务端
method in mod.server.component.itemBannedCompServer.ItemBannedCompServer
- 描述
清空禁用物品
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否清空成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItemBanned(levelId)
comp.ClearBannedItems()
```
## DisableVineBlockSpread
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置是否禁用藤曼蔓延生长
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| disable | bool | True:禁用 False:非禁用 |
- 返回值
无
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.DisableBineBlockSpread(disable)
```
## ForbidLiquidFlow
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
禁止/允许地图中的流体流动
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| forbid | bool | True为禁止流体流动 False为允许流体流动 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | success True为设置成功,False为设置失败 |
- 备注
- 禁止流动后的流体,在重新允许流动之后,不会立刻向四周流动,直到受到方块更新(如相邻的方块发生改变)
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
success = gameComp.ForbidLiquidFlow(True)
```
## GetBannedItemList
服务端
method in mod.server.component.itemBannedCompServer.ItemBannedCompServer
- 描述
获取禁用物品列表
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| list(str)或None | 禁用物品列表或者None(异常情况),list元素为物品标识符,格式[namespace:name:auxvalue],auxvalue默认为0,auxvalue为*时候匹配任意auxvalue值。 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItemBanned(levelId)
comp.GetBannedItemList()
```
## GetGameDiffculty
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取游戏难度
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | GetMinecraftEnum().GameDiffculty.*:Peaceful,Easy,Normal,Hard分别为0~3 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
diffculty = comp.GetGameDiffculty()
```
## GetGameRulesInfoServer
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取游戏规则
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| dict | 游戏规则字典 |
- 备注
- 游戏规则字典 gameRule见代码注释
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
type = comp.GetGameRulesInfoServer()
#返回值如下
{
'option_info': {
'pvp': bool,
'show_coordinates': bool,
'fire_spreads': bool,
'tnt_explodes': bool,
'mob_loot': bool,
'natural_regeneration': bool,
'tile_drops': bool,
'experimental_gameplay': bool,
},
'cheat_info': {
'enable': bool,
'always_day': bool,
'mob_griefing': bool,
'keep_inventory': bool,
'weather_cycle': bool,
'mob_spawn': bool,
'entities_drop_loot': bool,
'daylight_cycle': bool,
'command_blocks_enabled': bool,
'random_tick_speed': int,
}
}
```
## GetGameType
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取默认游戏模式
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | GetMinecraftEnum().GameType.*:Survival,Creative,Adventure分别为0~2 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
type = comp.GetGameType()
```
## GetLevelGravity
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取重力因子
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 重力因子 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.GetLevelGravity()
```
## GetSeed
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取存档种子
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 存档种子 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
seed = comp.GetSeed()
```
## IsDisableCommandMinecart
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取当前是否允许运行命令方块矿车内置逻辑指令,当前仅Apollo网络服可用
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | True:当前禁止运行命令方块矿车内置逻辑指令;False:当前允许运行命令方块矿车内置逻辑指令 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
isDisable = comp.IsDisableCommandMinecart()
```
## IsLockDifficulty
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取当前世界的游戏难度是否被锁定
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | isLock True为已锁定,False为未锁定 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
isLock = comp.IsLockDifficulty()
```
## LockDifficulty
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
锁定当前世界游戏难度(仅本次游戏有效),锁定后任何玩家在游戏内都无法通过指令或暂停菜单修改游戏难度
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| lock | bool | True:锁定 False:解锁 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | result是否操作成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.LockDifficulty(True)
```
## OpenCityProtect
仅Apollo可用
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
开启城市保护,包括禁止破坏方块,禁止对方块使用物品,禁止怪物攻击玩家,禁止玩家之间互相攻击,禁止日夜切换,禁止天气变化,禁止怪物群落刷新
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | success True为设置成功,False为设置失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
success = gameComp.OpenCityProtect()
```
## RemoveBannedItem
服务端
method in mod.server.component.itemBannedCompServer.ItemBannedCompServer
- 描述
移除禁用物品
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| itemName | str | 物品标识符,格式[namespace:name:auxvalue],auxvalue默认为0,auxvalue为*时候匹配任意auxvalue值。 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否移除成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItemBanned(levelId)
comp.RemoveBannedItem("minecraft:stained_glass:2")
```
## RemoveBlockProtectField
仅Apollo可用
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
取消一个方块无法被玩家/实体破坏的区域
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| field | int | 不可破坏区域的唯一ID,AddBlockProtectField的返回值 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | success True为取消成功,False为取消失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
field = gameComp.AddBlockProtectField(0, (-20, 0, -20), (20, 255, 20))
if field > 0:
print "AddBlockProtectField success field={}".format(field)
suc = gameComp.RemoveBlockProtectField(field)
print "RemoveBlockProtectField field={} suc={}".format(field, suc)
```
## SetCanActorSetOnFireByLightning
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
禁止/允许闪电点燃实体
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| enable | bool | True为允许闪电点燃实体 False为禁止闪电点燃实体 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | success True为设置成功,False为设置失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
success = gameComp.SetCanActorSetOnFireByLightning(False)
```
## SetCanBlockSetOnFireByLightning
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
禁止/允许闪电点燃方块
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| enable | bool | True为允许闪电点燃方块 False为禁止闪电点燃方块 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | success True为设置成功,False为设置失败 |
- 备注
- 只有当游戏难度为普通及以上,并且开启了火焰蔓延,闪电才会点燃方块
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
success = gameComp.SetCanBlockSetOnFireByLightning(False)
```
## SetDefaultGameType
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置默认游戏模式
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| gameType | int | GetMinecraftEnum().GameType.*:Survival,Creative,Adventure分别为0~2 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(playerId)
# 设置创造模式为默认游戏模式
comp.SetDefaultGameType(1)
```
## SetDisableCommandMinecart
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置停止/开启运行命令方块矿车内置逻辑指令,当前仅Apollo网络服可用
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| isDisable | bool | True:停止运行命令方块矿车内置逻辑指令;False:开启运行命令方块矿车内置逻辑指令 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
suc = comp.SetDisableCommandMinecart(True)
```
## SetDisableContainers
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
禁止所有容器界面的打开,包括玩家背包,各种包含背包界面的容器方块如工作台与箱子,以及包含背包界面的实体交互如马背包与村民交易
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| isDisable | bool | 是否禁止容器界面 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
comp.SetDisableContainers(True)
```
## SetDisableDropItem
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置禁止丢弃物品
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| isDisable | bool | 是否禁止丢弃物品 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
# 1、开启开关后,玩家死亡会所有物品消失;如需保证物品不掉落,可以配合/gamerule keepInventory true 使用
# 2、创造模式下物品依然能丢弃。
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
comp.SetDisableDropItem(True)
```
## SetDisableGravityInLiquid
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
是否屏蔽所有实体在液体(水、岩浆)中的重力
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| isDisable | bool | True:屏蔽 False:取消屏蔽 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 设置屏蔽实体在液体中的重力后,实体将不能上浮也不能下潜。**对玩家而言,当水/岩浆淹没腰部及以上时(约在水面/岩浆表面0.7格及以下),将无法上岸。**
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetDisableGravityInLiquid(True)
```
## SetDisableHunger
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置是否屏蔽饥饿度
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| isDisable | bool | 是否屏蔽饥饿度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- 如需隐藏饥饿度请使用extraClientApi的HideHungerGui
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
comp.SetDisableHunger(True)
```
## SetGameDifficulty
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置游戏难度
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| difficulty | int | GetMinecraftEnum().GameDiffculty.*:Peaceful,Easy,Normal,Hard分别为0~3 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功,True为成功,False为失败 |
- 备注
- 若已经锁定了游戏难度,除非调用解锁游戏难度,否则将无法成功修改游戏难度
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
result = comp.SetGameDifficulty(0)
```
## SetGameRulesInfoServer
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置游戏规则。所有参数均可选。
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| gameRuleDict | dict | 游戏规则字典 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 其中游戏规则字典中每一项都为可选参数,但是设置option_info或者cheat_info其中一项子项后,必须加上option_info或者cheat_info
- 示例
```python
###游戏规则字典说明
gameRuleDict ={
'option_info': {
'pvp': bool, #玩家伤害
'show_coordinates': bool, #显示坐标
'fire_spreads': bool, #火焰蔓延
'tnt_explodes': bool, #tnt爆炸
'mob_loot': bool, #生物战利品
'natural_regeneration': bool, #自然生命恢复
'tile_drops': bool, #方块掉落
'immediate_respawn':bool #立即重生
},
'cheat_info': {
'enable': bool, #是否开启作弊
'always_day': bool, #终为白日
'mob_griefing': bool, #生物破坏方块
'keep_inventory': bool, #保留物品栏
'weather_cycle': bool, #天气更替
'mob_spawn': bool, #生物生成
'entities_drop_loot': bool, #实体掉落
'daylight_cycle': bool, #开启昼夜交替
'command_blocks_enabled': bool, #启用方块命令
'random_tick_speed': int,#随机方块tick速度
}
}
###
ruleDict ={
'cheat_info': {
'enable': True,
'always_day': True,
}
}
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetGameRulesInfoServer(ruleDict)
```
## SetHurtCD
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置伤害CD
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| cdTime | int | 单位帧数 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetHurtCD(1)
```
## SetLevelGravity
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置重力因子
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| data | float | 重力因子 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
#生物可单独设置重力因子,当生物的重力因子非0时则该生物单独有自己的重力因子,具体参见实体重力组件
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetLevelGravity(-0.08)
```