A storage of item stacks.
defines.inventoryunknowntrueThe inventory index this inventory uses, if any.
stringunknowntrueName of this inventory, if any. Names match keys of defines.inventory.
LuaEntityunknowntrueThe entity that owns this inventory, if any.
LuaPlayerunknowntrueThe player that owns this inventory, if any.
LuaEquipmentunknowntrueThe equipment that owns this inventory, if any.
stringunknowntrueThe mod that owns this inventory, if any.
WeightunknownfalseGives a total weight of all items currently in this inventory.
WeightunknowntrueGives a maximum weight of items that can be inserted into this inventory.
booleanunknownfalseIs this object valid? This Lua object holds a reference to an object within the game engine. It is possible that the game-engine object is removed whilst a mod still holds the corresponding Lua object. If that happens, the object becomes invalid, i.e. this attribute will be false. Mods are advised to check for object validity if any change to the game state might have occurred between the creation of the Lua object and its access.
stringunknownfalseThe class name of this object. Available even when valid is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.
LuaInventory.clear()
inventory.clear()
takes_table: falsetable_optional: falseClear this inventory of all items so that it becomes empty.
LuaInventory.can_insert(items: ItemStackIdentification) -> boolean
inventory.can_insert(items)
takes_table: falsetable_optional: falseCan at least some items be inserted?
items: ItemStackIdentification — Items that would be inserted.boolean — true if at least a part of the given items could be inserted into this inventory.LuaInventory.insert(items: ItemStackIdentification) -> uint32
inventory.insert(items)
takes_table: falsetable_optional: falseInsert items into this inventory.
items: ItemStackIdentification — Items to insert.uint32 — Number of items actually inserted.LuaInventory.remove(items: ItemStackIdentification) -> uint32
inventory.remove(items)
takes_table: falsetable_optional: falseRemove items from this inventory.
items: ItemStackIdentification — Items to remove.uint32 — Number of items actually removed.LuaInventory.get_item_count(item?: ItemWithQualityID) -> uint32
inventory.get_item_count()
takes_table: falsetable_optional: falseGet the number of all or some items in this inventory.
item?: ItemWithQualityID — The item to count. If not specified, count all items.uint32LuaInventory.get_item_count_filtered(filter: ItemFilter) -> uint32
inventory.get_item_count_filtered(filter)
takes_table: falsetable_optional: falseGet the number of items in this inventory that match provided filter.
filter: ItemFilteruint32LuaInventory.get_item_quality_counts(item?: ItemID) -> Dict<string, uint32>
inventory.get_item_quality_counts()
takes_table: falsetable_optional: falseGet the number of all or some items in this inventory, aggregated by quality.
item?: ItemIDDict<string, uint32>LuaInventory.is_empty() -> boolean
inventory.is_empty()
takes_table: falsetable_optional: falseDoes this inventory contain nothing?
booleanLuaInventory.is_full() -> boolean
inventory.is_full()
takes_table: falsetable_optional: falseIs every stack in this inventory full? Ignores stacks blocked by the current bar.
For the input slots of crafting machines that allow counts larger than the item stack size, this may return true even when more items can still be inserted.
booleanLuaInventory.get_contents() -> ItemWithQualityCounts
inventory.get_contents()
takes_table: falsetable_optional: falseGet counts of all items in this inventory.
ItemWithQualityCounts — List of all items in the inventory.LuaInventory.supports_bar() -> boolean
inventory.supports_bar()
takes_table: falsetable_optional: falseDoes this inventory support a bar? Bar is the draggable red thing, found for example on chests, that limits the portion of the inventory that may be manipulated by machines.
"Supporting a bar" doesn't mean that the bar is set to some nontrivial value. Supporting a bar means the inventory supports having this limit at all. The character's inventory is an example of an inventory without a bar; the wooden chest's inventory is an example of one with a bar.
booleanLuaInventory.get_bar() -> uint32
inventory.get_bar()
takes_table: falsetable_optional: falseGet the current bar. This is the index at which the red area starts.
Only useable if this inventory supports having a bar.
uint32LuaInventory.set_bar(bar?: uint32)
inventory.set_bar()
takes_table: falsetable_optional: falseSet the current bar.
Only useable if this inventory supports having a bar.
bar?: uint32 — The new limit. Omitting this parameter or passing nil will clear the limit.LuaInventory.supports_filters() -> boolean
inventory.supports_filters()
takes_table: falsetable_optional: falseIf this inventory supports filters.
booleanLuaInventory.is_filtered() -> boolean
inventory.is_filtered()
takes_table: falsetable_optional: falseIf this inventory supports filters and has at least 1 filter set.
booleanLuaInventory.can_set_filter(index: uint32, filter: ItemFilter) -> boolean
inventory.can_set_filter(index, filter)
takes_table: falsetable_optional: falseIf the given inventory slot filter can be set to the given filter.
index: uint32 — The item stack indexfilter: ItemFilter — The item filterbooleanLuaInventory.get_filter(index: uint32) -> ItemFilter?
inventory.get_filter(index)
takes_table: falsetable_optional: falseGets the filter for the given item stack index.
index: uint32 — The item stack indexItemFilter? — The current filter or nil if none.LuaInventory.set_filter(index: uint32, filter: ItemFilter | nil) -> boolean
inventory.set_filter(index, filter)
takes_table: falsetable_optional: falseSets the filter for the given item stack index.
Some inventory slots don't allow some filters (gun ammo can't be filtered for non-ammo).
index: uint32 — The item stack index.filter: ItemFilter | nil — The new filter. nil erases any existing filter.boolean — If the filter was allowed to be set.LuaInventory.find_item_stack(item: ItemWithQualityID) -> LuaItemStack?, uint32?
inventory.find_item_stack(item)
takes_table: falsetable_optional: falseFinds the first LuaItemStack in the inventory that matches the given item name.
item: ItemWithQualityID — The item to findLuaItemStack? — The first matching stack, or nil if none match.uint32? — The stack index of the matching stack, if any is found.LuaInventory.find_empty_stack(item?: ItemWithQualityID) -> LuaItemStack?, uint32?
inventory.find_empty_stack()
takes_table: falsetable_optional: falseFinds the first empty stack. Filtered slots are excluded unless a filter item is given.
item?: ItemWithQualityID — If given, empty stacks that are filtered for this item will be included.LuaItemStack? — The first empty stack, or nil if there aren't any empty stacks.uint32? — The stack index of the matching stack, if any is found.LuaInventory.count_empty_stacks(include_filtered?: boolean, include_bar?: boolean) -> uint32
inventory.count_empty_stacks()
takes_table: falsetable_optional: falseCounts the number of empty stacks.
include_filtered?: boolean — If true, filtered slots will be included. Defaults to false.include_bar?: boolean — If true, slots blocked by the current bar will be included. Defaults to true.uint32LuaInventory.get_insertable_count(item: ItemWithQualityID) -> uint32
inventory.get_insertable_count(item)
takes_table: falsetable_optional: falseGets the number of the given item that can be inserted into this inventory.
This is a "best guess" number; things like assembling machine filtered slots, module slots, items with durability, and items with mixed health will cause the result to be inaccurate. The main use for this is in checking how many of a basic item can fit into a basic inventory.
This accounts for the 'bar' on the inventory.
item: ItemWithQualityID — The item to check.uint32LuaInventory.sort_and_merge()
inventory.sort_and_merge()
takes_table: falsetable_optional: falseSorts and merges the items in this inventory.
LuaInventory.resize(size: uint16)
inventory.resize(size)
takes_table: falsetable_optional: falseResizes the inventory.
Items in slots beyond the new capacity are deleted.
Only inventories created by LuaGameScript::create_inventory can be resized.
size: uint16 — New size of a inventoryLuaInventory.destroy()
inventory.destroy()
takes_table: falsetable_optional: falseDestroys this inventory.
Only inventories created by LuaGameScript::create_inventory can be destroyed this way.