---
sidebarDepth: 1
---
# 属性
## AddPlayerExperience
服务端
method in mod.server.component.expCompServer.ExpComponentServer
- 描述
增加玩家经验值
- 参数
| 参数名 |
数据类型
| 说明 |
| :--- | :--- | :--- |
| exp | int | 玩家经验值,可设置负数 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- 如果设置的exp值为负数,且超过当前等级已有的经验值,调用接口后,该玩家等级不会下降但是经验值会置为最小值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateExp(entityId)
comp.AddPlayerExperience(25)
```
## AddPlayerLevel
服务端
method in mod.server.component.levelCompServer.LevelComponentServer
- 描述
修改玩家等级
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| level | int | 玩家等级,可设置负数 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateLv(playerId)
comp.AddPlayerLevel(2)
```
## CollectOnlineClientData
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
收集在线玩家客户端数据,用于判断玩家是否作弊
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| collectTypes | list(str) | 数据类型,不同类型收集到不同数据,具体说明参见备注。 |
| callback | function | 回调函数,用于分析数据并判断玩家是否作弊,包含两个参数,第一个参数是playerId,类型str;第二个参数表示收集到的数据,dict类型,内容由collectTypes决定的,具体参见备注,若数据收集失败则为None(比如玩家不在线) |
| extraArgs | dict | 默认为None,根据collectTypes传入不同参数,具体说明参见备注。 |
- 返回值
无
- 备注
- collectTypes中类型解释如下
game类型收集到的数据字典解释如下:
| 关键字 | 数据类型 | 说明 |
| ----------| --------------------- | ---------|
| gameType | int | 游戏模式,含义:-1:获取失败,0:生存模式,1:创造模式,2:冒险模式,3:旁观者模式|
| levelGravity | float | 世界的重力因子|
player类型收集到的数据字典解释如下:
| 关键字 | 数据类型 | 说明 |
| ----------| --------------------- | ---------|
| playerHealth | int | 玩家生命值|
world类型收集到的数据字典解释如下:
| 关键字 | 数据类型 | 说明 |
| ----------| --------------------- | ---------|
| blockName | str | 某一位置方块的名称,要求extraArgs参数包含pos参数|
| blockAuxValue | int | 某一位置方块的附加值AuxValue,要求extraArgs参数字典中包含"pos",若缺少则没有数据|
entity类型收集到的数据字典解释如下:
| 关键字 | 数据类型 | 说明 |
| ----------| --------------------- | ---------|
| entityPos | tuple(float,float,float) | 实体位置,具体参见客户端GetPos接口说明,要求extraArgs参数字典中包含"entityId",若缺少则没有数据|
| entityGravity | float | 获取实体的重力因子,当生物重力因子为0时则应用世界的重力因子,要求extraArgs参数字典中包含"entityId",若缺少则没有数据|
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
def ProcessData(playerId, data):
#正常返回实例:ProcessData 123 {'blockAuxValue': 0, 'blockName': 'minecraft:air', 'blockBoxSize': (-1.0, -1.0), 'gameType': 1, 'entityPos': (123,456,789), 'levelGravity': -0.08, 'playerHealth': 20, 'entityGravity': 0.0}
#失败返回实例:ProcessData 123 None
print minecraft'ProcessData', playerId, data
comp.CollectOnlineClientData(['player', 'world', 'entity', 'game'], ProcessData, {'entityId' :'123', 'pos' : (123,456,789))})
```
## GetPlayerExp
服务端
method in mod.server.component.expCompServer.ExpComponentServer
- 描述
获取玩家当前等级下的经验值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| isPercent | bool | 是否为百分比 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 玩家经验值 |
- 备注
- 如果设置返回百分比为False,则返回玩家当前等级下经验的绝对值(非当前玩家总经验值)。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateExp(entityId)
print(comp.GetPlayerExp(False))
```
## GetPlayerHealthLevel
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家健康临界值,当饥饿值大于等于健康临界值时会自动恢复血量,开启饥饿值且开启自然恢复时有效。原版默认值为18
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 健康临界值,-1表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.GetPlayerHealthLevel())
```
## GetPlayerHealthTick
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家自然恢复速度,当饥饿值大于等于健康临界值时会自动恢复血量,开启饥饿值且开启自然恢复时有效。原版默认值为80刻(即每4秒)恢复1点血量
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 自然恢复速度,-1表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.GetPlayerHealthTick())
```
## GetPlayerHunger
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家饥饿度,展示在UI饥饿度进度条上,初始值为20,即每一个鸡腿代表2个饥饿度。 **饱和度(saturation)** :玩家当前饱和度,初始值为5,最大值始终为玩家当前饥饿度(hunger),该值直接影响玩家**饥饿度(hunger)**。
1)增加方法:吃食物。
2)减少方法:每触发一次**消耗事件**,该值减少1,如果该值不大于0,直接把玩家 **饥饿度(hunger)** 减少1。
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 玩家饥饿度 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetPlayerHunger()
```
## GetPlayerLevel
服务端
method in mod.server.component.levelCompServer.LevelComponentServer
- 描述
获取玩家等级
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 玩家等级 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateLv(playerId)
comp.GetPlayerLevel()
```
## GetPlayerMaxExhaustionValue
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家foodExhaustionLevel的归零值,常量值,默认为4。**消耗度(exhaustion)**是指玩家当前消耗度水平,初始值为0,该值会随着玩家一系列动作(如跳跃)的影响而增加,当该值大于最大消耗度(maxExhaustion)后归零,并且把饱和度(saturation)减少1(为了说明饥饿度机制,我们将此定义为**消耗事件**)
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 玩家foodExhaustionLevel的归零值 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.GetPlayerMaxExhaustionValue()
```
## GetPlayerStarveLevel
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家饥饿临界值,当饥饿值小于饥饿临界值时会自动扣除血量,开启饥饿值且开启饥饿掉血时有效。原版默认值为1
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 饥饿临界值 -1表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.GetPlayerStarveLevel())
```
## GetPlayerStarveTick
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
获取玩家饥饿掉血速度,当饥饿值小于饥饿临界值时会自动扣除血量,开启饥饿值且开启饥饿掉血时有效。原版默认值为80刻(即每4秒)扣除1点血量
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 饥饿掉血速度,-1表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.GetPlayerStarveTick())
```
## GetPlayerTotalExp
服务端
method in mod.server.component.expCompServer.ExpComponentServer
- 描述
获取玩家的总经验值
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 总经验值,正整数。获取失败的情况下返回-1。 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateExp(entityId)
print(comp.GetPlayerTotalExp())
```
## IsPlayerNaturalRegen
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
是否开启玩家自然恢复,当饥饿值大于等于健康临界值时会自动恢复血量,开启饥饿值且开启自然恢复时有效。原版默认开启
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | True表示开启,False表示关闭,None表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.IsPlayerNaturalRegen())
```
## IsPlayerNaturalStarve
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
是否开启玩家饥饿掉血,当饥饿值小于饥饿临界值时会自动恢复血量,开启饥饿值且开启饥饿掉血时有效。原版默认开启
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | True表示开启,False表示关闭,None表示获取失败 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
print(comp.IsPlayerNaturalStarve())
```
## SetPlayerHealthLevel
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家健康临界值,当饥饿值大于等于健康临界值时会自动恢复血量,开启饥饿值且开启自然恢复时有效.原版默认值为18
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| healthLevel | int | 健康临界值 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 注:健康临界值始终大于等于饥饿临界值。如果设置的健康临界值小于饥饿临界值,饥饿临界值将被设置为当前的健康临界值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerHealthLevel(16) # 饥饿值大于等于16就会进入自然恢复状态,默认每隔4秒恢复1点血量
```
## SetPlayerHealthTick
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家自然恢复速度,当饥饿值大于等于健康临界值时会自动恢复血量,开启饥饿值且开启自然恢复时有效.原版默认值为80刻(即每4秒)恢复1点血量
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| healthTick | int | 自然恢复速度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 注:最小值为1,即每秒恢复20点血量
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerHealthTick(40) # 自然恢复状态下每隔2(40/20)秒恢复1点血量
```
## SetPlayerHunger
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家饥饿度。
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| value | float | 饥饿度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerHunger(10)
```
## SetPlayerMaxExhaustionValue
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家**最大消耗度(maxExhaustion)**,通过调整 **最大消耗度(maxExhaustion)** 的大小,就可以调整 **饥饿度(hunger)** 的消耗速度,当 **最大消耗度(maxExhaustion)** 很大时,饥饿度可以看似一直不下降
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| value | float | **最大消耗度(maxExhaustion)** |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 例如:当**最大消耗度(maxExhaustion)**为4时,玩家的饥饿消耗速度是**最大消耗度(maxExhaustion)**为8时的两倍
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(playerId)
comp.SetPlayerMaxExhaustionValue(10.0)
```
## SetPlayerNaturalRegen
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置是否开启玩家自然恢复,当饥饿值大于等于健康临界值时会自动恢复血量,开启饥饿值且开启自然恢复时有效.原版默认开启
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| value | bool | True开启,False关闭 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerNaturalRegen(False) # 关闭自然恢复,即使饥饿值大于健康临界值时也不会恢复血量
```
## SetPlayerNaturalStarve
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置是否开启玩家饥饿掉血,当饥饿值小于饥饿临界值时会自动扣除血量,开启饥饿值且开启饥饿掉血时有效.原版默认开启
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| value | bool | True开启,False关闭 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerNaturalStarve(False) # 关闭饥饿掉血,即使饥饿值小于饥饿临界值时也不会扣除血量
```
## SetPlayerPrefixAndSuffixName
服务端
method in mod.server.component.nameCompServer.NameComponentServer
- 描述
设置玩家前缀和后缀名字
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| prefix | str | 前缀内容 |
| prefixColor | str | 前缀内容颜色描述,可以使用GenerateColor接口传入参数 |
| suffix | str | 后缀内容 |
| suffixColor | str | 后缀内容颜色描述,可以使用GenerateColor接口传入参数 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateName(playerId)
comp.SetPlayerPrefixAndSuffixName("红队",serverApi.GenerateColor('RED'),'肉盾',serverApi.GenerateColor('RED'))
```
## SetPlayerStarveLevel
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家饥饿临界值,当饥饿值小于饥饿临界值时会自动扣除血量,开启饥饿值且开启饥饿掉血时有效。原版默认值为1
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| starveLevel | int | 饥饿临界值 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 注:健康临界值始终大于等于饥饿临界值。如果设置的饥饿临界值大于健康临界值,将被设置为当前的健康临界值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerStarveLevel(2) # 饥饿值小于等于2就会进入饥饿掉血状态,默认每隔4秒掉1点血量
```
## SetPlayerStarveTick
服务端
method in mod.server.component.playerCompServer.PlayerCompServer
- 描述
设置玩家饥饿掉血速度,当饥饿值小于饥饿临界值时会自动扣除血量,开启饥饿值且开启饥饿掉血时有效.原版默认值为80刻(即每4秒)扣除1点血量
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| starveTick | int | 饥饿掉血速度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 注:最小值为1,即每秒扣20点血量
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePlayer(entityId)
comp.SetPlayerStarveTick(40) # 饥饿掉血状态下每隔2(40/20)秒扣除1点血量
```
## SetPlayerTotalExp
服务端
method in mod.server.component.expCompServer.ExpComponentServer
- 描述
设置玩家的总经验值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| exp | int | 总经验值,正整数 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- 根据总经验值会重新计算等级,该接口可引起等级的变化
- 内部运算采用浮点数,数值较大时会出现误差
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateExp(entityId)
comp.SetPlayerTotalExp(25)
```
## Swing
客户端
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
本地玩家播放原版攻击动作
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否成功 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePlayer(clientApi.GetLevelId())
comp.Swing()
```
## getUid
客户端
method in mod.client.component.playerCompClient.PlayerCompClient
- 描述
获取本地玩家的uid
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| long或None | 玩家uid |
- 备注
- 不是客户端线程或者没有经过登录认证获取的uid为None。在当前机器上调用该接口获取的值为固定值,不依赖创建的player
- getUid接口不能在加载mod过程中使用,推荐开发者在OnLocalPlayerStopLoading事件触发之后再使用
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreatePlayer(entityId)
uid = comp.getUid()
```