---
sidebarDepth: 1
---
# 属性
## ChangeEntityDimension
服务端
method in mod.server.component.dimensionCompServer.DimensionCompServer
- 描述
传送实体
- 参数
| 参数名 |
数据类型
| 说明 |
| :--- | :--- | :--- |
| dimensionId | int | 维度id,0-主世界; 1-下界; 2-末地; 或其他自定义维度 |
| pos | tuple(int,int,int) | 传送的坐标,假如输入None,那么就优先选择目标维度的传送门作为目的地,其次使用维度坐标映射逻辑确定目的地 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 该接口无法对玩家使用,玩家请使用ChangePlayerDimension
- 该接口只能传送到另一个维度,如果实体已经在这个维度会返回False
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateDimension(entityId)
comp.ChangeEntityDimension(0, (0,4,0))
```
## GetAllComponentsName
服务端
method in mod.server.component.entityComponentServer.EntityComponentServer
- 描述
获取实体所拥有的原版组件list
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| list(str) | 原版组件名list,[EntityComponentType枚举](../../枚举值/EntityComponentType.md) |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityComponent(entityId)
print comp.GetAllComponentsName()
```
## GetAttrMaxValue
服务端客户端
### 服务端接口
method in mod.server.component.attrCompServer.AttrCompServer
- 描述
获取实体的引擎属性的最大值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| type | int | [AttrType枚举](../../枚举值/AttrType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 属性值结果 |
- 备注
- attack_damage,knockback_resistance,jump_strength这三个值目前实现中并不会同步给客户端,因此这几个值通过客户端获取的为默认值。只有通过服务端的GetAttr才能获取到准确值
- 因为护甲为身上盔甲总防御值,因此目前不支持获取护甲的最大值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.GetAttrMaxValue(serverApi.GetMinecraftEnum().AttrType.HEALTH)
```
### 客户端接口
method in mod.client.component.attrCompClient.AttrCompClient
- 描述
获取属性最大值,包括生命值,饥饿度,移速等
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| type | int | [AttrType枚举](../../枚举值/AttrType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 属性值结果 |
- 备注
- attack_damage,knockback_resistance,jump_strength这三个值目前实现中并不会同步给客户端,因此这几个值通过客户端获取的为默认值。只有通过服务端的GetAttr才能获取到准确值
- 因为护甲为身上盔甲总防御值,因此目前不支持获取护甲的最大值
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateAttr(entityId)
comp.GetAttrMaxValue(clientApi.GetMinecraftEnum().AttrType.HEALTH)
```
## GetAttrValue
服务端客户端
### 服务端接口
method in mod.server.component.attrCompServer.AttrCompServer
- 描述
获取实体的引擎属性
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| attrType | int | [AttrType枚举](../../枚举值/AttrType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 属性结果 |
- 备注
- damage,knockback_resistance,jump_strength这三个值目前实现中并不会同步给客户端,因此这几个值通过客户端获取的为默认值。只有通过服务端的GetAttr才能获取到准确值
- 当生物不存在该属性时,返回-1。部分属性的最大值默认为1,可通过entity的json配置来设置,详见attrType连接
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.GetAttrValue(serverApi.GetMinecraftEnum().AttrType.HEALTH)
```
### 客户端接口
method in mod.client.component.attrCompClient.AttrCompClient
- 描述
获取属性值,包括生命值,饥饿度,移速
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| attrType | int | [AttrType枚举](../../枚举值/AttrType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 属性结果 |
- 备注
- damage,knockback_resistance,jump_strength这三个值目前实现中并不会同步给客户端,因此这几个值通过客户端获取的为默认值。只有通过服务端的GetAttr才能获取到准确值
- 当生物不存在该属性时,返回-1。部分属性的最大值默认为1,可通过entity的json配置来设置,详见attrType连接
- 护甲值,取决于身上穿戴的护甲总防御量和接口增加的额外护甲值。客户端无法获取接口增加的护甲值,建议开发者自行同步
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateAttr(entityId)
comp.GetAttrValue(clientApi.GetMinecraftEnum().AttrType.HEALTH)
```
## GetBodyRot
客户端
method in mod.client.component.rotCompClient.RotComponentClient
- 描述
获取实体的身体的角度
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 身体绕竖直方向的角度,单位是角度,如果没有身体,返回为0 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateRot(entityId)
y = comp.GetBodyRot()
```
## GetCurrentAirSupply
服务端客户端
### 服务端接口
method in mod.server.component.breathCompServer.BreathCompServer
- 描述
生物当前氧气储备值
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 生物当前氧气储备值 |
- 备注
- 注意:该值返回的是当前氧气储备的支持的逻辑帧数 = 氧气储备值 * 逻辑帧数(每秒20帧数)
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBreath(entityId)
comp.GetCurrentAirSupply()
```
### 客户端接口
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
玩家当前氧气储备值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| entityId | str | 玩家id |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 玩家当前氧气储备值 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetCurrentAirSupply(entityId))
```
## GetDeathTime
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取生物死亡后持续的时间(刻,1秒20刻),用于控制死亡动画。0表示生物未死亡。
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 死亡时间,0表示生物未死亡, -1为调用失败 |
- 备注
- 凋零的死亡动画有特殊逻辑,无法通过该接口获取
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetDeathTime()
```
## GetEntitiesBySelector
服务端
method in mod.server.component.entityComponentServer.EntityComponentServer
- 描述
传入目标选择器,获取对应实体id (最大范围是所有已加载的实体)
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| command | str | 目标选择器指令 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| list(str) | 目标实体id列表 |
- 备注
- 要使用范围进行筛选时,需要在创建Component时传入作为中心的entityId。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityComponent(entityId)
print(comp.GetEntitiesBySelector("@e[type=rabbit]"))
```
## GetEntityDamage
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取生物(包括玩家)的攻击力
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| entityId | str | 生物的实体Id |
| targetEntityId | str | 可选参数,攻击目标的实体Id(部分附魔的武器,会针对不同的生物产生伤害的加成,例如“节肢克星”附魔,对节肢生物有伤害加成) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 返回生物(包括玩家)攻击力 |
- 备注
- 注:该接口获取的是生物的基础攻击力,手持武器,buff效果,附魔效果的总和,抛射物不在计算范围内,使用技能或者抛射物攻击的敌对生物的攻击力不在计算范围内,例如骷髅、恶魂、唤魔者、掠夺者、流浪者、凋灵等。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetEntityDamage(entityId,targetEntityId))
```
## GetEntityDimensionId
服务端
method in mod.server.component.dimensionCompServer.DimensionCompServer
- 描述
获取实体所在维度
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 维度id,0-主世界; 1-下界; 2-末地; 或其他自定义维度 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateDimension(entityId)
comp.GetEntityDimensionId()
```
## GetEntityFallDistance
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取实体的坠落高度,越大的值会给予实体更大的坠落伤害,建议在[OnGroundServerEvent](../../事件/实体.md#ongroundserverevent)事件中调用
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 坠落高度,无坠落为0,获取失败为-1 |
- 备注
- 该接口不支持抛射物
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetEntityFallDistance()
```
## GetEntityLinksTag
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取实体相连接的实体,如获取entityId为马,会返回骑乘者的信息
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| dict | 相连接实体的dict |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetEntityLinksTag()
```
## GetEntityOwner
服务端
method in mod.server.component.actorOwnerCompServer.ActorOwnerComponentServer
- 描述
获取实体的属主(包括可驯服生物的主人,或者掉落物的丢弃者,弹射物的发射者等)
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| str | 实体属主id |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateActorOwner(entityId)
ownerId = comp.GetEntityOwner()
```
## GetFootPos
服务端客户端
### 服务端接口
method in mod.server.component.posCompServer.PosComponentServer
- 描述
获取实体脚所在的位置
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(float,float,float) | 位置信息 |
- 备注
- 获取实体脚底的位置(除了睡觉时)
- 类似接口参见[获取实体位置](#getpos)
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePos(entityId)
entityFootPos = comp.GetFootPos()
```
### 客户端接口
method in mod.client.component.posCompClient.PosComponentClient
- 描述
获取实体脚所在的位置
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(float,float,float) | 位置信息 |
- 备注
- 获取实体脚底的位置(除了睡觉时)
- 类似接口参见[获取实体位置](#getpos)
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePos(entityId)
#获取位置:
entityFootPos = comp.GetFootPos()
```
## GetGravity
服务端
method in mod.server.component.gravityCompServer.GravityComponentServer
- 描述
获取实体的重力因子,当生物重力因子为0时则应用世界的重力因子
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| float | 重力因子 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGravity(entityId)
comp.GetGravity()
```
## GetLoadActors
服务端
method in mod.server.component.gameCompServer.GameComponentServer
- 描述
获取已加载的实体id
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| list(str) | 实体id列表 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetLoadActors())
```
## GetMarkVariant
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取实体的标记变种属性值
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 标记变种枚举值,获取失败返回-1,详见[马的标记变种枚举](../../枚举值/HorseSpotType.md)、[V2版村民服装枚举](../../枚举值/VillagerClothingType.md). |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetMarkVariant()
```
## GetMaxAirSupply
服务端客户端
### 服务端接口
method in mod.server.component.breathCompServer.BreathCompServer
- 描述
获取生物最大氧气储备值
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 最大氧气储备值 |
- 备注
- 注意:该值返回的是最大氧气储备的支持的逻辑帧数 = 氧气储备值 * 逻辑帧数(每秒20帧数)
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBreath(entityId)
comp.GetMaxAirSupply()
```
### 客户端接口
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
玩家最大氧气储备值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| entityId | str | 实体id |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 玩家最大氧气储备值 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetMaxAirSupply(entityId))
```
## GetMobColor
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取生物的颜色,截止至网易2.9版本,只对羊和热带鱼有效
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 颜色枚举值,详见[EntityColorType枚举](../../枚举值/EntityColorType.md) |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetMobColor()
```
## GetMobStrength
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取生物的强度,截止至网易2.9版本,只对羊驼有效,强度越大羊驼驮运的箱子时格子数量越多
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 强度值,取值范围为 1~5 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetMobStrength()
```
## GetMobStrengthMax
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取生物强度的最大值,截止至网易2.9版本,只对羊驼有效,强度越大羊驼驮运的箱子时格子数量越多,[SetMobStrength](#setstrength)无法超过SetMobStrengthMax的值
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 强度值,取值范围为 1~5,原版默认值为5 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetMobStrengthMax()
```
## GetName
服务端客户端
### 服务端接口
method in mod.server.component.nameCompServer.NameComponentServer
- 描述
获取生物的自定义名称(即使用命名牌或者SetName接口设置的名称),或者玩家的名字。
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| str | 生物的自定义名称,或者玩家的名字 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateName(entityId)
comp.GetName()
```
### 客户端接口
method in mod.client.component.nameCompClient.NameComponentClient
- 描述
获取生物的自定义名称(即使用命名牌或者SetName接口设置的名称),或者玩家的名字。
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| str | 生物的自定义名称,或者玩家的名字 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateName(entityId)
comp.GetName()
```
## GetPos
服务端客户端
### 服务端接口
method in mod.server.component.posCompServer.PosComponentServer
- 描述
获取实体位置
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(float,float,float) | 位置信息 |
- 备注
- 对于非玩家,获取到的是脚底部位的位置
- 对于玩家,如果处于行走,站立,游泳,潜行,滑翔状态,获得的位置比脚底位置高1.62;如果处于睡觉状态,获得的位置比最低位置高0.2
- 类似接口有[GetFootPos](#getfootpos),对任何实体都是获取脚底部位的位置
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePos(entityId)
comp.GetPos()
```
### 客户端接口
method in mod.client.component.posCompClient.PosComponentClient
- 描述
获取实体位置
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(float,float,float) | 实体的坐标 |
- 备注
- 对于非玩家,获取到的是脚底部位的位置
- 对于玩家,如果处于行走,站立,游泳,潜行,滑翔状态,获得的位置比脚底位置高1.62,如果处于睡觉状态,获得的位置比最低位置高0.2
- 类似接口有[GetFootPos](#getfootpos),对任何实体都是获取脚底部位的位置
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreatePos(entityId)
#获取位置:
entityPos = comp.GetPos()
```
## GetRiderId
客户端
method in mod.client.component.gameCompClient.GameComponentClient
- 描述
获取玩家坐骑entityid
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| str | 获取玩家坐骑entityid,无骑乘时返回None |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateGame(levelId)
print(comp.GetRiderId(playerId))
```
## GetRot
服务端客户端
### 服务端接口
method in mod.server.component.rotCompServer.RotComponentServer
- 描述
获取实体头与水平方向的俯仰角度和竖直方向的旋转角度,获得角度后可用GetDirFromRot接口转换为朝向的单位向量 MC坐标系说明
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(float,float) | (上下角度,左右角度)单位是角度而不是弧度 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRot(entityId)
comp.GetRot()
```
### 客户端接口
method in mod.client.component.rotCompClient.RotComponentClient
- 描述
获取实体头与水平方向的俯仰角度和竖直方向的旋转角度,获得角度后可用GetDirFromRot接口转换为朝向的单位向量 MC坐标系说明
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(float,float) | 俯仰角度及绕竖直方向旋转的角度,单位是角度 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateRot(entityId)
x, y = comp.GetRot()
```
## GetSize
服务端客户端
### 服务端接口
method in mod.server.component.collisionBoxCompServer.CollisionBoxComponentServer
- 描述
获取实体的包围盒
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(float,float) | 包围盒大小 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateCollisionBox(entityId)
comp.GetSize()
```
### 客户端接口
method in mod.client.component.collisionBoxCompClient.CollisionBoxComponentClient
- 描述
获取实体的包围盒
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| tuple(float,float) | 包围盒大小 |
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateCollisionBox(entityId)
comp.GetSize()
```
## GetTradeLevel
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取村民的交易等级
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 村民的交易等级,调用失败返回 -1,详见[TradeLevelType](../../枚举值/TradeLevelType.md) |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetTradeLevel()
```
## GetTypeFamily
服务端
method in mod.server.component.attrCompServer.AttrCompServer
- 描述
获取生物行为包字段 type_family
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| list(str) | type_family列表,例['cow', 'mob'] |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.GetTypeFamily()
```
## GetUnitBubbleAirSupply
服务端
method in mod.server.component.breathCompServer.BreathCompServer
- 描述
单位气泡数对应的氧气储备值
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 单位气泡数对应的氧气储备值 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBreath(levelId)
comp.GetUnitBubbleAirSupply()
```
## GetVariant
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取实体的变种属性值
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| int | 变种枚举值,获取失败返回-1,详见[猫变种枚举](../../枚举值/CatVariantType.md)、[马变种枚举](../../枚举值/HorseType.md)、[狐狸变种枚举](../../枚举值/FoxType.md) |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.GetVariant()
```
## HasChest
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
判断生物是否背负了箱子,截止至网易2.9版本,只对羊驼、驴、骡生效
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否背负了箱子,获取失败返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.HasChest()
```
## HasComponent
服务端
method in mod.server.component.entityComponentServer.EntityComponentServer
- 描述
判断实体是否有原版组件
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| attrType | int | [EntityComponentType枚举](../../枚举值/EntityComponentType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否有对应组件 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityComponent(entityId)
print comp.HasComponent(serverApi.GetMinecraftEnum().EntityComponentType.attack)
```
## HasSaddle
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
判断实体是否装备了鞍
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否装备了鞍,调用失败返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.HasSaddle()
```
## IsAngry
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
判断实体是否处于激怒状态
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否处于激怒状态,调用失败返回None |
- 备注
- 该接口对铁傀儡无效,友好型生物如羊、猪没有激怒状态,可通过生物行为包中的json确定。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsAngry()
```
## IsBaby
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
判断实体是否为幼年
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否为幼年,调用失败返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsBaby()
```
## IsConsumingAirSupply
服务端
method in mod.server.component.breathCompServer.BreathCompServer
- 描述
获取生物当前是否在消耗氧气
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否消耗氧气 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBreath(entityId)
comp.IsConsumingAirSupply()
```
## IsIllagerCaptain
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
判断实体是否为袭击队长,截止至网易2.9版本,只对掠夺者和卫道士有效
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否为袭击队长,是返回True,否返回False,调用失败返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsIllagerCaptain()
```
## IsNaturallySpawned
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取生物是否为自然生成的
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否为自然生成的,调用失败返回None |
- 备注
- 一些自然生成的生物拥有持久性(例如末影龙、随大型结构生成的生物),则IsNaturallySpawned会返回False,详见基岩版持久性生物介绍
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsNaturallySpawned()
```
## IsOutOfControl
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
判断实体是否处于失控状态,截止至网易2.9版本,只对船有效
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否失控,调用失败返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsOutOfControl()
```
## IsPregnant
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
获取生物是否怀孕,截止至网易2.9版本,只对海龟有效
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否怀孕,调用失败返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsPregnant()
```
## IsSheared
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
判断实体是否被剃毛,截止至网易2.9版本,只对羊有效
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 已经被剃毛返回True,没有返回False,调用失败返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsSheared()
```
## IsSitting
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
判断实体是否处于坐下状态
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否处于坐下状态,调用失败返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsSitting()
```
## IsTamed
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
判断实体是否被驯服
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否为被驯服,调用失败返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.IsTamed()
```
## LockLocalPlayerRot
客户端
method in mod.client.component.rotCompClient.RotComponentClient
- 描述
在分离摄像机时,锁定本地玩家的头部角度
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| lock | bool | 传入True为锁定本地玩家头部角度
传入False为解锁本地玩家头部角度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | True:设置成功
False:设置失败 |
- 备注
- 只能设置localplayer,即本地玩家自己
- 玩家重生、切换维度时会重置头部角度
- 锁定本地玩家头部角度时第一人称视角下可以旋转镜头,但玩家头部角度不会发生改变,下次切换到第一人称视角时镜头角度仍为锁定时的角度
- 锁定本地玩家头部角度后,玩家划船时头部角度会尽量靠近锁定时的角度,若无法转到该角度,则会向左或向右看(视哪边距离目标角度更近而定)
- 示例
```python
import mod.client.extraClientApi as clientApi
# 分离摄像机
comp = clientApi.GetEngineCompFactory().CreateCamera(levelId)
comp.DepartCamera()
# 锁定本地玩家的头部角度
comp = clientApi.GetEngineCompFactory().CreateRot(entityId)
comp.LockLocalPlayerRot(True)
```
## PromoteToIllagerCaptain
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
晋升实体为袭击队长,截止至网易2.9版本,只对掠夺者和卫道士有效
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.PromoteToIllagerCaptain()
```
## ResetToDefaultValue
服务端
method in mod.server.component.attrCompServer.AttrCompServer
- 描述
重置实体引擎属性到默认值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| type | int | [AttrType枚举](../../枚举值/AttrType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 本接口对伤害吸收生命值ABSORPTION、护甲ARMOR属性无效
- 由于SetAttrValue接口旧有实现多数情况下会同时修改默认值,因此配合使用本接口时,请在SetAttrValue时指定参数setDefault=0
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.ResetToDefaultValue(serverApi.GetMinecraftEnum().AttrType.HEALTH)
# 在同类型属性的相关事件触发过程中,调用此接口可能会被相关事件覆盖无效,如受伤时,自动恢复到默认血量
# 解决方案是通过定时器在下一帧再执行相应的Reset操作
def ResetToDefaultHealth(self, entityId):
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.ResetToDefaultValue(serverApi.GetMinecraftEnum().AttrType.HEALTH)
def ActorHurtServerEvent(self, args):
entityId = args.get("entityId")
# 无效,调用后会被ActorHurtServerEvent覆盖
ResetToDefaultHealth(entityId)
# 有效,下一帧恢复
gameComp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
gameComp.AddTimer(0, self.ResetToDefaultHealth, entityId)
```
## ResetToMaxValue
服务端
method in mod.server.component.attrCompServer.AttrCompServer
- 描述
重置实体引擎属性到最大值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| type | int | [AttrType枚举](../../枚举值/AttrType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 本接口对伤害吸收生命值ABSORPTION、护甲ARMOR属性无效
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.ResetToMaxValue(serverApi.GetMinecraftEnum().AttrType.HEALTH)
# 在同类型属性的相关事件触发过程中,调用此接口可能会被相关事件覆盖导致无效,如受伤时,自动恢复满血
# 解决方案是通过定时器在下一帧再执行相应的Reset操作
def ResetToMaxHealth(self, entityId):
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.ResetToMaxValue(serverApi.GetMinecraftEnum().AttrType.HEALTH)
def ActorHurtServerEvent(self, args):
entityId = args.get("entityId")
# 无效,调用后会被ActorHurtServerEvent覆盖
ResetToMaxHealth(entityId)
# 有效,下一帧恢复
gameComp = serverApi.GetEngineCompFactory().CreateGame(serverApi.GetLevelId())
gameComp.AddTimer(0, self.ResetToMaxHealth, entityId)
```
## SetAngry
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置实体是否处于激怒状态
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| isAngry | bool | 是否设置为激怒状态 |
| targerId | str | 攻击的目标id,设置为True时必须设置目标,设置为isAngry为False的时候不用填 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- target必须在被激怒的生物的可见范围内,否则无法正常生效
- 友好型生物如羊、猪没有激怒状态,可通过生物行为包中的json确定。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetAngry(True, playerId)
```
## SetAsAdult
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置实体为成年体
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否为成功 |
- 备注
- 该接口只对定义有 "minecraft:ageable_grow_up" 事件的实体生效。
如果有需要,可自行添加,例如实现僵尸实体添加如下事件到events:
'''json
"minecraft:ageable_grow_up": {
"add": {
"component_groups": [
"minecraft:zombie_adult"
]
},
"remove": {
"component_groups": [
"minecraft:zombie_baby"
]
}
},
'''
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetAsAdult()
```
## SetAttrMaxValue
服务端
method in mod.server.component.attrCompServer.AttrCompServer
- 描述
设置实体的引擎属性的最大值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| type | int | [AttrType枚举](../../枚举值/AttrType.md) |
| value | float | 属性值 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 在设置属性的时候,需要注意判断是否超过原版的值范围,如果设置的数值超过原版值的范围,则返回False。
- 设置的最大饱和度不能超过当前的饥饿值; 食用食物后,最大饱和度会被原版游戏机制修改
- 需要注意的是护甲值由身上的护甲累计计算所得,并不能通过该接口直接修改
- 对于饥饿度,SetAttrMaxValue总是同时修改最大值与默认值,对于其他属性,它只修改最大值不修改默认值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.SetAttrMaxValue(serverApi.GetMinecraftEnum().AttrType.SPEED,0.2)
```
## SetAttrValue
服务端
method in mod.server.component.attrCompServer.AttrCompServer
- 描述
设置实体的引擎属性
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| attrType | int | [AttrType枚举](../../枚举值/AttrType.md) |
| value | float | 属性值 |
| setDefault | int | 是否同时设置默认值,1会同时设置默认值,0则不会,缺省时默认为1 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 在设置属性的时候,需要注意判断是否超过原版的值范围或是当前属性的值范围,如果设置的数值超过原版值的范围,则返回False。
- 如果超过当前属性的最大值,则需要先调用SetAttrMaxValue接口来扩充该属性的最大值,否则设置的值过大时会由于超过该属性的最大值而被截取成该最大值。如果设置的值低于当前属性的最小值,则会被设置成原版的最小值。
- 关于基础属性的原版最大值或最小值限制,可查看[AttrType枚举](../../枚举值/AttrType.md)
- 设置的护甲值属于额外的,会与装备带来的护甲值叠加,只能为非负整数,会覆盖掉原有生物(除潜影贝和岩浆怪)自带的护甲值,以下生物的护甲值最高为20:僵尸,僵尸村民,僵尸猪人,尸壳,溺尸,唤魔者,凋灵
- setDefault参数对于饥饿度与饱和度属性无效,只会修改当前值,不会修改默认值
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
# 如果设置的值超过属性当前的最大值,需要先扩充该属性的最大值,否则不生效。
comp.SetAttrMaxValue(serverApi.GetMinecraftEnum().AttrType.HEALTH, 30)
comp.SetAttrValue(serverApi.GetMinecraftEnum().AttrType.HEALTH, 30)
```
## SetChest
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置生物是否背负了箱子,截止至网易2.9版本,只对羊驼、驴、骡生效
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| hasChest | bool | 是否背负箱子 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetChest(True)
```
## SetCurrentAirSupply
服务端
method in mod.server.component.breathCompServer.BreathCompServer
- 描述
设置生物氧气储备值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| data | int | 设置生物当前氧气值 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 注意:该值设置的是当前氧气储备的支持的逻辑帧数 = 氧气储备值 * 逻辑帧数(每秒20帧数)
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBreath(entityId)
comp.SetCurrentAirSupply(300)
```
## SetEntityLookAtPos
服务端
method in mod.server.component.rotCompServer.RotComponentServer
- 描述
设置非玩家的实体看向某个位置
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| targetPos | tuple(float,float,float) | 要看向的目标位置 |
| minTime | float | 凝视行为最短维持时间,单位为秒 |
| maxTime | float | 凝视行为最长维持时间,单位为秒,最大值为60
实际行为维持时间将在minTime和maxTime之间取随机值 |
| reject | bool | 在进行凝视行为时,是否禁止触发其他行为
True为禁止其他行为
False为允许其他行为(此时凝视行为可能表现不明显) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功,True为成功,False为失败 |
- 备注
- 调用本接口会打断该生物正在进行的行为,且该生物不会立刻看向目标位置,而是逐渐看向目标位置
- 对部分不会转向的实体调用此接口,可能会返回失败或返回成功但实际无表现
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRot(entityId)
# 设置该实体看向(0,78,0)这个位置,该凝视行为最少持续2秒,最多持续3秒,凝视过程中禁止触发其他行为
comp.SetEntityLookAtPos((0,78,0), 2, 3, True)
```
## SetEntityOwner
服务端
method in mod.server.component.actorOwnerCompServer.ActorOwnerComponentServer
- 描述
设置实体的属主(包括可驯服生物的主人,或者掉落物的丢弃者,弹射物的发射者等)
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| targetId | str | 属主实体id,为None时设置实体的属主为空 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功,True表示设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateActorOwner(entityId)
result = comp.SetEntityOwner(targetId)
```
## SetFootPos
服务端
method in mod.server.component.posCompServer.PosComponentServer
- 描述
设置实体脚底所在的位置
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| footPos | tuple(float,float,float) | 实体脚所在的位置 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 行为与使用tp命令一致,实体会瞬移到目标点
- 在床上时调用该接口会返回False
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePos(entityId)
comp.SetFootPos((0, 4, 0))
```
## SetGravity
服务端
method in mod.server.component.gravityCompServer.GravityComponentServer
- 描述
设置实体的重力因子,当生物重力因子为0时则应用世界的重力因子
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| gravity | float | 负数,表示每帧向下的速度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateGravity(entityId)
comp.SetGravity(-0.08)
```
## SetMarkVariant
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置实体的标记变种属性值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| variantType | int | 变种枚举值,详见[马的标记变种枚举](../../枚举值/HorseSpotType.md)、[V2版村民服装枚举](../../枚举值/VillagerClothingType.md). |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 如果想设置其他生物的变种属性,可以直接查看behavior_packs中各个版本的entities文件下对应种类json中的"minecraft:mark_variant"属性
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetMarkVariant(1)
```
## SetMaxAirSupply
服务端
method in mod.server.component.breathCompServer.BreathCompServer
- 描述
设置生物最大氧气储备值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| data | int | 设置生物最大氧气值 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 注意:该值设置的是最大氧气储备的支持的逻辑帧数 = 氧气储备值 * 逻辑帧数(每秒20帧数)
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBreath(entityId)
comp.SetMaxAirSupply(400)
```
## SetMobColor
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置生物的颜色,截止至网易2.9版本,只对羊和热带鱼有效
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| colorType | int | 颜色枚举值,详见[EntityColorType枚举](../../枚举值/EntityColorType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
import common.minecraftEnum as minecraftEnum
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetMobColor(minecraftEnum.EntityColorType.LightGreen)
```
## SetMobStrength
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置生物的强度,截止至网易2.9版本,只对羊驼有效,强度越大羊驼驮运的箱子时格子数量越多
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| strength | int | 强度值,取值范围为 1~5,如果设置值大于[GetMobStrengthMax](#getmobstrengthmax)的值,将被设置为[GetMobStrengthMax](#getmobstrengthmax)的值 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetMobStrength(5)
```
## SetMobStrengthMax
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置生物强度的最大值,截止至网易2.9版本,只对羊驼有效,强度越大羊驼驮运的箱子时格子数量越多,[SetMobStrength](#setmobstrength)无法超过SetMobStrengthMax的值。由于引擎限制,在羊驼被打时候会reload组件,strengthMax会恢复成llama.json中的配置值(minecraft:strength)
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| strength | int | 强度值,取值范围为 1~5,原版默认值为5 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetMobStrengthMax(5)
```
## SetName
服务端
method in mod.server.component.nameCompServer.NameComponentServer
- 描述
用于设置生物的自定义名称,跟原版命名牌作用相同,玩家和新版流浪商人暂不支持
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| name | str | 名称 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateName(entityId)
comp.SetName("new Name")
```
## SetOutOfControl
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置实体是否处于失控状态,截止至网易2.9版本,只对船有效
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| isOutOfControl | bool | 是否处于失控状态 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetOutOfControl(True)
```
## SetPersistent
服务端
method in mod.server.component.attrCompServer.AttrCompServer
- 描述
设置实体不会因为离玩家太远而被[清除](https://zh.minecraft.wiki/w/%E7%94%9F%E6%88%90#%E6%B8%85%E9%99%A4)
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| persistent | bool | 设置为True时,则实体不会被清除 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否成功 |
- 备注
- 使用CreateEngineEntityByTypeStr创建isNpc为True的实体时,默认不会被清除
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateAttr(entityId)
comp.SetPersistent(True)
```
## SetPlayerLookAtPos
客户端
method in mod.client.component.rotCompClient.RotComponentClient
- 描述
设置本地玩家看向某个位置
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| targetPos | tuple(float,float,float) | 要看向的目标位置 |
| pitchStep | float | 俯仰角方向旋转的角速度(每帧),最小为0.2 |
| yawStep | float | 偏航角方向旋转的角速度(每帧),最小为0.2 |
| blockInput | bool | 转向目标角度时是否屏蔽玩家操作,默认为True
True:屏蔽玩家操作,此时玩家无法转向、移动
False:不屏蔽玩家操作,此时如果玩家有移动、镜头转向操作将会打断通过本接口设置的转向 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功,True为成功,False为失败 |
- 备注
- 当本地玩家未与摄像机分离时,调用本接口会导致摄像机一同看向指定位置
当本地玩家与摄像机分离时,调用本接口将只改变本地玩家模型的朝向
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateRot(localPlayerId)
# 设置本地玩家以0.2度每帧的俯仰角速度、1度每帧的偏航角速度看向(0,78,0)这个位置,转向过程中屏蔽玩家操作
comp.SetPlayerLookAtPos((0,78,0), 0.2, 1, True)
```
## SetPos
服务端
method in mod.server.component.posCompServer.PosComponentServer
- 描述
设置实体位置
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| pos | tuple(float,float,float) | xyz值 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 行为与使用tp命令一致,实体会瞬移到目标点
- 对于所有类型的实体都是设置脚底位置,与[SetFootPos](#setfootpos)等价
- 在床上时调用该接口会返回False
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreatePos(entityId)
comp.SetPos((1,2,3))
```
## SetRecoverTotalAirSupplyTime
服务端
method in mod.server.component.breathCompServer.BreathCompServer
- 描述
设置恢复最大氧气量的时间,单位秒
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| timeSec | float | 恢复生物最大氧气值 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 注意:当设置的最大氧气值小于(timeSec*10)时,生物每帧恢复氧气量的值为0
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBreath(entityId)
comp.SetRecoverTotalAirSupplyTime(10)
```
## SetRot
服务端客户端
### 服务端接口
method in mod.server.component.rotCompServer.RotComponentServer
- 描述
设置实体头与水平方向的俯仰角度和竖直方向的旋转角度 MC坐标系说明
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| rot | tuple(float,float) | (上下角度,左右角度)单位是角度而不是弧度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateRot(entityId)
comp.SetRot((30,0))
```
### 客户端接口
method in mod.client.component.rotCompClient.RotComponentClient
- 描述
设置实体头与水平方向的俯仰角度和竖直方向的旋转角度 MC坐标系说明
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| rot | tuple(float,float) | 俯仰角度及绕竖直方向旋转的角度,单位是角度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置是否成功 |
- 备注
- 建议只用来设置本地玩家。如果设置其他生物,会被生物自身行为覆盖。
- 示例
```python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateRot(entityId)
# 设为向上仰视45度,并朝向世界z轴正方向
comp.SetRot((-45, 0))
```
## SetSheared
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置实体是否被剃毛,截止至网易2.9版本,只对羊有效
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| isSheared | bool | 是否剃毛 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetSheared(True)
```
## SetSitting
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置生物是否坐下
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| shouldSitDown | bool | 是否坐下 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 该接口对熊猫无效,熊猫坐下有特殊游戏逻辑
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetSitting()
```
## SetSize
服务端
method in mod.server.component.collisionBoxCompServer.CollisionBoxComponentServer
- 描述
设置实体的包围盒。设置过大会导致游戏卡顿。实体的scale的立方乘以包围盒的体积不可超过32768
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| size | tuple(float,float) | 第一位表示宽度和长度,第二位表示高度 |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 对新生产的实体需要经过5帧之后再设置包围盒的大小才会生效
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateCollisionBox(entityId)
comp.SetSize((2,3))
```
## SetTradeLevel
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置村民的交易等级
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| holderId | int | 村民的交易等级,详见[TradeLevelType](../../枚举值/TradeLevelType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否成功 |
- 示例
```python
import mod.server.extraServerApi as serverApi
import common.minecraftEnum as minecraftEnum
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetTradeLevel(minecraftEnum.TradeLevelType.Master)
```
## SetVariant
服务端
method in mod.server.component.entityDefinitionsCompServer.EntityDefinitionsCompServer
- 描述
设置实体的变种属性值
- 参数
| 参数名 | 数据类型
| 说明 |
| :--- | :--- | :--- |
| variantType | int | 变种枚举值,详见[猫变种枚举](../../枚举值/CatVariantType.md)、[马变种枚举](../../枚举值/HorseType.md)、[狐狸变种枚举](../../枚举值/FoxType.md) |
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否设置成功 |
- 备注
- 如果想设置其他生物的变种属性,可以直接查看behavior_packs中各个版本的entities文件下对应种类json中的"minecraft:variant"属性
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateEntityDefinitions(entityId)
result = comp.SetVariant(1)
```
## isEntityInLava
客户端
method in mod.client.component.attrCompClient.AttrCompClient
- 描述
实体是否在岩浆中
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否在岩浆中,True为在岩浆中,False为不在岩浆中 |
- 备注
- 只能获取到本地客户端已加载的实体是否在岩浆中,若实体在其他维度或未加载(距离本地玩家太远),将获取失败
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreateAttr(entityId)
isInLava = comp.isEntityInLava()
```
## isEntityOnGround
客户端
method in mod.client.component.attrCompClient.AttrCompClient
- 描述
实体是否触地
- 参数
无
- 返回值
| 数据类型
| 说明 |
| :--- | :--- |
| bool | 是否触地,True为触地,False为不触地 |
- 备注
- 客户端实体刚创建时引擎计算还没完成,此时获取该实体是否着地将返回默认值True,需要延迟一帧进行获取才能获取到正确的数据
- 生物处于骑乘状态时,如玩家骑在猪身上,也视作触地
- 只能获取到本地客户端已加载的实体是否触地,若实体在其他维度或未加载(距离本地玩家太远),将获取失败
- 示例
```python
comp = clientApi.GetEngineCompFactory().CreateAttr(entityId)
isOnGound = comp.isEntityOnGround()
```