Files
netease-modsdk-wiki/docs/mcdocs/1-ModAPI/接口/世界/游戏规则.md
2025-03-18 14:46:12 +08:00

1261 lines
28 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
---
# 游戏规则
## AddBannedItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemBannedCompServer.ItemBannedCompServer
- 描述
增加禁用物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| itemName | str | 物品标识符,格式[namespace:name:auxvalue]auxvalue默认为0auxvalue为*时候匹配任意auxvalue值。例如minecraft:egg也可以通过填写配置文件config/banned_items.json进行启动禁用 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否增加成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItemBanned(levelId)
comp.AddBannedItem("minecraft:egg")
```
## AddBlockProtectField
<span style="display:inline;color:#ff5555">仅Apollo可用</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置一个方块无法被玩家/实体破坏的区域
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| dimensionId | int | 不可破坏区域所在维度 |
| startPos | tuple(int,int,int) | 初始位置不可破坏区域AABB包围盒的最小点 |
| endPos | tuple(int,int,int) | 结束位置不可破坏区域AABB包围盒的最大点 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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
<span style="display:inline;color:#ff5555">仅Apollo可用</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
取消全部已设置的方块无法被玩家/实体破坏的区域
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemBannedCompServer.ItemBannedCompServer
- 描述
清空禁用物品
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否清空成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItemBanned(levelId)
comp.ClearBannedItems()
```
## DisableVineBlockSpread
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置是否禁用藤曼蔓延生长
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| disable | bool | True:禁用 False:非禁用 |
- 返回值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.DisableVineBlockSpread(disable)
```
## ForbidLiquidFlow
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
禁止/允许地图中的流体流动
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| forbid | bool | True为禁止流体流动 False为允许流体流动 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | success True为设置成功False为设置失败 |
- 备注
- 禁止流动后的流体,在重新允许流动之后,不会立刻向四周流动,直到受到方块更新(如相邻的方块发生改变)
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
success = gameComp.ForbidLiquidFlow(True)
```
## GetBannedItemList
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemBannedCompServer.ItemBannedCompServer
- 描述
获取禁用物品列表
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| list(str)或None | 禁用物品列表或者None(异常情况),list元素为物品标识符,格式[namespace:name:auxvalue]auxvalue默认为0auxvalue为*时候匹配任意auxvalue值。 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItemBanned(levelId)
comp.GetBannedItemList()
```
## GetGameDiffculty
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取游戏难度
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | GetMinecraftEnum().GameDiffculty.*:PeacefulEasyNormalHard分别为0~3 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
difficulty = comp.GetGameDiffculty()
```
## GetGameRulesInfoServer
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取游戏规则
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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, #TNT爆炸
'mob_loot': bool, #生物战利品
'natural_regeneration': bool, #自然生命恢复
'respawn_block_explosion': bool, #重生方块爆炸
'respawn_radius': int, #重生半径,请注意范围,目前支持[0,128]
'tile_drops': bool, #方块掉落
'immediate_respawn':bool #立即重生
'experimental_biomes': bool, # 自定义生物群系
'experimental_modding': bool, # 即将推出的创作者功能
'experimental_holiday': 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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取默认游戏模式
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | GetMinecraftEnum().GameType.*:SurvivalCreativeAdventure分别为0~2 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
type = comp.GetGameType()
```
## GetLevelGravity
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取重力因子
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| float | 重力因子 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.GetLevelGravity()
```
## GetPistonMaxInteractionCount
<span style="display:inline;color:#ff5555">服务端</span><span style="display:inline;color:#7575f9">客户端</span>
### 服务端接口
<span id="s0"></span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取活塞/粘性活塞最多推动的方块数量默认为12个方块可能被其他开发者修改。
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 最大推动的方块数量 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetPistonMaxInteractionCount())
```
### 客户端接口
<span id="c0"></span>
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取活塞/粘性活塞最多推动的方块数量默认为12个方块可能被其他开发者修改。
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 最大推动的方块数量 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetPistonMaxInteractionCount())
```
## GetSeed
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取存档种子
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 存档种子 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
seed = comp.GetSeed()
```
## IsDisableCommandMinecart
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取当前是否允许运行命令方块矿车内置逻辑指令当前仅Apollo网络服可用
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | True当前禁止运行命令方块矿车内置逻辑指令False当前允许运行命令方块矿车内置逻辑指令 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
isDisable = comp.IsDisableCommandMinecart()
```
## IsLockDifficulty
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取当前世界的游戏难度是否被锁定
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | isLock True为已锁定False为未锁定 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
isLock = comp.IsLockDifficulty()
```
## IsLockGameRulesInfo
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取当前世界的游戏规则是否被锁定
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | isLock True为已锁定False为未锁定 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
isLock = comp.IsLockGameRulesInfo()
```
## IsLockGameType
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取当前世界的游戏类型是否被锁定,包括默认游戏类型和个人游戏类型
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | isLock True为已锁定False为未锁定 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
isLock = comp.IsLockGameType()
```
## LockDifficulty
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
锁定当前世界游戏难度(仅本次游戏有效),锁定后任何玩家在游戏内都无法通过指令或暂停菜单修改游戏难度
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| lock | bool | True:锁定 False:解锁 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | result是否操作成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.LockDifficulty(True)
```
## LockGameRulesInfo
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
锁定当前世界游戏规则仅本次游戏有效玩家无法通过指令、游戏菜单或api修改游戏规则包括[SetGameRulesInfoServer](#setgamerulesinfoserver)示例中列举的规则)
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| lock | bool | True:锁定 False:解锁 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | result是否操作成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.LockGameRulesInfo(True)
```
## LockGameType
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
锁定当前世界游戏类型仅本次游戏有效玩家无法通过指令、游戏菜单或相关api如[SetPlayerGameType](../玩家/游戏模式.md#setplayergametype)和[SetDefaultGameType](#setdefaultgametype)修改游戏类型,包括默认游戏类型和个人游戏类型
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| lock | bool | True:锁定 False:解锁 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | result是否操作成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.LockGameType(True)
```
## OpenCityProtect
<span style="display:inline;color:#ff5555">仅Apollo可用</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
开启城市保护,包括禁止破坏方块,禁止对方块使用物品,禁止怪物攻击玩家,禁止玩家之间互相攻击,禁止日夜切换,禁止天气变化,禁止怪物群落刷新
- 参数
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | success True为设置成功False为设置失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
success = gameComp.OpenCityProtect()
```
## RemoveBannedItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemBannedCompServer.ItemBannedCompServer
- 描述
移除禁用物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| itemName | str | 物品标识符,格式[namespace:name:auxvalue]auxvalue默认为0auxvalue为*时候匹配任意auxvalue值。 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否移除成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItemBanned(levelId)
comp.RemoveBannedItem("minecraft:stained_glass:2")
```
## RemoveBlockProtectField
<span style="display:inline;color:#ff5555">仅Apollo可用</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
取消一个方块无法被玩家/实体破坏的区域
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| field | int | 不可破坏区域的唯一IDAddBlockProtectField的返回值 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
禁止/允许闪电点燃实体
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| enable | bool | True为允许闪电点燃实体 False为禁止闪电点燃实体 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | success True为设置成功False为设置失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
success = gameComp.SetCanActorSetOnFireByLightning(False)
```
## SetCanBlockSetOnFireByLightning
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
禁止/允许闪电点燃方块
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| enable | bool | True为允许闪电点燃方块 False为禁止闪电点燃方块 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | success True为设置成功False为设置失败 |
- 备注
- 只有当游戏难度为普通及以上,并且开启了火焰蔓延,闪电才会点燃方块
- 示例
```python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
success = gameComp.SetCanBlockSetOnFireByLightning(False)
```
## SetDefaultGameType
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置默认游戏模式
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| gameType | int | GetMinecraftEnum().GameType.*:SurvivalCreativeAdventure分别为0~2 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(playerId)
# 设置创造模式为默认游戏模式
comp.SetDefaultGameType(1)
```
## SetDisableCommandMinecart
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置停止/开启运行命令方块矿车内置逻辑指令当前仅Apollo网络服可用
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| isDisable | bool | True停止运行命令方块矿车内置逻辑指令False开启运行命令方块矿车内置逻辑指令 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
suc = comp.SetDisableCommandMinecart(True)
```
## SetDisableContainers
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
禁止所有容器界面的打开,包括玩家背包,各种包含背包界面的容器方块如工作台与箱子,以及包含背包界面的实体交互如马背包与村民交易
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| isDisable | bool | 是否禁止容器界面 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
comp.SetDisableContainers(True)
```
## SetDisableDropItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置禁止丢弃物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| isDisable | bool | 是否禁止丢弃物品 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
# 1、开启开关后玩家死亡会所有物品消失如需保证物品不掉落可以配合/gamerule keepInventory true 使用
# 2、创造模式下物品依然能丢弃。
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
comp.SetDisableDropItem(True)
```
## SetDisableGravityInLiquid
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
是否屏蔽所有实体在液体(水、岩浆)中的重力
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| isDisable | bool | True:屏蔽 False:取消屏蔽 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 设置屏蔽实体在液体中的重力后,实体将不能上浮也不能下潜。**对玩家而言,当水/岩浆淹没腰部及以上时(约在水面/岩浆表面0.7格及以下),将无法上岸。**
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetDisableGravityInLiquid(True)
```
## SetDisableHunger
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置是否屏蔽饥饿度
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| isDisable | bool | 是否屏蔽饥饿度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- 如需隐藏饥饿度请使用extraClientApi的HideHungerGui
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(entityId)
comp.SetDisableHunger(True)
```
## SetGameDifficulty
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置游戏难度
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| difficulty | int | GetMinecraftEnum().GameDiffculty.*:PeacefulEasyNormalHard分别为0~3 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功True为成功False为失败 |
- 备注
- 若已经锁定了游戏难度除非调用LockDifficulty解锁游戏难度否则将无法成功修改游戏难度
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
result = comp.SetGameDifficulty(0)
```
## SetGameRulesInfoServer
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置游戏规则。所有参数均可选。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| gameRuleDict | dict | 游戏规则字典 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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, #自然生命恢复
'respawn_block_explosion': bool, #重生方块爆炸
'respawn_radius': int, #重生半径,请注意范围,目前支持[0,128]
'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,#随机刻速度
}
}
###
ruleDict ={
'cheat_info': {
'enable': True,
'always_day': True,
}
}
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetGameRulesInfoServer(ruleDict)
```
## SetHurtCD
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置全局受击间隔CD
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| cdTime | int | 单位帧数 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetHurtCD(1)
```
## SetLevelGravity
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置重力因子
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| data | float | 重力因子 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
#生物可单独设置重力因子当生物的重力因子非0时则该生物单独有自己的重力因子具体参见实体重力组件
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
comp.SetLevelGravity(-0.08)
```
## SetPistonMaxInteractionCount
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
设置活塞/粘性活塞最多推动的方块数量默认为12个方块。该设置不存档。
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| value | int | 最大推动的方块数量取值范围为1至1024 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.SetPistonMaxInteractionCount(1))
```