160 lines
5.3 KiB
Markdown
160 lines
5.3 KiB
Markdown
---
|
||
sidebarDepth: 1
|
||
---
|
||
# 背包
|
||
|
||
## GetEntityItem
|
||
|
||
<span style="display:inline;color:#ff5555">服务端</span>
|
||
|
||
method in mod.server.component.itemCompServer.ItemCompServer
|
||
|
||
- 描述
|
||
|
||
获取生物物品,支持获取背包,盔甲栏,副手以及主手物品
|
||
|
||
- 参数
|
||
|
||
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
|
||
| :--- | :--- | :--- |
|
||
| posType | int | [ItemPosType枚举](../../枚举值/ItemPosType.md) |
|
||
| slotPos | int | 槽位,获取INVENTORY及ARMOR时需要设置,其他情况写0即可 |
|
||
| getUserData | bool | 是否获取userData,默认为False |
|
||
|
||
- 返回值
|
||
|
||
| <div style="width: 4em">数据类型</div> | 说明 |
|
||
| :--- | :--- |
|
||
| dict | 物品信息字典,没有物品则返回None |
|
||
|
||
- 备注
|
||
- 左右手及装备可以替代GetPlayerItem接口获取玩家的物品,但背包不行。获取生物背包目前支持驴、骡、羊驼以及其他带背包的自定义生物
|
||
|
||
- 示例
|
||
|
||
```python
|
||
import mod.server.extraServerApi as serverApi
|
||
comp = serverApi.GetEngineCompFactory().CreateItem(entityId)
|
||
comp.GetEntityItem(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 0)
|
||
```
|
||
|
||
|
||
|
||
## GetEquItemEnchant
|
||
|
||
<span style="display:inline;color:#ff5555">服务端</span>
|
||
|
||
method in mod.server.component.itemCompServer.ItemCompServer
|
||
|
||
- 描述
|
||
|
||
获取装备槽位中盔甲的附魔
|
||
|
||
- 参数
|
||
|
||
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
|
||
| :--- | :--- | :--- |
|
||
| slotPos | int | [ArmorSlotType枚举](../../枚举值/ArmorSlotType.md)枚举 |
|
||
|
||
- 返回值
|
||
|
||
| <div style="width: 4em">数据类型</div> | 说明 |
|
||
| :--- | :--- |
|
||
| list(tuple(int,int)) | 盔甲的附魔 |
|
||
|
||
- 备注
|
||
- 如果物品不存在,或者没有附魔值,返回None。如果存在返回tuple数组,每个tuple由附魔类型([EnchantType枚举](../../枚举值/EnchantType.md))和附魔等级组成
|
||
|
||
- 示例
|
||
|
||
```python
|
||
import mod.server.extraServerApi as serverApi
|
||
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
|
||
comp.GetEquItemEnchant(serverApi.GetMinecraftEnum().ArmorSlotType.HEAD)
|
||
```
|
||
|
||
|
||
|
||
## GetEquItemModEnchant
|
||
|
||
<span style="display:inline;color:#ff5555">服务端</span>
|
||
|
||
method in mod.server.component.itemCompServer.ItemCompServer
|
||
|
||
- 描述
|
||
|
||
获取装备槽位中盔甲的自定义附魔
|
||
|
||
- 参数
|
||
|
||
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
|
||
| :--- | :--- | :--- |
|
||
| slotPos | int | [ArmorSlotType枚举](../../枚举值/ArmorSlotType.md)枚举 |
|
||
|
||
- 返回值
|
||
|
||
| <div style="width: 4em">数据类型</div> | 说明 |
|
||
| :--- | :--- |
|
||
| list(tuple(str,int)) | list中每个tuple由自定义附魔id和附魔等级组成,没有自定义附魔则返回空列表 |
|
||
|
||
- 示例
|
||
|
||
```python
|
||
import mod.server.extraServerApi as serverApi
|
||
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
|
||
comp.GetEquItemModEnchant(serverApi.GetMinecraftEnum().ArmorSlotType.HEAD)
|
||
```
|
||
|
||
|
||
|
||
## SetEntityItem
|
||
|
||
<span style="display:inline;color:#ff5555">服务端</span>
|
||
|
||
method in mod.server.component.itemCompServer.ItemCompServer
|
||
|
||
- 描述
|
||
|
||
设置生物物品,建议开发者根据生物特性来进行设置,部分生物设置装备后可能不显示但是死亡后仍然会掉落所设置的装备
|
||
|
||
- 参数
|
||
|
||
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
|
||
| :--- | :--- | :--- |
|
||
| posType | int | [ItemPosType枚举](../../枚举值/ItemPosType.md) |
|
||
| itemDict | dict | 生物身上不同位置的<a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a>列表,如果传入None将清除当前位置的物品/装备 |
|
||
| slotPos | int | 容器槽位,如果ItemPosType为左右手可不传,如果ItemPosType为背包则对应背包槽位,如果ItemPosType为armor则对应装备位置,具体请看[ArmorSlotType枚举](../../枚举值/ArmorSlotType.md) |
|
||
|
||
- 返回值
|
||
|
||
| <div style="width: 4em">数据类型</div> | 说明 |
|
||
| :--- | :--- |
|
||
| bool | 设置成功返回True |
|
||
|
||
- 备注
|
||
- 设置生物背包目前支持驴、骡、羊驼以及其他带背包的自定义生物。该接口与spawnTo系列接口相比多了槽位限制,只能设置对应槽位的装备、左手物品,并且右手不能设置装备。溺尸暂不支持设置自定义装备。如果传入的itemDict为None或{},itemName为minecraft:air,count为0,均可以达到清除物品的效果。玩家背包请使用SpawnItemToPlayerInv来生成物品,使用SetInvItemNum设置0来清除物品,其他部位也可以用该接口设置。
|
||
- posType设置成serverApi.GetMinecraftEnum().ItemPosType.OFFHAND,itemDict设置成None可替代ClearPlayerOffHand
|
||
|
||
- 示例
|
||
|
||
```python
|
||
import mod.server.extraServerApi as serverApi
|
||
comp = serverApi.GetEngineCompFactory().CreateItem(entityId)
|
||
itemDict = {
|
||
'itemName': 'minecraft:bow',
|
||
'count': 1,
|
||
'enchantData': [(serverApi.GetMinecraftEnum().EnchantType.BowDamage, 1),],
|
||
'auxValue': 0,
|
||
'customTips':'§c new item §r',
|
||
'extraId': 'abc',
|
||
'userData': {},
|
||
}
|
||
comp.SetEntityItem(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, itemDict, 0)
|
||
|
||
#替代ClearPlayerOffHand接口的做法
|
||
comp.SetEntityItem(serverApi.GetMinecraftEnum().ItemPosType.OFFHAND, None, 0)
|
||
```
|
||
|
||
|
||
|