背包
GetEntityItem
服务端开发补充
能力:盔甲 · 实体 · 主手物品 · 物品 · 物品NBT · 副手物品
读取生物的背包、护甲或手持槽位物品。
- 物品的 NBT 即物品信息字典里的 userData,需传 getUserData=True 才返回。
服务端
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取生物物品,支持获取背包,盔甲栏,副手以及主手物品
- 参数
| 参数名 | 数据类型 | 说明 |
|---|---|---|
| posType | int | ItemPosType枚举 |
| slotPos | int | 槽位,获取INVENTORY及ARMOR时需要设置,其他情况写0即可 |
| getUserData | bool | 是否获取userData,默认为False |
- 返回值
| 数据类型 | 说明 |
|---|---|
| dict | 物品信息字典,没有物品则返回None |
备注
左右手及装备可以替代GetPlayerItem接口获取玩家的物品,但背包不行。获取生物背包目前支持驴、骡、羊驼以及其他带背包的自定义生物
3.8新增的收纳袋的userdata与箱子类的Items列表不同,它的格式为 {'bundle_weight': {'type': 3, 'value': 7}, 'storage_item_component_content': []} 其中bundle_weight表示收纳袋当前的重量值,示例表示它里面有7个普通可堆叠物品,而storage_item_component_content与箱子的Items类似,但即使槽位为空,它也包含64个元素
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(entityId)
comp.GetEntityItem(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 0)GetEquItemEnchant
服务端开发补充
能力:盔甲 · 附魔 · 附魔等级 · 实体
作用对象:盔甲
适用限定:盔甲
读取盔甲装备槽中的原版附魔。
服务端
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取装备槽位中盔甲的附魔
- 参数
| 参数名 | 数据类型 | 说明 |
|---|---|---|
| slotPos | int | ArmorSlotType枚举枚举 |
- 返回值
| 数据类型 | 说明 |
|---|---|
| list(tuple(int,int)) | 盔甲的附魔 |
备注
如果物品不存在,或者没有附魔值,返回None。如果存在返回tuple数组,每个tuple由附魔类型(EnchantType枚举)和附魔等级组成
示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.GetEquItemEnchant(serverApi.GetMinecraftEnum().ArmorSlotType.HEAD)GetEquItemModEnchant
服务端开发补充
读取盔甲装备槽中的自定义附魔。
服务端
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取装备槽位中盔甲的自定义附魔
- 参数
| 参数名 | 数据类型 | 说明 |
|---|---|---|
| slotPos | int | ArmorSlotType枚举枚举 |
- 返回值
| 数据类型 | 说明 |
|---|---|
| list(tuple(str,int)) | list中每个tuple由自定义附魔id和附魔等级组成,没有自定义附魔则返回空列表 |
- 示例
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.GetEquItemModEnchant(serverApi.GetMinecraftEnum().ArmorSlotType.HEAD)SetEntityItem
服务端开发补充
服务端
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
设置生物物品,建议开发者根据生物特性来进行设置,部分生物设置装备后可能不显示但是死亡后仍然会掉落所设置的装备
- 参数
| 参数名 | 数据类型 | 说明 |
|---|---|---|
| posType | int | ItemPosType枚举 |
| itemDict | dict | 生物身上不同位置的物品信息字典列表,如果传入None将清除当前位置的物品/装备 |
| slotPos | int | 容器槽位,如果ItemPosType为左右手可不传,如果ItemPosType为背包则对应背包槽位,如果ItemPosType为armor则对应装备位置,具体请看ArmorSlotType枚举 |
- 返回值
| 数据类型 | 说明 |
|---|---|
| bool | 设置成功返回True |
备注
设置生物背包目前支持驴、骡、羊驼以及其他带背包的自定义生物。该接口与spawnTo系列接口相比多了槽位限制,只能设置对应槽位的装备、左手物品,并且右手不能设置装备。溺尸暂不支持设置自定义装备。如果传入的itemDict为None或{},itemName为minecraft:air,count为0,均可以达到清除物品的效果。玩家背包请使用SpawnItemToPlayerInv来生成物品,使用SetInvItemNum设置0来清除物品,其他部位也可以用该接口设置。
posType设置成serverApi.GetMinecraftEnum().ItemPosType.OFFHAND,itemDict设置成None可替代ClearPlayerOffHand
示例
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)