--- sidebarDepth: 1 --- # 容器 ## GetChestBoxSize 服务端 method in mod.server.component.chestContainerCompServer.ChestContainerCompServer - 描述 获取箱子容量大小 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | playerId | None | 该参数已废弃 | | pos | tuple(int,int,int) | 箱子位置 | | dimensionId | int | 箱子所在维度,可获取对应维度的常加载区块内箱子容量 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | int | 箱子大小,错误值-1 | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateChestBlock(levelId) comp.GetChestBoxSize(None, (x, y, z), 0) ``` ## GetChestPairedPosition 服务端 method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer - 描述 获取与箱子A合并成一个大箱子的箱子B的坐标 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 箱子A的位置坐标 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | tuple(int,int,int)或None | 箱子B的位置坐标,假如输入的箱子A坐标上的方块不是箱子类方块或者没有和其他箱子方块组合成一个大箱子,就会返回None | - 备注 - 该接口使用创建组件时的playerId来定位具体维度,且仅可获取玩家附近的方块,若方块位置离玩家太远,可能无法获取到正确的返回信息。 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId) pos = (-1, 4, 34) otherPos = comp.GetChestPairedPosition(pos) if otherPos: print "GetChestPairedPosition success pos=%s otherPos=%s" % (str(pos), str(otherPos)) else: print "GetChestPairedPosition failed pos=%s" % (str(pos), ) ``` ## GetContainerItem 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 获取容器内的物品 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 容器位置 | | slotPos | int | 容器槽位 | | dimensionId | int | 方块所在维度 | | getUserData | bool | 是否获取userData,默认为False | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 物品信息字典,没有物品则返回None | - 备注 - 容器的具体类型包括:箱子,陷阱箱,潜影盒,漏斗,木桶,投掷器,发射器 - 此接口不支持末影箱。对应的末影箱接口请参考 [GetEnderChestItem](#getenderchestitem) - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateItem(levelId) comp.GetContainerItem((x,y,z), 0, 2) ``` ## GetContainerSize 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 获取容器容量大小 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 箱子位置 | | dimensionId | int | 容器所在维度 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | int | 箱子大小,错误值-1 | - 备注 - 此接口不支持末影箱,因为末影箱的size固定为27。 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateItem(levelId) comp.GetContainerSize((x, y, z), 0) ``` ## GetEnderChestItem 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 获取末影箱内的物品 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | playerId | str | 玩家id | | slotPos | int | 容器槽位 | | getUserData | bool | 是否获取userData,默认为False | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 物品信息字典,没有物品则返回None | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateItem(playerId) comp.GetEnderChestItem(playerId, 0) ``` ## GetInputSlotItem 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 获取熔炉输入栏物品, 支持使用下面参数清空特定槽位:itemDict为空,为{}, 或itemName为minecraft:air,或者count为0 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 容器位置 | | dimensionId | int | 方块所在维度 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 物品信息字典,没有物品则返回None | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateItem(levelId) itemName = comp.GetInputSlotItem((x, y, z), 1) ``` ## GetOpenContainerItem 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 获取开放容器的物品 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | playerId | str | 玩家id | | containerId | int | [开放容器Id枚举](../../枚举值/OpenContainerId.md) | | getUserData | bool | 是否获取userData,默认为False | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 物品信息字典,没有物品则返回None | - 备注 - 需要在事件[CraftItemOutputChangeServerEvent](../../事件/物品.html#CraftItemOutputChangeServerEvent)的监听函数里面才能获取正确的结果 - 开放容器为临时容器,用来保存交互过程中的物品,如铁砧输入位,砂轮输入位 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateItem(playerId) comp.GetOpenContainerItem(playerId,serverApi.GetMinecraftEnum().OpenContainerId.AnvilInputContainer, True) ``` ## GetOutputSlotItem 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 获取熔炉输出栏物品 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | pos | tuple(int,int,int) | 容器位置 | | dimensionId | int | 方块所在维度 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 物品信息字典,没有物品则返回None | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateItem(levelId) itemName = comp.GetOutputSlotItem((x, y, z), 1) ``` ## GetPlayerUIItem 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 获取合成容器的物品 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | playerId | str | 玩家id | | slot | int | 容器槽位,含义见:[容器类型枚举](../../枚举值/PlayerUISlot.md) | | getUserData | bool | 是否获取userData,默认为False | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | dict | 物品信息字典,没有物品则返回None | - 备注 - 合成容器包括工作台、铁砧、附魔台、织布机、砂轮、切石机、制图台、锻造台。 - 所有合成容器槽位共享,不会根据不同容器重新排列 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateItem(playerId) comp.GetPlayerUIItem(playerId, slot, True) ``` ## SetChestBoxItemExchange 服务端 method in mod.server.component.chestContainerCompServer.ChestContainerCompServer - 描述 交换箱子里物品的槽位 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | playerId | str | 玩家id | | pos | tuple(int,int,int) | 箱子位置 | | slotPos1 | int | 箱子槽位1 | | slotPos2 | int | 箱子槽位2 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置成功返回True,失败返回False | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateChestBlock(playerId) comp.SetChestBoxItemExchange(playerId, (x,y,z), 0, 1) ``` ## SetChestBoxItemNum 服务端 method in mod.server.component.chestContainerCompServer.ChestContainerCompServer - 描述 设置箱子槽位物品数目 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | playerId | None | 该参数已废弃 | | pos | tuple(int,int,int) | 箱子位置 | | slotPos | int | 箱子槽位 | | num | int | 物品数目 | | dimensionId | int | 方块所在维度,可在对应维度的常加载区块设置方块 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateChestBlock(levelId) comp.SetChestBoxItemNum(None, (x,y,z), 0, 10, 0) ``` ## SetInputSlotItem 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 设置熔炉输入栏物品 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | itemDict | dict | 物品字典信息, 包含三种key: itemName, auxValue, count | | pos | tuple(int,int,int) | 容器位置 | | dimensionId | int | 方块所在维度 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 是否成功设置 | - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateItem(playerId) comp.SetInputSlotItem({"itemName": "minecraft:iron_ore", "auxValue": 0, "count": 1}, (x, y, z), 1) ``` ## SetPlayerUIItem 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 设置合成容器的物品 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | playerId | str | 玩家id | | slot | int | 容器槽位,含义见:[容器类型枚举](../../枚举值/PlayerUISlot.md) | | itemDict | dict | 物品信息字典,没有物品则返回None | | needBack | bool | 是否将容器槽位的已有物品放回至玩家背包中,默认为True。设置为False时,则会直接用itemDict中的物品覆盖容器槽位的已有物品。 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 备注 - 合成容器包括工作台、铁砧、附魔台、织布机、砂轮、切石机、制图台、锻造台。 - 如果原槽位有物品,则会将原有物品放入玩家背包。如果玩家背包已满,则会在世界中玩家当前的位置生成对应的物品掉落物。 - 注意,所有合成容器槽位共享,不会根据不同容器重新排列,没有打开容器或者打开了别的容器,该接口会返回False。 - 下面情况视为清空特定槽位:itemDict为None,为{}, 或itemName为minecraft:air,或者count为0,同时needBack参数为False - 由于创造输出物品生成位比较特殊,该接口已经屏蔽了slot = 50的情况,即无法设置创造输出位的物品。 - 示例 ```python import mod.server.extraServerApi as serverApi comp = serverApi.GetEngineCompFactory().CreateItem(playerId) itemDict = { 'itemName': 'minecraft:bow', 'count': 1, # 可填入0达到删除某槽位物品的效果 'auxValue': 0, } comp.SetPlayerUIItem(playerId, slot, itemDict) # 也可以直接使用 comp.SetPlayerUIItem(playerId, slot, None, False) 来清空物品 ``` ## SpawnItemToContainer 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 生成物品到容器方块的物品栏 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | itemDict | dict | 物品信息字典 | | slotPos | int | 箱子槽位 | | blockPos | tuple(int,int,int) | 箱子位置 | | dimensionId | int | 容器所在维度 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 备注 - 此接口不支持末影箱。对应的末影箱接口请参考 [SpawnItemToEnderChest](#spawnitemtoenderchest) - 下面情况视为清空特定槽位:itemDict为空,为{}, 或itemName为minecraft:air,或者count为0 - 目前该接口支持的容器类型方块:箱子、潜影盒、漏斗、木桶、投掷器、发射器 - 示例 ```python import mod.server.extraServerApi as serverApi itemDict = { 'itemName': 'minecraft:bow', 'count': 1, # 可填入0达到删除某槽位物品的效果 'enchantData': [(serverApi.GetMinecraftEnum().EnchantType.BowDamage, 1),], 'auxValue': 0, 'customTips':'§c new item §r', 'extraId': 'abc', 'userData': { }, } # 生成物品到容器的0号槽位,容器位于维度0,坐标为(x,y,z) comp = serverApi.GetEngineCompFactory().CreateItem(levelId) comp.SpawnItemToContainer(itemDict, 0, (x,y,z), 0) ``` ## SpawnItemToEnderChest 服务端 method in mod.server.component.itemCompServer.ItemCompServer - 描述 生成物品到末影箱 - 参数 | 参数名 |
数据类型
| 说明 | | :--- | :--- | :--- | | itemDict | dict | 物品信息字典 | | slotPos | int | 末影箱槽位 | - 返回值 |
数据类型
| 说明 | | :--- | :--- | | bool | 设置结果 | - 备注 - 下面情况视为清空特定槽位:itemDict为空,为{}, 或itemName为minecraft:air,或者count为0 - 示例 ```python import mod.server.extraServerApi as serverApi itemDict = { 'itemName': 'minecraft:bow', 'count': 1, 'enchantData': [(serverApi.GetMinecraftEnum().EnchantType.BowDamage, 1),], 'auxValue': 0, 'customTips':'§c new item §r', 'extraId': 'abc', 'userData': { }, } comp = serverApi.GetEngineCompFactory().CreateItem(playerId) comp.SpawnItemToEnderChest(itemDict, 0) ```