Files
netease-modsdk-wiki/docs/mcdocs/1-ModAPI/接口/方块/容器.md
boybook 760c2dd9ad 2.6
2025-12-01 20:59:16 +08:00

657 lines
19 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
sidebarDepth: 1
---
# 容器
## GetBrewingStandSlotItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取酿造台指定槽位物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| slot | int | 槽位,详见枚举[酿造台槽位](../../枚举值/BrewingStandSlotType.md) |
| pos | tuple(int,int,int) | 容器位置 |
| dimensionId | int | 方块所在维度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a>没有物品则返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.GetBrewingStandSlotItem(serverApi.GetMinecraftEnum().BrewingStandSlotType.SLOT_FUEL, (x, y, z), 0)
```
## GetChestBoxSize
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.chestContainerCompServer.ChestContainerCompServer
- 描述
获取箱子容量大小
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | None | 该参数已废弃 |
| pos | tuple(int,int,int) | 箱子位置 |
| dimensionId | int | 箱子所在维度,可获取对应维度的常加载区块内箱子容量 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 箱子大小,错误值-1 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChestBlock(levelId)
comp.GetChestBoxSize(None, (x, y, z), 0)
```
## GetChestPairedPosition
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.blockInfoCompServer.BlockInfoComponentServer
- 描述
获取与箱子A合并成一个大箱子的箱子B的坐标
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 箱子A的位置坐标 |
| dimensionId | int | 箱子A所在维度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| tuple(int,int,int)或None | 箱子B的位置坐标假如输入的箱子A坐标上的方块不是箱子类方块或者没有和其他箱子方块组合成一个大箱子就会返回None |
- 备注
- 如果dimensionId不传或传入负值该接口使用创建组件时的playerId来定位具体维度且仅可获取玩家附近的方块若方块位置离玩家太远可能无法获取到正确的返回信息。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateBlockInfo(playerId)
pos = (-1, 4, 34)
dimensionId = 0
otherPos = comp.GetChestPairedPosition(pos, dimensionId)
if otherPos:
print "GetChestPairedPosition success pos=%s otherPos=%s" % (str(pos), str(otherPos))
else:
print "GetChestPairedPosition failed pos=%s" % (str(pos), )
```
## GetContainerItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取容器内的物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 容器位置 |
| slotPos | int | 容器槽位 |
| dimensionId | int | 方块所在维度 |
| getUserData | bool | 是否获取userData默认为False |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a>没有物品则返回None |
- 备注
- 容器的具体类型包括:箱子,陷阱箱,潜影盒,漏斗,木桶,投掷器,发射器
- 此接口不支持末影箱。对应的末影箱接口请参考 [GetEnderChestItem](#getenderchestitem)
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
comp.GetContainerItem((x,y,z), 0, 2)
```
## GetContainerSize
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取容器容量大小
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 箱子位置 |
| dimensionId | int | 容器所在维度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| int | 箱子大小,错误值-1 |
- 备注
- 此接口不支持末影箱因为末影箱的size固定为27。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
comp.GetContainerSize((x, y, z), 0)
```
## GetEnderChestItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取末影箱内的物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
| slotPos | int | 容器槽位 |
| getUserData | bool | 是否获取userData默认为False |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a>没有物品则返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.GetEnderChestItem(playerId, 0)
```
## GetInputSlotItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取熔炉输入栏物品, 支持使用下面参数清空特定槽位:itemDict为空为{}, 或itemName为minecraft:air或者count为0
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 容器位置 |
| dimensionId | int | 方块所在维度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a>没有物品则返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
itemName = comp.GetInputSlotItem((x, y, z), 1)
```
## GetOpenContainerItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取开放容器的物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
| containerId | int | [开放容器Id枚举](../../枚举值/OpenContainerId.md) |
| getUserData | bool | 是否获取userData默认为False |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a>没有物品则返回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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取熔炉输出栏物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| pos | tuple(int,int,int) | 容器位置 |
| dimensionId | int | 方块所在维度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a>没有物品则返回None |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(levelId)
itemName = comp.GetOutputSlotItem((x, y, z), 1)
```
## GetPlayerUIItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
获取合成容器的物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
| slot | int | 容器槽位。在isNeteaseUI为True时代表netease_ui_container中对应槽位isNeteaseUI为False时含义见[容器类型枚举](../../枚举值/PlayerUISlot.md) |
| getUserData | bool | 是否获取userData默认为False |
| isNeteaseUI | bool | 默认为falsetrue时获取netease_ui_container的物品 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a>没有物品则返回None |
- 备注
- 合成容器包括工作台、铁砧、附魔台、织布机、砂轮、切石机、制图台、锻造台。
- 所有合成容器槽位共享不会根据不同容器重新排列。网易ui容器独立于原版合成容器不同自定义容器中的netease_ui_container共享槽位。
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
comp.GetPlayerUIItem(playerId, slot, True)
```
## SetBrewingStandSlotItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
设置酿造台指定槽位物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| itemDict | dict | 物品字典信息, 包含三种key: itemName, auxValue, count |
| slot | int | 槽位,详见枚举[酿造台槽位](../../枚举值/BrewingStandSlotType.md) |
| pos | tuple(int,int,int) | 容器位置 |
| dimensionId | int | 方块所在维度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 是否成功设置 |
- 备注
- 该接口仅可设置酿造台支持放入的物品
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateItem(playerId)
itemDict = {"itemName": "minecraft:blaze_powder", "auxValue": 0, "count": 64}
comp.SetBrewingStandSlotItem(itemDict, serverApi.GetMinecraftEnum().BrewingStandSlotType.SLOT_FUEL, (x, y, z), 0)
```
## SetChestBoxItemExchange
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.chestContainerCompServer.ChestContainerCompServer
- 描述
交换箱子里物品的槽位
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
| pos | tuple(int,int,int) | 箱子位置 |
| slotPos1 | int | 箱子槽位1 |
| slotPos2 | int | 箱子槽位2 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置成功返回True失败返回False |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChestBlock(playerId)
comp.SetChestBoxItemExchange(playerId, (x,y,z), 0, 1)
```
## SetChestBoxItemNum
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.chestContainerCompServer.ChestContainerCompServer
- 描述
设置箱子槽位物品数目
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | None | 该参数已废弃 |
| pos | tuple(int,int,int) | 箱子位置 |
| slotPos | int | 箱子槽位 |
| num | int | 物品数目 |
| dimensionId | int | 方块所在维度,可在对应维度的常加载区块设置方块 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 示例
```python
import mod.server.extraServerApi as serverApi
comp = serverApi.GetEngineCompFactory().CreateChestBlock(levelId)
comp.SetChestBoxItemNum(None, (x,y,z), 0, 10, 0)
```
## SetInputSlotItem
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
设置熔炉输入栏物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| itemDict | dict | 物品字典信息, 包含三种key: itemName, auxValue, count |
| pos | tuple(int,int,int) | 容器位置 |
| dimensionId | int | 方块所在维度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
设置合成容器的物品
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| playerId | str | 玩家id |
| slot | int | 容器槽位。在isNeteaseUI为True时代表netease_ui_container中对应槽位isNeteaseUI为False时含义见[容器类型枚举](../../枚举值/PlayerUISlot.md) |
| itemDict | dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a>没有物品则返回None |
| needBack | bool | 是否将容器槽位的已有物品放回至玩家背包中默认为True。设置为False时则会直接用itemDict中的物品覆盖容器槽位的已有物品。 |
| isNeteaseUI | bool | 默认为falsetrue时设置netease_ui_container的物品 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| bool | 设置结果 |
- 备注
- 合成容器包括工作台、铁砧、附魔台、织布机、砂轮、切石机、制图台、锻造台。
- 如果原槽位有物品,则会将原有物品放入玩家背包。如果玩家背包已满,则会在世界中玩家当前的位置生成对应的物品掉落物。
- 注意所有合成容器槽位共享不会根据不同容器重新排列没有打开容器或者打开了别的容器该接口会返回False。
- 如果设置的是netease_ui_container即使没有打开容器也能设置成功所有netease_ui_container槽位共享。
- 下面情况视为清空特定槽位: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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
生成物品到容器方块的物品栏
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| itemDict | dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a> |
| slotPos | int | 箱子槽位 |
| blockPos | tuple(int,int,int) | 箱子位置 |
| dimensionId | int | 容器所在维度 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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
<span style="display:inline;color:#ff5555">服务端</span>
method in mod.server.component.itemCompServer.ItemCompServer
- 描述
生成物品到末影箱
- 参数
| 参数名 | <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- | :--- |
| itemDict | dict | <a href="../../../../mcguide/20-玩法开发/10-基本概念/1-我的世界基础概念.html#物品信息字典#物品信息字典">物品信息字典</a> |
| slotPos | int | 末影箱槽位 |
- 返回值
| <div style="width: 4em">数据类型</div> | 说明 |
| :--- | :--- |
| 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)
```