Skip to content

物品 ​

索引 ​

包括物品属性的接口,物品的生成与获取见玩家/背包,实体/背包,方块/容器,物品实体的生成与获取见世界/实体管理

接口描述
BindItemToMinecraftModel客户端将指定物品作为附作物动态挂接到实体原版模型上,在实体原版模型上渲染指定物品。
BindItemToSkeletonModel客户端将指定物品作为附作物动态挂接到实体的网易版骨骼模型,在实体的网易版骨骼模型上指定骨骼渲染指定物品。
CancelShearsDestroyBlockSpeed服务端取消剪刀对某一方块的破坏速度设置
CancelShearsDestroyBlockSpeedAll服务端取消剪刀对全部方块的破坏速度设置
ChangeArmorTextures客户端修改盔甲在场景中显示和在UI中显示的贴图
ChangeItemTexture客户端替换物品的贴图,修改后所有用到该贴图的物品都会被改变,后续创建的此类物品也会被改变。会同时修改物品在UI界面上的显示,手持时候的显示与场景掉落的显示。
GetAllEnchantsInfo服务端获取目前已注册的所有附魔信息
GetAllEnchantsInfo客户端获取目前已注册的所有附魔信息
GetBindBoneForBindItem客户端查询获取实体上已绑定的物品附着物所绑定的骨骼名称。
GetBindItemOffset客户端查询获取实体上的物品附着物相对骨骼的位置偏移。
GetBindItemRotation客户端查询获取实体上的物品附着物相对骨骼的旋转角度。
GetBindItemScale客户端查询获取实体上的物品附着物的缩放比例。
GetCustomName服务端获取物品的自定义名称,与铁砧修改的名称一致
GetFishingLineColor服务端获取服务端当前设置的钓鱼线颜色
GetFishingLineColor客户端获取钓鱼线的颜色
GetFishingLineMax服务端获取服务端当前设置的钓鱼线最大长度
GetFishingLineMax客户端获取钓鱼线的最大长度
GetIconInfo客户端获取物品图标纹理在图集中的UV坐标位置与尺寸信息
GetItemBasicInfo服务端获取物品的基础信息
GetItemBasicInfo客户端获取物品的基础信息
GetItemDefenceAngle服务端获取盾牌物品的抵挡角度范围
GetItemDurability服务端获取指定槽位的物品耐久
GetItemEffectName客户端获取物品的状态描述,如:§7保护 0§r
GetItemFormattedHoverText客户端获取物品的格式化hover文本,如:§f灾厄旗帜§r
GetItemHoverName客户端获取物品的hover名称,如:灾厄旗帜§r
GetItemInfoByBlockName服务端通过方块名称及aux值获取物品信息
GetItemLayer服务端获取物品的叠加贴图。物品叠加贴图详见SetItemLayer
GetItemMaxDurability服务端获取指定槽位的物品耐最大耐久
GetItemTags服务端获取物品的tags列表,包含原版minecraft:tags中定义的tags,以及netease_tags中注册并挂载到物品上的自定义标签
GetItemTags客户端获取物品的tags列表,包含原版minecraft:tags中定义的tags,以及netease_tags中注册并挂载到物品上的自定义标签
GetItemTexture客户端获取item_texture.json中物品的贴图路径。
GetLoadItems服务端获取已经加载的物品id
GetUserDataInEvent服务端使物品相关服务端事件的物品信息字典参数带有userData。在mod初始化时调用即可
GetUserDataInEvent客户端使物品相关客户端事件的物品信息字典参数带有userData。在mod初始化时调用即可
LookupItemByName服务端判定指定identifier的物品是否存在
LookupItemsByItemTag服务端根据netease_tags中注册的物品tag名,查找该tag下所有物品,支持#引用的标签自动展开;同一tag名被多个模组注册时自动合并去重;未注册的原版tag可直接查询
LookupItemsByItemTag客户端根据netease_tags中注册的物品tag名,查找该tag下所有物品,支持#引用的标签自动展开;同一tag名被多个模组注册时自动合并去重;未注册的原版tag可直接查询
RemoveItemLayer服务端移除物品的叠加贴图。物品叠加贴图详见SetItemLayer
SetAttackDamage服务端设置物品的攻击伤害值
SetBindBoneForBindItem客户端改变实体上已绑定的物品附着物所绑定的骨骼,又或者移除该物品附着物。
SetBindItemOffset客户端设置实体上的物品附着物相对骨骼的位置偏移。
SetBindItemRotation客户端设置实体上的物品附着物相对骨骼的旋转角度。
SetBindItemScale客户端设置实体上的物品附着物的缩放比例。
SetCompassEntity客户端设置指南针朝向的实体
SetCompassTarget客户端设置指南针的朝向位置
SetCustomName服务端设置物品的自定义名称,与使用铁砧重命名一致
SetFishingLineColor服务端设置钓鱼线的颜色,设置后会自动同步到所有客户端。
SetFishingLineMax服务端设置钓鱼线的最大长度(超过此长度会断线),设置后会自动同步到所有客户端。
SetItemDefenceAngle服务端设置盾牌物品的抵挡角度范围
SetItemDurability服务端设置物品的耐久值
SetItemLayer服务端设置物品的叠加贴图,可以在物品的上层与下层叠加自定义贴图。具体使用可参考CustomItemsMod示例。
SetItemMaxDurability服务端设置物品的最大耐久值
SetItemTierLevel服务端设置工具类物品的挖掘等级
SetItemTierSpeed服务端设置工具类物品的挖掘速度(可通过userData中的ModTierSpeed获取挖掘速度)
SetMaxStackSize服务端设置物品的最大堆叠数量(存档)
SetShearsDestroyBlockSpeed服务端设置剪刀对某一方块的破坏速度

BindItemToMinecraftModel ​

客户端物品附着 原版模型 骨骼绑定开发补充

把物品作为附着物挂到实体原版模型上显示。

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

将指定物品作为附作物动态挂接到实体原版模型上,在实体原版模型上渲染指定物品。

  • 参数
参数名数据类型说明
entityIdstr需要挂接到的实体的id。
itemDictdict需要挂接的物品的信息字典。
boneNamestr需要挂接到的骨骼名称(不区分大小写),默认值为"root"
isClientEntitybool是否是客户端实体。如果实体是由CreateClientEntityByTypeStr接口创建的客户端实体,则需要传入True.默认为False
offsettuple(float,float,float)绑定物品的偏移量,相对绑定entity脚下中心,默认值为(0, 0, 0)
rotationtuple(float,float,float)绑定物品的三维旋转(单位为度,按照ZYX顺序旋转),默认值为(0, 0, 0)
scalefloat绑定物品的缩放比例。默认值为1.0
  • 返回值
数据类型说明
int绑定成功后,返回创建的物品模型id。失败则返回-1
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 在玩家的头部绑定一个附魔的金苹果
# 物品信息字典主要需要以下4个字段
itemDict = {
   "newItemName" : "minecraft:apple",     # 物品的identifier
   "newAuxValue" : 0,                     # 物品的auxvalue
   "isEnchanted" : True,                  # 是否附魔
   "userData":{}                          # 物品的userData,用于旗帜等物品
}
player_id = clientApi.GetLocalPlayerId()
itemModelId = comp.BindItemToMinecraftModel(player_id, itemDict, "head", False, (0,0,0), (0,0,0), 1.0)
print("Successfully bind item with id:", itemModelId)

BindItemToSkeletonModel ​

客户端物品附着 骨骼模型 骨骼绑定开发补充

能力:骨骼绑定 · 实体 · 物品

作用对象:实体

把物品挂到实体网易骨骼模型的指定骨骼上。

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

将指定物品作为附作物动态挂接到实体的网易版骨骼模型,在实体的网易版骨骼模型上指定骨骼渲染指定物品。

  • 参数
参数名数据类型说明
entityIdstr需要挂接到的实体的id。
itemDictdict需要挂接的物品的信息字典。
boneNamestr需要挂接到的骨骼名称(不区分大小写),默认值为"root"
isClientEntitybool是否是客户端实体。如果实体是由CreateClientEntityByTypeStr接口创建的客户端实体,则需要传入True.默认为False
offsettuple(float,float,float)绑定物品的偏移量,相对绑定的骨骼中心,默认值为(0, 0, 0)
rotationtuple(float,float,float)绑定物品的三维旋转(单位为度,按照ZYX顺序旋转),默认值为(0, 0, 0)
scalefloat绑定物品的缩放比例。默认值为1.0
  • 返回值
数据类型说明
int绑定成功后,返回创建的物品模型id。失败则返回-1
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 在玩家的头顶绑定一个附魔的金苹果
# 物品信息字典主要需要以下4个字段
itemDict = {
   "newItemName" : "minecraft:apple",     # 物品的identifier
   "newAuxValue" : 0,                     # 物品的auxvalue
   "isEnchanted" : True,                  # 是否附魔
   "userData":{}                          # 物品的userData,用于旗帜等物品
}
player_id = clientApi.GetLocalPlayerId()
itemModelId = comp.BindItemToSkeletonModel(player_id, itemDict, "head", False, (0,0,0), (0,0,0), 1.0)
print("Successfully bind item with id:", itemModelId)

CancelShearsDestroyBlockSpeed ​

服务端剪刀挖掘 破坏速度 设置取消开发补充

取消剪刀对指定方块的破坏速度覆盖。

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

取消剪刀对某一方块的破坏速度设置

  • 参数
参数名数据类型说明
blockNamestr方块名称,包含命名空间
  • 返回值
数据类型说明
bool设置是否成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(entityId)
comp.CancelShearsDestroyBlockSpeed("minecraft:obsidian")

CancelShearsDestroyBlockSpeedAll ​

服务端剪刀挖掘 破坏速度 全部重置开发补充

取消剪刀对全部方块的破坏速度覆盖。

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

取消剪刀对全部方块的破坏速度设置

  • 参数

无

  • 返回值
数据类型说明
bool设置是否成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(entityId)
comp.CancelShearsDestroyBlockSpeedAll()

ChangeArmorTextures ​

客户端盔甲贴图 纹理替换 外观设置开发补充

替换盔甲在世界和界面中的显示贴图。

客户端

method in mod.client.component.actorRenderCompClient.ActorRenderCompClient

  • 描述

修改盔甲在场景中显示和在UI中显示的贴图

  • 参数
参数名数据类型说明
armorIdentifierstr盔甲标识符,格式[namespace:name:auxvalue],auxvalue默认为0
texturesDictdict场景中目标贴图的映射表,格式可参考"definitions/attachables/diamond_helmet.json"配置
uiIconTexturestr盔甲UI图标的贴图, 为None或者""的话表示不修改UI上的图标
  • 返回值
数据类型说明
bool修改是否成功(因为采用延迟加载,此处返回成功不代表参数中的贴图路径正确,路径错误会导致渲染时贴图丢失显示异常)
  • 备注

  • 无法跟物品的贴图动画同时使用

  • 有一定性能消耗,不建议频繁调用

  • 示例

python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateActorRender(levelId)
# 修改钻石头盔的显示为黄金头盔
textureDict = {
    "default": "textures/models/armor/gold_1",
    "enchanted": "textures/misc/enchanted_item_glint"
}
print(comp.ChangeArmorTextures("minecraft:diamond_helmet", textureDict, "textures/items/gold_helmet"))

ChangeItemTexture ​

客户端物品贴图 纹理替换 外观设置开发补充

替换物品共享贴图,影响界面、手持和掉落显示。

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

替换物品的贴图,修改后所有用到该贴图的物品都会被改变,后续创建的此类物品也会被改变。会同时修改物品在UI界面上的显示,手持时候的显示与场景掉落的显示。

  • 参数
参数名数据类型说明
identifierstr物品标识符,格式[namespace:name:auxvalue],auxvalue默认为0
texturePathstr贴图路径
  • 返回值
数据类型说明
bool是否修改成功(因为采用延迟加载,此处返回成功不代表贴图路径正确,路径错误会导致渲染时贴图丢失显示异常)
  • 备注

  • 因为会同时修改用到此贴图的所有物品,所以使用的时候尽量谨慎,不建议改原版的物品,建议只用于修改用到自定义新贴图的物品。

  • 序列帧贴图物品暂不支持动态修改贴图

  • 部分物品有特殊逻辑无法修改:箱子,旗帜,生物头颅,盾牌,三叉戟,鱼杆

  • 示例

python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
print(comp.ChangeItemTexture("mytool:hatchet_1:0", "textures/items/hatchet_1"))

GetAllEnchantsInfo ​

服务端附魔信息 附魔枚举 注册查询开发补充

读取当前已注册的全部附魔信息。

客户端附魔信息 附魔枚举 注册查询开发补充

读取当前已注册的全部附魔信息。

服务端客户端

服务端接口 ​

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

获取目前已注册的所有附魔信息

  • 参数

无

  • 返回值
数据类型说明
list(dict)附魔信息字典附魔信息字典
  • 备注

  • 1.目前能获取原生及自定义附魔信息 2.由于原生附魔的消耗存在不相同的计算规则,目前不提供原生附魔的costs信息

  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
comp.GetAllEnchantsInfo()

客户端接口 ​

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

获取目前已注册的所有附魔信息

  • 参数

无

  • 返回值
数据类型说明
list(dict)附魔信息字典附魔信息字典
  • 备注

  • 1.目前能获取原生及自定义附魔信息 2.由于原生附魔的消耗存在不相同的计算规则,目前不提供原生附魔的costs信息

  • 示例

python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
comp.GetAllEnchantsInfo()

GetBindBoneForBindItem ​

客户端物品附着 绑定骨骼 参数读取开发补充

读取物品附着的绑定骨骼。

关联接口:SetBindBoneForBindItem (client)

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

查询获取实体上已绑定的物品附着物所绑定的骨骼名称。

  • 参数
参数名数据类型说明
entityIdstr需要查询的实体的id。
itemModelIdint需要查询的物品模型id。
isClientEntitybool是否是客户端实体。如果实体是由CreateClientEntityByTypeStr接口创建的客户端实体,则需要传入True.默认为False
  • 返回值
数据类型说明
str绑定的骨骼名称。查询失败返回None
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 在玩家的头部绑定一个附魔的金苹果
# 物品信息字典主要需要以下4个字段
itemDict = {
   "newItemName" : "minecraft:apple",     # 物品的identifier
   "newAuxValue" : 0,                     # 物品的auxvalue
   "isEnchanted" : True,                  # 是否附魔
   "userData":{}                          # 物品的userData,用于旗帜等物品
}
player_id = clientApi.GetLocalPlayerId()
itemModelId = comp.BindItemToMinecraftModel(player_id, itemDict, "head", False, (0,0,0), (0,0,0), 1.0)
print("Successfully bind item with id:", itemModelId)
# 使这个苹果绑定到手部
comp.SetBindBoneForBindItem(player_id, itemModelId, "rightarm")
# 获取当前绑定的骨骼名称
boneName = comp.GetBindBoneForBindItem(player_id, itemModelId)
print("The bone name of the bind item is:", boneName)

GetBindItemOffset ​

客户端物品附着 位置偏移 参数读取开发补充

读取物品附着的位置偏移。

关联接口:SetBindItemOffset (client)

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

查询获取实体上的物品附着物相对骨骼的位置偏移。

  • 参数
参数名数据类型说明
entityIdstr需要查询的实体的id。
itemModelIdint需要查询的物品模型id。
isClientEntitybool是否是客户端实体。如果实体是由CreateClientEntityByTypeStr接口创建的客户端实体,则需要传入True.默认为False
  • 返回值
数据类型说明
tuple(float,float,float)物品的位置偏移,查询如果失败返回None
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 在玩家的头部绑定一个附魔的金苹果
# 物品信息字典主要需要以下4个字段
itemDict = {
   "newItemName" : "minecraft:apple",     # 物品的identifier
   "newAuxValue" : 0,                     # 物品的auxvalue
   "isEnchanted" : True,                  # 是否附魔
   "userData":{}                          # 物品的userData,用于旗帜等物品
}
player_id = clientApi.GetLocalPlayerId()
itemModelId = comp.BindItemToMinecraftModel(player_id, itemDict, "head", False, (0,0,0), (0,0,0), 1.0)
print("Successfully bind item with id:", itemModelId)
# 使这个苹果往x方向偏移10个单位
offset = comp.GetBindItemOffset(player_id, itemModelId)
print("offset is:", offset)

GetBindItemRotation ​

客户端物品附着 旋转角度 参数读取开发补充

读取物品附着的旋转角度。

关联接口:SetBindItemRotation (client)

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

查询获取实体上的物品附着物相对骨骼的旋转角度。

  • 参数
参数名数据类型说明
entityIdstr需要查询的实体的id。
itemModelIdint需要查询物品模型id。
isClientEntitybool是否是客户端实体。如果实体是由CreateClientEntityByTypeStr接口创建的客户端实体,则需要传入True.默认为False
  • 返回值
数据类型说明
tuple(float,float,float)返回物品的三维旋转,查询如果失败返回None
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 在玩家的头部绑定一个附魔的金苹果
# 物品信息字典主要需要以下4个字段
itemDict = {
   "newItemName" : "minecraft:apple",     # 物品的identifier
   "newAuxValue" : 0,                     # 物品的auxvalue
   "isEnchanted" : True,                  # 是否附魔
   "enchantData" : [],                    # 附魔信息
   "userData":{}                          # 物品的userData,用于旗帜等物品
}
player_id = clientApi.GetLocalPlayerId()
itemModelId = comp.BindItemToMinecraftModel(player_id, itemDict, "head", False, (0,0,0), (0,0,0), 1.0)
print("Successfully bind item with id:", itemModelId)
# 获取这个苹果旋转角度
rotation = comp.GetBindItemRotation(player_id, itemModelId)
print("rotation is:", rotation)

GetBindItemScale ​

客户端物品附着 缩放比例 参数读取开发补充

读取物品附着的缩放比例。

关联接口:SetBindItemScale (client)

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

查询获取实体上的物品附着物的缩放比例。

  • 参数
参数名数据类型说明
entityIdstr需要查询的实体的id。
itemModelIdint需要查询的物品模型id。
isClientEntitybool是否是客户端实体。如果实体是由CreateClientEntityByTypeStr接口创建的客户端实体,则需要传入True.默认为False
  • 返回值
数据类型说明
float绑定物品的缩放比例。查询如果失败返回None
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 在玩家的头部绑定一个附魔的金苹果
# 物品信息字典主要需要以下4个字段
itemDict = {
   "newItemName" : "minecraft:apple",     # 物品的identifier
   "newAuxValue" : 0,                     # 物品的auxvalue
   "isEnchanted" : True,                  # 是否附魔
   "userData":{}                          # 物品的userData,用于旗帜等物品
}
player_id = clientApi.GetLocalPlayerId()
itemModelId = comp.BindItemToMinecraftModel(player_id, itemDict, "head", False, (0,0,0), (0,0,0), 1.0)
print("Successfully bind item with id:", itemModelId)
# 使这个苹果变大1.5倍
scale = comp.GetBindItemScale(player_id, itemModelId)
print("scale is:", scale)

GetCustomName ​

服务端物品名称 自定义名称 名称读取开发补充

读取物品自定义名称,与铁砧重命名对应。

关联接口:SetCustomName (server)

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

获取物品的自定义名称,与铁砧修改的名称一致

  • 参数
参数名数据类型说明
itemDictdict物品信息字典。如果是接口获取的itemDict,应该包含userData,即getUserData应该为True
  • 返回值
数据类型说明
str自定义名称
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
itemDict = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
name = comp.GetCustomName(itemDict)

GetFishingLineColor ​

服务端钓鱼线 颜色读取 外观查询开发补充

读取当前钓鱼线颜色。

关联接口:SetFishingLineColor (server) · SetFishingLineColor (server)

客户端钓鱼线 颜色读取 外观查询开发补充

读取当前钓鱼线颜色。

服务端客户端

服务端接口 ​

method in mod.server.component.fishingLineCompServer.FishingLineCompServer

  • 描述

获取服务端当前设置的钓鱼线颜色

  • 参数
参数名数据类型说明
itemNamestr鱼竿物品的完整名称,如 "minecraft:fishing_rod" 或自定义鱼竿名称
  • 返回值
数据类型说明
tuple(float,float,float)rgb颜色值,每个分量0.0-1.0
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFishingLine(playerId)
color = comp.GetFishingLineColor("mymod:custom_fishing_rod")
print color

客户端接口 ​

method in mod.client.component.fishingLineCompClient.FishingLineCompClient

  • 描述

获取钓鱼线的颜色

  • 参数
参数名数据类型说明
itemNamestr鱼竿物品的完整名称,如 "minecraft:fishing_rod" 或自定义鱼竿名称
  • 返回值
数据类型说明
tuple(float,float,float)rgb颜色值,每个分量0.0-1.0
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateFishingLine(playerId)
color = comp.GetFishingLineColor("mymod:custom_fishing_rod")
print color

GetFishingLineMax ​

服务端钓鱼线 长度上限 长度读取开发补充

读取钓鱼线最大长度。

关联接口:SetFishingLineMax (server) · SetFishingLineMax (server)

客户端钓鱼线 长度上限 长度读取开发补充

读取钓鱼线最大长度。

服务端客户端

服务端接口 ​

method in mod.server.component.fishingLineCompServer.FishingLineCompServer

  • 描述

获取服务端当前设置的钓鱼线最大长度

  • 参数
参数名数据类型说明
itemNamestr鱼竿物品的完整名称,如 "minecraft:fishing_rod" 或自定义鱼竿名称
  • 返回值
数据类型说明
float最大长度,单位为格
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFishingLine(playerId)
maxLen = comp.GetFishingLineMax("mymod:custom_fishing_rod")

客户端接口 ​

method in mod.client.component.fishingLineCompClient.FishingLineCompClient

  • 描述

获取钓鱼线的最大长度

  • 参数
参数名数据类型说明
itemNamestr鱼竿物品的完整名称,如 "minecraft:fishing_rod" 或自定义鱼竿名称
  • 返回值
数据类型说明
float最大长度,单位为格
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateFishingLine(playerId)
maxLen = comp.GetFishingLineMax("mymod:custom_fishing_rod")

GetIconInfo ​

客户端物品图标 纹理图集 图标坐标 图集坐标开发补充

能力:图集UV

按物品名与附加值读取物品图标在图集中的归一化UV与尺寸;方块类物品在atlas.terrain、普通物品在atlas.items。按贴图键查方块贴图用GetTextureAtlasUV。

  • 返回值不含图集名:方块类物品图标位于atlas.terrain,普通物品位于atlas.items。
  • 获取失败返回None。

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

获取物品图标纹理在图集中的UV坐标位置与尺寸信息

  • 参数
参数名数据类型说明
itemDictdict物品信息字典,格式
  • 返回值
数据类型说明
tuple(float,float,float,float)物品图标在图集中的UV坐标与尺寸(u0,v0,w,h),u0,v0为左上角归一化UV坐标,w为纹理宽度,h为纹理高度。获取失败返回None
  • 备注

  • 获取的是物品图标所在图集的UV信息,方块类物品的图标位于atlas.terrain图集,普通物品图标位于atlas.items图集,两者返回的均为归一化UV坐标

  • 示例

python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
uv = comp.GetIconInfo({"itemName": "minecraft:apple", "auxValue": 0})
# uv = (0.1064453125, 0.0009765625, 0.015625, 0.015625)

GetItemBasicInfo ​

服务端物品属性 基础信息 属性读取开发补充

能力:攻击力 · 物品 · 堆叠上限

读取物品基础信息。

客户端物品属性 基础信息 属性读取开发补充

能力:攻击力 · 物品 · 堆叠上限

读取物品基础信息。

服务端客户端

服务端接口 ​

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

获取物品的基础信息

  • 参数
参数名数据类型说明
itemNamestritem的identifier
auxValueint物品的附加值auxvalue,默认为0
isEnchantedbool是否附魔,默认为False。用于返回的id_aux
  • 返回值
数据类型说明
dict基础信息,详见备注
  • 备注

  • auxValue默认值是0,可以不设置。如果物品不存在,返回值为None

关键字数据类型说明
itemNamestr本地化的物品名字
maxStackSizeint物品最大堆叠数目
maxDurabilityint物品最大耐久值
id_auxint主要用于客户端的ui绑定,详见客户端接口
tierDictdict自定义方块定义的挖掘相关的属性 netease:tier,没有设置时返回None
itemCategorystr创造栏分类
itemTypestr物品类型
customItemTypestr自定义物品类型
tagslist(str)物品的tags列表,如['minecraft:is_food']
customTipsstr自定义物品/方块tips
itemTierLevelint工具等级
fuelDurationfloat燃料时长
foodNutritionint食物营养值
foodSaturationfloat食物饱食度
weaponDamageint武器攻击力
armorDefenseint防具防御力
armorSlotint防具槽位
armorToughnessint防具韧性
armorKnockbackResistancefloat防具击退抗性
enchant_slot_typeint附魔槽位枚举标志 自定义附魔文档
  • 部分原版物品较为特殊,获取不到个别字段的返回值 方块类燃料获取不到燃料时长,弓、弩获取不到武器攻击力,蛋糕获取不到营养值和饱食度,马铠获取不到防具防御力,上述物品获取对应字段返回值为0

  • 创造栏分类说明

创造栏分类意义
construction建筑
nature自然
equipment装备
items物品
custom自定义
空字符串不在创造栏
  • 物品类型,值为空字符串或者下列类型名之一:
类型名意义
book书
sword剑
shears剪刀
axe斧头
clock时钟
bucket桶
fishing_rod钓鱼竿
hoe锄头
shovel锹
pickaxe镐
dye骨粉
food食物
block方块
armor盔甲
custom_ranged_weapon自定义远程武器
compass指南针
trident三叉戟
potion药水
crossbow弩
  • 自定义物品类型物品类型,值为行为包里minecraft:item内description的custom_item_type字段值

  • 工具等级代表不同的材质,没有工具等级时为值-1,工具等级与材质对应关系如下

工具等级材质
0木制/金制工具
1石制工具
2铁制工具
3钻石工具
4合金工具
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
info = comp.GetItemBasicInfo("minecraft:bow")
enchant_slot_type = info["enchant_slot_type"]
support_sword = (enchant_slot_type & EnchantSlotType.SWORD) > 0

客户端接口 ​

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

获取物品的基础信息

  • 参数
参数名数据类型说明
itemNamestritem的identifier
auxValueint物品的附加值auxvalue,默认为0
isEnchantedbool是否附魔,默认为False。用于返回的id_aux
  • 返回值
数据类型说明
dict基础信息字典,见备注
  • 备注

  • auxValue默认值是0,可以不设置。如果物品不存在,返回值为None

关键字数据类型说明
itemNamestr本地化的物品名字
maxStackSizeint物品最大堆叠数目
maxDurabilityint物品最大耐久值
id_auxint用于给UI的inventory_item_renderer类型控件绑定#item_id_aux字段,详见备注
tierDictdict自定义方块定义的挖掘相关的属性 netease:tier,没有设置时返回None
itemCategorystr创造栏分类
itemTypestr物品类型
customItemTypestr自定义物品类型
tagslist(str)物品的tags列表,如['minecraft:is_food']
customTipsstr自定义物品/方块tips
itemTierLevelint工具等级
fuelDurationfloat燃料时长
foodNutritionint食物营养值
foodSaturationfloat食物饱食度
weaponDamageint武器攻击力
armorDefenseint防具防御力
armorSlotint防具槽位
armorToughnessint防具韧性
armorKnockbackResistancefloat防具击退抗性
enchant_slot_typeint附魔槽位枚举标志 自定义附魔文档
  • 部分原版物品较为特殊,获取不到个别字段的返回值 方块类燃料获取不到燃料时长,弓、弩获取不到武器攻击力,蛋糕获取不到营养值和饱食度,马铠获取不到防具防御力,上述物品获取对应字段返回值为0

  • id_aux字段的示例: 在ui中添加一个inventory_item_renderer控件以及#item_id_aux的绑定

"my_item_renderer": {
    "type": "custom",
    "renderer": "inventory_item_renderer",
    "size": [ 160, 160 ],
    "bindings" : [
        {
            "binding_condition" : "always_when_visible",
            "binding_name" : "#GetItemIdAux",
            "binding_name_override" : "#item_id_aux"
        }
    ]
}

然后在python中添加绑定回调

python
@ViewBinder.binding(ViewBinder.BF_BindInt, "#GetItemIdAux")
def OnStarkGridResize(self):
    comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
    info = comp.GetItemBasicInfo("minecraft:bow", 0, True)
    return info['id_aux']
  • 创造栏分类说明
创造栏分类意义
construction建筑
nature自然
equipment装备
items物品
custom自定义
  • 物品类型,值为空字符串或者下列类型名之一:
类型名意义
book书
sword剑
shears剪刀
axe斧头
clock时钟
bucket桶
fishing_rod钓鱼竿
hoe锄头
shovel锹
pickaxe镐
dye骨粉
food食物
block方块
armor盔甲
custom_ranged_weapon自定义远程武器
compass指南针
trident三叉戟
potion药水
crossbow弩
  • 自定义物品类型物品类型,值为行为包里minecraft::item内的custom_item_type字段值

  • 工具等级代表不同的材质,没有工具等级时为值-1,工具等级与材质对应关系如下

工具等级材质
0木制/金制工具
1石制工具
2铁制工具
3钻石工具
4合金工具
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
info = comp.GetItemBasicInfo("minecraft:bow")
enchant_slot_type = info["enchant_slot_type"]
support_sword = (enchant_slot_type & EnchantSlotType.SWORD) > 0

GetItemDefenceAngle ​

服务端盾牌格挡 抵挡角度 参数读取开发补充

读取盾牌格挡的抵挡角度。

关联接口:SetItemDefenceAngle (server)

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

获取盾牌物品的抵挡角度范围

  • 参数
参数名数据类型说明
posTypeintItemPosType枚举
slotPosint槽位
  • 返回值
数据类型说明
list(float)角度范围
  • 备注

  • 当传入的玩家id不正确,玩家手里没手持盾牌,传入不存在的槽位时,会返回空列表

  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.GetItemDefenceAngle(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 0)

GetItemDurability ​

服务端物品耐久 耐久读取 槽位查询开发补充

能力:耐久度 · 物品

读取指定物品位置的当前耐久;修改耐久时需另行计算目标值并写入。

  • 槽位对背包和盔甲栏才有意义;读取当前耐久不等于读取最大耐久。

关联接口:SetItemDurability (server) · GetPlayerItem (server) · ItemPosType (common)

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

获取指定槽位的物品耐久

  • 参数
参数名数据类型说明
posTypeintItemPosType枚举
slotPosint槽位,当posType为ItemPosType.INVENTORY或ItemPosType.ARMOR时才有意义
  • 返回值
数据类型说明
int物品的耐久值
  • 备注

  • posType设置成serverApi.GetMinecraftEnum().ItemPosType.INVENTORY可替代GetInvItemDurability;posType设置成serverApi.GetMinecraftEnum().ItemPosType.ARMOR可替代GetEquItemDurability;

  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.GetItemDurability(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 1)

#替代GetInvItemDurability的方法
comp.GetItemDurability(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 1)

#替代GetEquItemDurability的方法
comp.GetItemDurability(serverApi.GetMinecraftEnum().ItemPosType.ARMOR, 1)

GetItemEffectName ​

客户端物品描述 状态文字 文本读取开发补充

读取物品状态效果描述文字。

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

获取物品的状态描述,如:§7保护 0§r

  • 参数
参数名数据类型说明
itemNamestritem的identifier
auxValueint物品的附加值auxValue,默认为不指定auxValue(0)
userDatadict物品userData,默认为None
  • 返回值
数据类型说明
str物品的状态描述
  • 示例
python
# 灾厄旗帜
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
comp.GetItemEffectName("minecraft:banner", 15, {'Type': 1})

GetItemFormattedHoverText ​

客户端物品悬浮文本 格式化文字 文本读取开发补充

读取带格式的物品悬浮说明。

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

获取物品的格式化hover文本,如:§f灾厄旗帜§r

  • 参数
参数名数据类型说明
itemNamestritem的identifier
auxValueint物品的附加值auxValue,默认为不指定auxValue(0)
showCategorybool是否包括item的类别信息,默认False
userDatadict物品userData,默认为None
  • 返回值
数据类型说明
str物品的格式化hover文本
  • 示例
python
# 灾厄旗帜
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
comp.GetItemFormattedHoverText("minecraft:banner", 15, True, {'Type': 1})

GetItemHoverName ​

客户端物品悬浮文本 物品名称 名称读取开发补充

读取物品显示用的悬浮名称。

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

获取物品的hover名称,如:灾厄旗帜§r

  • 参数
参数名数据类型说明
itemNamestritem的identifier
auxValueint物品的附加值auxValue,默认为不指定auxValue(0)
userDatadict物品userData,默认为None
  • 返回值
数据类型说明
str物品hover名称
  • 示例
python
# 灾厄旗帜
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
comp.GetItemHoverName("minecraft:banner", 15, {'Type': 1})

GetItemInfoByBlockName ​

服务端方块物品 类型转换 物品查询开发补充

根据方块名称和附加值查询对应物品信息。

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

通过方块名称及aux值获取物品信息

  • 参数
参数名数据类型说明
blockNamestr方块identifier
auxValueintaux值
isLegacybool方块是否为原生方块,默认为True,即使用旧版aux对应的state
  • 返回值
数据类型说明
dict物品信息字典
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
blockDict = comp.GetItemInfoByBlockName("minecraft:stone")

GetItemLayer ​

服务端物品贴图 叠加图层 图层读取开发补充

读取物品叠加贴图层。

关联接口:SetItemLayer (server)

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

获取物品的叠加贴图。物品叠加贴图详见SetItemLayer

  • 参数
参数名数据类型说明
itemDictdict物品信息字典
layerint贴图的层级。可以为-2,-1,1,2,3。
  • 返回值
数据类型说明
str贴图的名字,不存在返回None
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
itemDict = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
texture = comp.GetItemLayer(itemDict, 1)

GetItemMaxDurability ​

服务端物品耐久 耐久上限 上限读取开发补充

读取指定槽位物品的最大耐久。

关联接口:SetItemMaxDurability (server)

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

获取指定槽位的物品耐最大耐久

  • 参数
参数名数据类型说明
posTypeintItemPosType枚举
slotPosint槽位,当posType为ItemPosType.INVENTORY或ItemPosType.ARMOR时才有意义
isUserDatabool如果为True,则只尝试获取该物品userData特殊设置的值,没有特殊设置过则返回0。如果为False,则会先尝试获取userData中的值,没有的话获取该类物品通用值。
  • 返回值
数据类型说明
int物品的最大耐久
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.GetItemMaxDurability(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 1, False)

GetItemTags ​

服务端物品标签 类型分类 标签读取开发补充

读取物品资源中定义的标签列表。

客户端物品标签 类型分类 标签读取开发补充

读取物品资源中定义的标签列表。

服务端客户端

服务端接口 ​

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

获取物品的tags列表,包含原版minecraft:tags中定义的tags,以及netease_tags中注册并挂载到物品上的自定义标签

  • 参数
参数名数据类型说明
itemNamestritem的identifier
auxValueint物品的附加值auxValue,默认为不指定auxValue(0)
  • 返回值
数据类型说明
list(str)物品tags列表
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
comp.GetItemTags("minecraft:apple")

客户端接口 ​

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

获取物品的tags列表,包含原版minecraft:tags中定义的tags,以及netease_tags中注册并挂载到物品上的自定义标签

  • 参数
参数名数据类型说明
itemNamestritem的identifier
auxValueint物品的附加值auxValue,默认为不指定auxValue(0)
  • 返回值
数据类型说明
list(str)物品tags列表
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
comp.GetItemTags("minecraft:apple")

GetItemTexture ​

客户端物品贴图 资源路径 路径读取开发补充

读取物品纹理定义中的贴图路径。

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

获取item_texture.json中物品的贴图路径。

  • 参数
参数名数据类型说明
identifierstr物品标识符,格式[namespace:name:auxvalue],auxvalue默认为0
  • 返回值
数据类型说明
str物品的贴图路径
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
print(comp.GetItemTexture("mytool:hatchet_1:0"))

GetLoadItems ​

服务端物品注册 标识枚举 加载查询开发补充

列出已加载的物品类型标识。

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

获取已经加载的物品id

  • 参数
参数名数据类型说明
flagboolTrue获取所有物品,False仅获取注册到创造栏的物品,默认为True
  • 返回值
数据类型说明
list(str)物品id列表
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
itemName = comp.GetLoadItems(True)

GetUserDataInEvent ​

服务端物品事件 附加数据 事件配置开发补充

在模组初始化时启用物品事件参数中的附加数据。

客户端物品事件 附加数据 事件配置开发补充

在模组初始化时启用物品事件参数中的附加数据。

服务端客户端

服务端接口 ​

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

使物品相关服务端事件的物品信息字典参数带有userData。在mod初始化时调用即可

  • 参数
参数名数据类型说明
eventNamestr引擎事件名
  • 返回值
数据类型说明
bool是否成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
# 这样调用之后,PlayerEatFoodServerEvent事件的itemDict参数会带有userData字段
comp.GetUserDataInEvent("PlayerEatFoodServerEvent")

客户端接口 ​

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

使物品相关客户端事件的物品信息字典参数带有userData。在mod初始化时调用即可

  • 参数
参数名数据类型说明
eventNamestr引擎事件名
  • 返回值
数据类型说明
bool是否成功
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 这样调用之后,ActorAcquiredItemClientEvent事件的itemDict参数会带有userData字段
comp.GetUserDataInEvent("ActorAcquiredItemClientEvent")

LookupItemByName ​

服务端物品注册 类型检查 存在判断开发补充

判断指定物品标识是否存在。

服务端

method in mod.server.component.gameCompServer.GameComponentServer

  • 描述

判定指定identifier的物品是否存在

  • 参数
参数名数据类型说明
itemNamestr物品的identifier。类似"minecraft:bed",支持自定义物品
  • 返回值
数据类型说明
boolTrue为对应的物品存在,False为对应物品不存在
  • 示例
python
import mod.server.extraServerApi as serverApi
gameComp = serverApi.GetEngineCompFactory().CreateGame(levelId)
exist = gameComp.LookupItemByName("minecraft:bed")

LookupItemsByItemTag ​

服务端物品标签 按标签查物品 标签查询 物品分类开发补充

服务端按物品标签名列出该标签下全部物品名,自动展开#引用并合并多模组注册,原版标签也可查;反向查某物品有哪些标签用GetItemTags。

  • 返回list(dict),每项为含itemName键的物品名。
  • 物品标签与方块标签相互独立,identifier相同也不互通。
客户端物品标签 按标签查物品 标签查询 物品分类开发补充

客户端按物品标签名列出该标签下全部物品名,自动展开#引用并合并多模组注册,原版标签也可查;反向查某物品有哪些标签用GetItemTags。

  • 返回list(dict),每项为含itemName键的物品名。
  • 物品标签与方块标签相互独立,identifier相同也不互通。

服务端客户端

服务端接口 ​

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

根据netease_tags中注册的物品tag名,查找该tag下所有物品,支持#引用的标签自动展开;同一tag名被多个模组注册时自动合并去重;未注册的原版tag可直接查询

  • 参数
参数名数据类型说明
itemTagstr物品tag名,如 common:apple
  • 返回值
数据类型说明
list(dict)物品字典列表,dict包含itemName键
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
comp.LookupItemsByItemTag("common:apple")

客户端接口 ​

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

根据netease_tags中注册的物品tag名,查找该tag下所有物品,支持#引用的标签自动展开;同一tag名被多个模组注册时自动合并去重;未注册的原版tag可直接查询

  • 参数
参数名数据类型说明
itemTagstr物品tag名,如 common:apple
  • 返回值
数据类型说明
list(dict)物品字典列表,dict包含itemName键
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
comp.LookupItemsByItemTag("common:apple")

RemoveItemLayer ​

服务端物品贴图 叠加图层 图层移除开发补充

移除物品叠加贴图。

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

移除物品的叠加贴图。物品叠加贴图详见SetItemLayer

  • 参数
参数名数据类型说明
itemDictdict物品信息字典
layerint贴图的层级。可以为-2,-1,1,2,3。
  • 返回值
数据类型说明
bool是否成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
itemDict = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
success = comp.RemoveItemLayer(itemDict, 1)
if success:
    comp.SpawnItemToPlayerCarried(itemDict, playerId)

SetAttackDamage ​

服务端物品攻击 伤害数值 属性设置开发补充

设置物品的攻击伤害值。

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

设置物品的攻击伤害值

  • 参数
参数名数据类型说明
itemDictdict物品信息字典
attackDamageint攻击伤害值
  • 返回值
数据类型说明
bool设置是否成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
itemDict = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
success = comp.SetAttackDamage(itemDict, 5)
if success:
    comp.SpawnItemToPlayerCarried(itemDict, playerId)

SetBindBoneForBindItem ​

客户端物品附着 绑定骨骼 参数设置开发补充

设置物品附着的绑定骨骼。

关联接口:GetBindBoneForBindItem (client)

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

改变实体上已绑定的物品附着物所绑定的骨骼,又或者移除该物品附着物。

  • 参数
参数名数据类型说明
entityIdstr需要设置的实体的id。
itemModelIdint需要设置的物品模型id。
boneNamestr需要挂接到的骨骼名称(不区分大小写)。如果传入空字符串,则移除该物品附着物。
isClientEntitybool是否是客户端实体。如果实体是由CreateClientEntityByTypeStr接口创建的客户端实体,则需要传入True.默认为False
  • 返回值
数据类型说明
bool操作成功后返回True
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 在玩家的头部绑定一个附魔的金苹果
# 物品信息字典主要需要以下4个字段
itemDict = {
   "newItemName" : "minecraft:apple",     # 物品的identifier
   "newAuxValue" : 0,                     # 物品的auxvalue
   "isEnchanted" : True,                  # 是否附魔
   "userData":{}                          # 物品的userData,用于旗帜等物品
}
player_id = clientApi.GetLocalPlayerId()
itemModelId = comp.BindItemToMinecraftModel(player_id, itemDict, "head", False, (0,0,0), (0,0,0), 1.0)
print("Successfully bind item with id:", itemModelId)
# 使这个苹果绑定到手部
comp.SetBindBoneForBindItem(player_id, itemModelId, "rightarm")
# 移除这个苹果
comp.SetBindBoneForBindItem(player_id, itemModelId, "")

SetBindItemOffset ​

客户端物品附着 位置偏移 参数设置开发补充

设置物品附着的位置偏移。

关联接口:GetBindItemOffset (client)

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

设置实体上的物品附着物相对骨骼的位置偏移。

  • 参数
参数名数据类型说明
entityIdstr需要设置的实体的id。
itemModelIdint需要设置的物品模型id。
offsettuple(float,float,float)需要设置物品的位置偏移
isClientEntitybool是否是客户端实体。如果实体是由CreateClientEntityByTypeStr接口创建的客户端实体,则需要传入True.默认为False
  • 返回值
数据类型说明
bool设置是否成功,成功返回True
  • 备注

  • 1.物品的偏移方向是相对于骨骼的,因此对于不同的骨骼,其偏移方向可能不同。

  • 示例

python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 在玩家的头部绑定一个附魔的金苹果
# 物品信息字典主要需要以下4个字段
itemDict = {
   "newItemName" : "minecraft:apple",     # 物品的identifier
   "newAuxValue" : 0,                     # 物品的auxvalue
   "isEnchanted" : True,                  # 是否附魔
   "userData":{}                          # 物品的userData,用于旗帜等物品
}
player_id = clientApi.GetLocalPlayerId()
itemModelId = comp.BindItemToMinecraftModel(player_id, itemDict, "head", False, (0,0,0), (0,0,0), 1.0)
print("Successfully bind item with id:", itemModelId)
# 使这个苹果往y方向偏移0.5个单位
comp.SetBindItemOffset(player_id, itemModelId, (0, 0.5, 0))

SetBindItemRotation ​

客户端物品附着 旋转角度 参数设置开发补充

设置物品附着的旋转角度。

关联接口:GetBindItemRotation (client)

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

设置实体上的物品附着物相对骨骼的旋转角度。

  • 参数
参数名数据类型说明
entityIdstr需要设置的实体的id。
itemModelIdint需要设置的物品模型id。
rotationtuple(float,float,float)需要设置物品的三维旋转(单位为度,按照ZYX顺序旋转)
isClientEntitybool是否是客户端实体。如果实体是由CreateClientEntityByTypeStr接口创建的客户端实体,则需要传入True.默认为False
  • 返回值
数据类型说明
bool设置是否成功,成功返回True
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 在玩家的头部绑定一个附魔的金苹果
# 物品信息字典主要需要以下4个字段
itemDict = {
   "newItemName" : "minecraft:apple",     # 物品的identifier
   "newAuxValue" : 0,                     # 物品的auxvalue
   "isEnchanted" : True,                  # 是否附魔
   "userData":{}                          # 物品的userData,用于旗帜等物品
}
player_id = clientApi.GetLocalPlayerId()
itemModelId = comp.BindItemToMinecraftModel(player_id, itemDict, "head", False, (0,0,0), (0,0,0), 1.0)
print("Successfully bind item with id:", itemModelId)
# 使这个苹果绕y轴旋转90度
comp.SetBindItemRotation(player_id, itemModelId, (0, 90, 0))

SetBindItemScale ​

客户端物品附着 缩放比例 参数设置开发补充

设置物品附着的缩放比例。

关联接口:GetBindItemScale (client)

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

设置实体上的物品附着物的缩放比例。

  • 参数
参数名数据类型说明
entityIdstr需要设置的实体的id。
itemModelIdint需要设置的物品模型id。
scalefloat绑定物品的缩放比例。
isClientEntitybool是否是客户端实体。如果实体是由CreateClientEntityByTypeStr接口创建的客户端实体,则需要传入True.默认为False
  • 返回值
数据类型说明
bool设置是否成功,成功返回True
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(levelId)
# 在玩家的头部绑定一个附魔的金苹果
# 物品信息字典主要需要以下4个字段
itemDict = {
   "newItemName" : "minecraft:apple",     # 物品的identifier
   "newAuxValue" : 0,                     # 物品的auxvalue
   "isEnchanted" : True,                  # 是否附魔
   "userData":{}                          # 物品的userData,用于旗帜等物品
}
player_id = clientApi.GetLocalPlayerId()
itemModelId = comp.BindItemToMinecraftModel(player_id, itemDict, "head", False, (0,0,0), (0,0,0), 1.0)
print("Successfully bind item with id:", itemModelId)
# 使这个苹果变大1.5倍
comp.SetBindItemScale(player_id, itemModelId, 1.5)

SetCompassEntity ​

客户端指南针 实体目标 方向指引开发补充

设置指南针指向的实体。

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

设置指南针朝向的实体

  • 参数
参数名数据类型说明
entityIdstr实体id
  • 返回值
数据类型说明
bool是否设置成功
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(playerId)
comp.SetCompassEntity(entityId)

SetCompassTarget ​

客户端指南针 位置目标 方向指引开发补充

设置指南针指向的位置。

客户端

method in mod.client.component.itemCompClient.ItemCompClient

  • 描述

设置指南针的朝向位置

  • 参数
参数名数据类型说明
xint方块x坐标
yint方块y坐标
zint方块z坐标
  • 返回值
数据类型说明
bool是否设置成功
  • 示例
python
import mod.client.extraClientApi as clientApi
comp = clientApi.GetEngineCompFactory().CreateItem(playerId)
comp.SetCompassTarget(x,y,z)

SetCustomName ​

服务端物品名称 自定义名称 名称设置开发补充

修改物品自定义名称,与铁砧重命名对应。

关联接口:GetCustomName (server)

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

设置物品的自定义名称,与使用铁砧重命名一致

  • 参数
参数名数据类型说明
itemDictdict物品信息字典
namestr物品名称。支持unicode
  • 返回值
数据类型说明
bool设置是否成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
itemDict = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
comp.SetCustomName(itemDict, '史蒂夫')
comp.SpawnItemToPlayerCarried(itemDict, playerId)

SetFishingLineColor ​

服务端钓鱼线 颜色设置 外观同步开发补充

修改钓鱼线颜色,并同步到客户端。

关联接口:GetFishingLineColor (server) · GetFishingLineColor (server)

服务端

method in mod.server.component.fishingLineCompServer.FishingLineCompServer

  • 描述

设置钓鱼线的颜色,设置后会自动同步到所有客户端。

  • 参数
参数名数据类型说明
itemNamestr鱼竿物品的完整名称,如 "minecraft:fishing_rod" 或自定义鱼竿名称
colortuple(float,float,float)鱼线颜色rgb,取值[0, 1]
  • 返回值
数据类型说明
bool是否设置成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFishingLine(playerId)
comp.SetFishingLineColor("mymod:custom_fishing_rod", (1.0, 0.0, 0.0))

SetFishingLineMax ​

服务端钓鱼线 长度上限 参数同步开发补充

修改钓鱼线最大长度并同步到客户端;超过长度时会断线。

关联接口:GetFishingLineMax (server) · GetFishingLineMax (server)

服务端

method in mod.server.component.fishingLineCompServer.FishingLineCompServer

  • 描述

设置钓鱼线的最大长度(超过此长度会断线),设置后会自动同步到所有客户端。

  • 参数
参数名数据类型说明
itemNamestr鱼竿物品的完整名称,如 "minecraft:fishing_rod" 或自定义鱼竿名称
maxLengthfloat最大长度,单位为格,钓鱼竿默认值为32.0
  • 返回值
数据类型说明
bool是否设置成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateFishingLine(playerId)
comp.SetFishingLineMax("mymod:custom_fishing_rod", 64.0)

SetItemDefenceAngle ​

服务端盾牌格挡 抵挡角度 参数设置开发补充

设置盾牌格挡的抵挡角度。

关联接口:GetItemDefenceAngle (server)

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

设置盾牌物品的抵挡角度范围

  • 参数
参数名数据类型说明
posTypeintItemPosType枚举
slotPosint槽位
angleLeftfloat左边的范围,不想设置左范围传None,取值范围是[-180,180]
angleRightfloat右边的范围,不想设置右范围传None,取值范围是[-180,180],且angleLeft<angleRight
  • 返回值
数据类型说明
bool是否设置成功
  • 备注

  • 当设置的物品不是盾牌物品时,返回False;原生盾牌会返回True但是仍然走原生的逻辑

  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.SetItemDefenceAngle(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 0, -60, 70)

SetItemDurability ​

服务端物品耐久 耐久设置 槽位修改开发补充

设置物品耐久的目标值;增减耐久需先读取当前值,使用物品事件中的写入宜延后执行。

  • 这是赋值而非自动扣减;数值会限制在零至最大耐久之间。
  • 原文建议在使用物品事件中通过 AddTimer 延迟设置,否则可能失效。

关联接口:GetItemDurability (server) · AddTimer (server) · ItemPosType (common)

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

设置物品的耐久值

  • 参数
参数名数据类型说明
posTypeintItemPosType枚举
slotPosint槽位,当posType为ItemPosType.INVENTORY或ItemPosType.ARMOR时才有意义
durabilityint耐久值
  • 返回值
数据类型说明
bool设置结果
  • 备注

  • 在使用物品事件中调用这个接口时,建议使用AddTimer延迟一下,不然接口设置可能会失效

  • 设置的耐久值超过物品的最大耐久值时,使用最大耐久值;最小耐久值为0。

  • posType设置成serverApi.GetMinecraftEnum().ItemPosType.INVENTORY时可以代替SetInvItemDurability;posType设置成serverApi.GetMinecraftEnum().ItemPosType.ARMOR时可以代替SetEquItemDurability;

  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.SetItemDurability(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 0, 5)

#替代SetInvItemDurability的方法
comp.SetItemDurability(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 0, 5)
#替代SetEquItemDurability的方法
comp.SetItemDurability(serverApi.GetMinecraftEnum().ItemPosType.ARMOR, 0, 5)

SetItemLayer ​

服务端物品贴图 叠加图层 图层设置开发补充

在物品贴图的上层或下层叠加自定义纹理。

关联接口:GetItemLayer (server)

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

设置物品的叠加贴图,可以在物品的上层与下层叠加自定义贴图。具体使用可参考CustomItemsMod示例。

  • 参数
参数名数据类型说明
itemDictdict物品信息字典
layerint贴图的层级。可以为-2,-1,1,2,3。负数层级显示在物品下方,正数的层级显示在物品上方。层级大的显示在层级小的上方。
texturestr贴图的名字,对应item_texture.json中的key。
  • 返回值
数据类型说明
bool设置是否成功
  • 备注

  • 如果需要在自定义ui中显示叠加贴图,需要在您的物品渲染控件下添加top_layer_3,top_layer_2,top_layer_1,bottom_layer_1,bottom_layer_2共5个图片控件,即可使用SetUiItem显示叠加贴图。可参考CustomFurnaceMod示例

"customItemLayer@common.item_renderer_additional_layer": {
    "bindings": [
        {
            "binding_name": "#visible",
            "binding_condition": "always"
        },
        {
            "binding_name": "#uv",
            "binding_condition": "always_when_visible"
        },
        {
            "binding_name": "#uv_size",
            "binding_condition": "always_when_visible"
        },
        {
            "binding_name": "#texture",
            "binding_condition": "always_when_visible"
        }
    ]
},
"itemImg" : {
    "anchor_from" : "center",
    "anchor_to" : "center",
    "controls" : [
        {
            "top_layer_3@neteaseCommonUI.customItemLayer": {
                "$item_renderer_additional_layer_layer": 3
            }
        },
        {
            "top_layer_2@neteaseCommonUI.customItemLayer": {
                "$item_renderer_additional_layer_layer": 2
            }
        },
        {
            "top_layer_1@neteaseCommonUI.customItemLayer": {
                "$item_renderer_additional_layer_layer": 1
            }
        },
        {
            "bottom_layer_1@neteaseCommonUI.customItemLayer": {
                "$item_renderer_additional_layer_layer": -1
            }
        },
        {
            "bottom_layer_2@neteaseCommonUI.customItemLayer": {
                "$item_renderer_additional_layer_layer": -2
            }
        },
        {
        "itemNum@neteaseCommonUI.itemNum" : {}
        }
    ],
    "layer" : 3,
    "offset" : [ 0, 0 ],
    "renderer" : "inventory_item_renderer",
    "size" : [ 24, 24 ],
    "type" : "custom",
    "visible" : true
}
  • 需要为5层叠加贴图预留ui层级,让他可以显示在背包背景之上,物品数量之下。例如在CustomFurnaceMod示例中,itemBtn中的default/hover/pressed贴图的层级为2,物品渲染控件itemImg的层级为5,五个叠加贴图的层级分别为3/4/6/7/8,selectedImg的层级为9,itemNum的层级为10,durabilityBar的层级为11。

  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
itemDict = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
success = comp.SetItemLayer(itemDict, 1, 'wooden_door')
if success:
    comp.SpawnItemToPlayerCarried(itemDict, playerId)

SetItemMaxDurability ​

服务端物品耐久 耐久上限 上限设置开发补充

修改物品最大耐久值。

关联接口:GetItemMaxDurability (server)

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

设置物品的最大耐久值

  • 参数
参数名数据类型说明
posTypeintItemPosType枚举
slotPosint槽位,当posType为ItemPosType.INVENTORY或ItemPosType.ARMOR时才有意义
maxDurabilityint最大耐久值,可设为0~32767
isUserDatabool如果为True,则该设置只对指定物品生效,如果为False,则对同一类所有物品生效
  • 返回值
数据类型说明
bool设置结果
  • 备注

  • 若物品堆叠数量大于1时,耐久度的变更对整一叠的物品生效。并且耐久度为0后,每次消耗耐久度的行为会使数量减一

  • 为物品设置的userData最大耐久度在计算时优先级最高,userData数据存盘。

  • 在砂轮或背包合并时,若两个物品都有userData,只会保留其中一个。在铁砧中修复时,最大耐久取被修复物品的耐久。

  • 当最大耐久值被更改时,当前耐久度也会按比例修复。

  • 对同一类所有物品设置的最大耐久度不存盘,每次重启世界都会重新初始化,可以通过对应item json的minecraft:max_damage组件设置初始化最大耐久度

  • 如果设置的是背包物品,当slot值为-1时,设置左手物品的最大耐久值

  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.SetItemMaxDurability(serverApi.GetMinecraftEnum().ItemPosType.INVENTORY, 0, 5, False)

SetItemTierLevel ​

服务端工具等级 挖掘等级 属性设置开发补充

能力:主手物品 · 挖掘等级

适用限定:挖掘等级

修改工具物品的挖掘等级。

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

设置工具类物品的挖掘等级

  • 参数
参数名数据类型说明
itemDictdict物品信息字典
levelint挖掘等级
  • 返回值
数据类型说明
bool设置是否成功
  • 备注

  • 对于不总是可以破坏的方块(包括方块材质为Stone,Metal,TopSnow,Snow,Web),需要使用不同挖掘等级(level)的工具才能破坏并产生掉落物。

level类型
0木
1石
2铁
3钻石
4下界
  • 剑和剪刀都可以对蜘蛛网进行破坏并产生掉落物; 铲可以对雪和顶层雪进行破坏并产生掉落物; 镐是否可以破坏判断: 1)对于黑曜石、下界类方块、远古残骸,需要Level大于等于3的镐才能破坏并产生掉落物; 2)对于钻石块、钻石矿石、绿宝石块、绿宝石矿石、金块、金矿石、红石矿石、发光的红石矿石,需要Level大于等于2的镐才能破坏并产生掉落物; 3)对于铁块、铁矿石、青金石块、青金石矿石,需要Level大于等于1的镐才能破坏并产生掉落物; 4)对于其他Stone和Metal材质的方块,需要Level大于等于0的镐才能破坏并产生掉落物。

  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
itemDict = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
success = comp.SetItemTierLevel(itemDict, 5)
if success:
    comp.SpawnItemToPlayerCarried(itemDict, playerId)

SetItemTierSpeed ​

服务端工具速度 挖掘速度 属性设置开发补充

修改工具物品的挖掘速度。

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

设置工具类物品的挖掘速度(可通过userData中的ModTierSpeed获取挖掘速度)

  • 参数
参数名数据类型说明
itemDictdict物品信息字典
speedfloat挖掘速度
  • 返回值
数据类型说明
bool设置是否成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
itemDict = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
success = comp.SetItemTierSpeed(itemDict, 32)
if success:
    comp.SpawnItemToPlayerCarried(itemDict, playerId)

SetMaxStackSize ​

服务端物品堆叠 堆叠上限 上限设置开发补充

设置物品最大堆叠数量;设置会保存到存档。

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

设置物品的最大堆叠数量(存档)

  • 参数
参数名数据类型说明
itemDictdict物品信息字典
maxStackSizeint最大堆叠数量,不能超过64,如果该值小于物品的堆叠数量,会返回失败
  • 返回值
数据类型说明
bool设置是否成功
  • 示例
python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
itemDict = comp.GetPlayerItem(serverApi.GetMinecraftEnum().ItemPosType.CARRIED, 0, True)
success = comp.SetMaxStackSize(itemDict, 32)
if success:
    comp.SpawnItemToPlayerCarried(itemDict, playerId)

SetShearsDestroyBlockSpeed ​

服务端剪刀挖掘 破坏速度 属性设置开发补充

设置剪刀对指定方块的破坏速度。

服务端

method in mod.server.component.itemCompServer.ItemCompServer

  • 描述

设置剪刀对某一方块的破坏速度

  • 参数
参数名数据类型说明
blockNamestr方块名称,包含命名空间
speedfloat破坏速度
  • 返回值
数据类型说明
bool设置是否成功
  • 备注

  • 设置的速度最终会加上剪刀的附魔:效率计算

  • 原版剪刀对蜘蛛网的破坏速度为15,羊毛的破坏速度为5,也可以用该接口重写对这两个方块的破坏速度

  • 设置的速度必须大于1,否则该接口返回False

  • 示例

python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(entityId)
comp.SetShearsDestroyBlockSpeed("minecraft:obsidian", 100)