inventory
Methods for interacting with inventories.
size() | Get the size of this inventory. |
---|---|
list() | List all items in this inventory. |
getItemDetail(slot) | Get detailed information about an item. |
pushItems(toName, fromSlot [, limit [, toSlot]]) | Push items from one inventory to another connected one. |
pullItems(fromName, fromSlot [, limit [, toSlot]]) | Pull items from a connected inventory into this one. |
- size()Source
Get the size of this inventory.
Returns
- number The number of slots in this inventory.
- list()Source
List all items in this inventory. This returns a table, with an entry for each slot.
Each item in the inventory is represented by a table containing some basic information, much like turtle.getItemDetail includes. More information can be fetched with getItemDetail.
The returned table is sparse, and so empty slots will be
nil
- it is recommended to loop over usingpairs
rather thanipairs
.Returns
- { table | nil... } All items in this inventory.
- getItemDetail(slot)Source
Get detailed information about an item.
Parameters
- slot number The slot to get information about.
Returns
- table Information about the item in this slot, or nil if not present.
Throws
If the slot is out of range.
- pushItems(toName, fromSlot [, limit [, toSlot]])Source
Push items from one inventory to another connected one.
This allows you to push an item in an inventory to another inventory on the same wired network. Both inventories must attached to wired modems which are connected via a cable.
Parameters
- toName string
The name of the peripheral/inventory to push to. This is the string given to peripheral.wrap,
and displayed by the wired modem.
- fromSlot number The slot in the current inventory to move items to.
- limit? number The maximum number of items to move. Defaults to the current stack limit.
- toSlot? number The slot in the target inventory to move to. If not given, the item will be inserted into any slot.
Returns
- number The number of transferred items.
Throws
If the peripheral to transfer to doesn't exist or isn't an inventory.
If either source or destination slot is out of range.
Usage
Wrap two chests, and push an item from one to another.
local chest_a = peripheral.wrap("minecraft:chest_0") local chest_b = peripheral.wrap("minecraft:chest_1") chest_a.pushItems(peripheral.getName(chest_b), 1)
See also
- peripheral.getName Allows you to get the name of a wrapped peripheral.
- toName string
- pullItems(fromName, fromSlot [, limit [, toSlot]])Source
Pull items from a connected inventory into this one.
This allows you to transfer items between inventories on the same wired network. Both this and the source inventory must attached to wired modems which are connected via a cable.
Parameters
- fromName string
The name of the peripheral/inventory to pull from. This is the string given to peripheral.wrap,
and displayed by the wired modem.
- fromSlot number The slot in the source inventory to move items from.
- limit? number The maximum number of items to move. Defaults to the current stack limit.
- toSlot? number The slot in current inventory to move to. If not given, the item will be inserted into any slot.
Returns
- number The number of transferred items.
Throws
If the peripheral to transfer to doesn't exist or isn't an inventory.
If either source or destination slot is out of range.
Usage
Wrap two chests, and push an item from one to another.
local chest_a = peripheral.wrap("minecraft:chest_0") local chest_b = peripheral.wrap("minecraft:chest_1") chest_a.pullItems(peripheral.getName(chest_b), 1)
See also
- peripheral.getName Allows you to get the name of a wrapped peripheral.
- fromName string