Inventory Controller Upgrade: Difference between revisions
imported>OCDoc Import Imported from legacy OpenComputers documentation at ocdoc.cil.li |
Unify item and component API pages |
||
| Line 2: | Line 2: | ||
[[File:inventory_controller_upgrade.png|128px]] | [[File:inventory_controller_upgrade.png|128px]] | ||
This upgrade allows the robot to interact in a more controlled fashion with inventories in the world. | This upgrade allows the robot to interact in a more controlled fashion with inventories in the world. | ||
Robots with this upgrade can read additional item information, suck and drop items from and into specific slots of an inventory and equip items on their own. This is particularly useful for interacting with advanced machines, where items have to go into specific slots, but can also come in handy for sorting systems or automated crafting. | Robots with this upgrade can read additional item information, suck and drop items from and into specific slots of an inventory and equip items on their own. This is particularly useful for interacting with advanced machines, where items have to go into specific slots, but can also come in handy for sorting systems or automated crafting. | ||
The Inventory Controller upgrade is crafted using the following recipe: | The Inventory Controller upgrade is crafted using the following recipe: | ||
| Line 22: | Line 18: | ||
[[File:invcontroller.png|200px]] | [[File:invcontroller.png|200px]] | ||
== Contents | = Component API = | ||
Component name: <code>inventory_controller</code> | |||
Callbacks: | |||
{{APICallback|name=getInventorySize|signature=(side: number): number or nil[, string]|description= | |||
Returns the size of the inventory at the specified side. '''side''' - must be a valid side. '''Returns:''' the size of the inventory, or <code>nil</code> followed by a description why this function failed (usually <code>no inventory</code>). | |||
}} | |||
{{APICallback|name=getStackInSlot|signature=(side:number, slot:number):table|description= | |||
Returns a table describing the item in the specified slot or nil. Deprecated for getting info about robot's own inventory, see <code>getStackInInternalSlot</code>. | |||
'''side''' - must be a valid side. | |||
'''slot''' - the slot to analyze. This does not check the inventory size and will consider slots outside the inventory bounds to be empty. | |||
'''Returns:''' <code>nil</code> if the slot was empty (or outside the inventory's bounds), a table otherwise with the following information about the item in that slot: | |||
* '''damage''':number - the current damage value of the item. | |||
* '''maxDamage''':number - the maximum damage this item can have before it breaks. | |||
* '''size''':number - the current stack size of the item. | |||
* '''maxSize''':number - the maximum stack size of this item. | |||
* '''id''':number - the Minecraft id of the item. Note that this field is only included if <code>insertIdsInConverters=true</code> in the configs, and can vary between servers! | |||
* '''name''':string - the '''untranslated''' item name, which is an internal Minecraft value like <code>oc:item.FloppyDisk</code> | |||
* '''label''':string - the '''translated''' item name | |||
* '''hasTag''':boolean - whether or not the item has an NBT tag associated with it. | |||
}} | |||
{{APICallback|name=getStackInInternalSlot|signature=(slot:number):table|description= | |||
Gets Itemstack description of item in specified or selected slot (if no input provided) of robot inventory. | |||
}} | |||
{{APICallback|name=dropIntoSlot|signature=(side:number, slot:number[, count:number]):boolean[, string]|description= | |||
Puts up to count items from the currently selected slot into the specified slot of the inventory at the specified side. '''side''' - a valid side. '''slot''' - the slot to drop the item into. '''count''' - how many items to transfer. '''Returns:''' <code>true</code> if at least one item was moved, <code>false</code> and a secondary result that describes the error otherwise. Note that the robot cannot drop items into it's own inventory, attempting to do so will cause this to throw an error. You need to use <code>robot.transferTo</code> from the [[API/robot|Robot API]] to do so. | |||
}} | |||
{{APICallback|name=suckFromSlot|signature=(side:number, slot:number[, count:number]):boolean|description= | |||
Takes up to count items from the specified slot of the inventory at the specified side and puts them into the currently selected slot. '''side''' - a valid side. '''slot''' - the slot to take the item from. '''count''' - how many items to transfer. '''Returns:''' <code>true</code> if at least one item was moved, <code>false</code> otherwise. If the currently selected slot is occupied, then the items will be stacked with similar items in the robot's inventory or moved to the next free slot if available. If no slot is available this operation will fail. Note that the robot cannot suck items from it's own inventory, attempting to do so will cause this to throw an error. You need to use <code>robot.transferTo</code> from the [[API/robot|Robot API]] to do so. | |||
}} | |||
{{APICallback|name=equip|signature=():boolean|description= | |||
Swaps the content of the robot's tool slot with the content of the currently selected inventory slot. '''Returns:''' <code>true</code> if the items were swapped, <code>false</code> otherwise. This operation usually succeeds. Note that you can put any kind of item into the robot's tool slot, not only tools, even items that the robot cannot use at all. | |||
}} | |||
{{APICallback|name=store|signature=(side:number, slot:number, dbAddress:string, dbSlot:number):boolean|description= | |||
Stores the Itemstack description of the item from the specified slot in an inventory on the specified side, into a specified database slot with the specified address. | |||
}} | |||
{{APICallback|name=storeInternal|signature=(slot:number, dbAddress:string, dBslot:number):boolean|description= | |||
Stores Itemstack description of item in specified robot inventory slot into specified database slot with the specified database address. | |||
}} | |||
{{APICallback|name=compareToDatabase|signature=(slot:number, dBaddress:string, dBslot:number):boolean|description= | |||
Compare Itemstack description in specified slot with one in specified slot of a database with specified address. Returns **true** if items match. | |||
}} | |||
{{APICallback|name=compareStacks|signature=(side:number, slotA:number, slotB:number):boolean|description= | |||
Checks to see if Itemstack descriptions in specified slotA and slotB of inventory on specified side match. Returns **true** if identical. | |||
}} | |||
{{APICallback|name=getSlotMaxStackSize|signature=(side:number, slot:number):number|description= | |||
Gets maximum number of items in specified slot in inventory on the specified side. | |||
}} | |||
{{APICallback|name=getSlotStackSize|signature=(side:number, slot:number):number|description= | |||
Gets number of items in specified slot in inventory on the specified side. | |||
}} | |||
= Example = | |||
Print meta-info about the item in the position indicated by [[API/robot|slot]] | |||
<syntaxhighlight lang="lua"> | |||
local component = require("component") | |||
local sides = require("sides") | |||
local slot = 1 | |||
local item = component.inventory_controller.getStackInInternalSlot(slot) | |||
if item then | |||
print("Item name: ", item.name) | |||
print("Item count: ", item.size) | |||
print("Item damage: ", item.damage) | |||
else | |||
print("Slot " .. slot .. " is empty") | |||
end | |||
</syntaxhighlight> | |||
= Contents = | |||
{{:Item/contents}} | {{:Item/contents}} | ||
Revision as of 22:02, 10 September 2026
Inventory Controller Upgrade
This upgrade allows the robot to interact in a more controlled fashion with inventories in the world.
Robots with this upgrade can read additional item information, suck and drop items from and into specific slots of an inventory and equip items on their own. This is particularly useful for interacting with advanced machines, where items have to go into specific slots, but can also come in handy for sorting systems or automated crafting.
The Inventory Controller upgrade is crafted using the following recipe:
- 4 x Gold Ingot
- 1 x Piston
- 1 x Dropper
- 1 x Analyzer
- 1 x Microchip (Tier 2)
- 1 x Printed Circuit Board
Component API
Component name: inventory_controller
Callbacks:
getInventorySize
getInventorySize(side: number): number or nil[, string]
Returns the size of the inventory at the specified side. side - must be a valid side. Returns: the size of the inventory, or nil followed by a description why this function failed (usually no inventory).
getStackInSlot
getStackInSlot(side:number, slot:number):table
Returns a table describing the item in the specified slot or nil. Deprecated for getting info about robot's own inventory, see getStackInInternalSlot.
side - must be a valid side.
slot - the slot to analyze. This does not check the inventory size and will consider slots outside the inventory bounds to be empty.
Returns: nil if the slot was empty (or outside the inventory's bounds), a table otherwise with the following information about the item in that slot:
- damage:number - the current damage value of the item.
- maxDamage:number - the maximum damage this item can have before it breaks.
- size:number - the current stack size of the item.
- maxSize:number - the maximum stack size of this item.
- id:number - the Minecraft id of the item. Note that this field is only included if
insertIdsInConverters=truein the configs, and can vary between servers! - name:string - the untranslated item name, which is an internal Minecraft value like
oc:item.FloppyDisk - label:string - the translated item name
- hasTag:boolean - whether or not the item has an NBT tag associated with it.
getStackInInternalSlot
getStackInInternalSlot(slot:number):table
Gets Itemstack description of item in specified or selected slot (if no input provided) of robot inventory.
dropIntoSlot
dropIntoSlot(side:number, slot:number[, count:number]):boolean[, string]
Puts up to count items from the currently selected slot into the specified slot of the inventory at the specified side. side - a valid side. slot - the slot to drop the item into. count - how many items to transfer. Returns: true if at least one item was moved, false and a secondary result that describes the error otherwise. Note that the robot cannot drop items into it's own inventory, attempting to do so will cause this to throw an error. You need to use robot.transferTo from the Robot API to do so.
suckFromSlot
suckFromSlot(side:number, slot:number[, count:number]):boolean
Takes up to count items from the specified slot of the inventory at the specified side and puts them into the currently selected slot. side - a valid side. slot - the slot to take the item from. count - how many items to transfer. Returns: true if at least one item was moved, false otherwise. If the currently selected slot is occupied, then the items will be stacked with similar items in the robot's inventory or moved to the next free slot if available. If no slot is available this operation will fail. Note that the robot cannot suck items from it's own inventory, attempting to do so will cause this to throw an error. You need to use robot.transferTo from the Robot API to do so.
equip
equip():boolean
Swaps the content of the robot's tool slot with the content of the currently selected inventory slot. Returns: true if the items were swapped, false otherwise. This operation usually succeeds. Note that you can put any kind of item into the robot's tool slot, not only tools, even items that the robot cannot use at all.
store
store(side:number, slot:number, dbAddress:string, dbSlot:number):boolean
Stores the Itemstack description of the item from the specified slot in an inventory on the specified side, into a specified database slot with the specified address.
storeInternal
storeInternal(slot:number, dbAddress:string, dBslot:number):boolean
Stores Itemstack description of item in specified robot inventory slot into specified database slot with the specified database address.
compareToDatabase
compareToDatabase(slot:number, dBaddress:string, dBslot:number):boolean
Compare Itemstack description in specified slot with one in specified slot of a database with specified address. Returns **true** if items match.
compareStacks
compareStacks(side:number, slotA:number, slotB:number):boolean
Checks to see if Itemstack descriptions in specified slotA and slotB of inventory on specified side match. Returns **true** if identical.
getSlotMaxStackSize
getSlotMaxStackSize(side:number, slot:number):number
Gets maximum number of items in specified slot in inventory on the specified side.
getSlotStackSize
getSlotStackSize(side:number, slot:number):number
Gets number of items in specified slot in inventory on the specified side.
Example
Print meta-info about the item in the position indicated by slot
local component = require("component")
local sides = require("sides")
local slot = 1
local item = component.inventory_controller.getStackInInternalSlot(slot)
if item then
print("Item name: ", item.name)
print("Item count: ", item.size)
print("Item damage: ", item.damage)
else
print("Slot " .. slot .. " is empty")
endContents
| Items | |
|---|---|
| Components | Data Card - Debug Card - Graphics Card - Internet Card - Linked Card - Network Card - Redstone Card - Wireless Network Card |
| Storage Devices | Floppy Disk - EEPROM - Hard Disk Drive - Memory |
| Upgrades | Angel Upgrade - Battery Upgrade - Chunkloader Upgrade - Database Upgrade - Experience Upgrade - Generator Upgrade - Hover Upgrade - Inventory Controller Upgrade - Inventory Upgrade - Leash Upgrade - Navigation Upgrade - Piston Upgrade - Sign I/O Upgrade - Solar Generator Upgrade - Tank Upgrade - Tank Controller Upgrade - Tractor Beam Upgrade |
| Containers | Card Container - Upgrade Container - Disk Drive |
| Others | Analyzer - Texture Picker - Component Bus - CPU - APU - Drone Case - Manual - Microcontroller Case - Nanomachines - Remote Terminal - Terminal Server - Server - Tablet Case - Tablet - Crafting Materials - Ink Cartridge - Scrench - Hover Boots - Grog - Loot Disks |
