Home

LuaInventory

A storage of item stacks.

Attributes

index

The inventory index this inventory uses, if any.

name

Name of this inventory, if any. Names match keys of defines.inventory.

entity_owner

The entity that owns this inventory, if any.

player_owner

The player that owns this inventory, if any.

equipment_owner

The equipment that owns this inventory, if any.

mod_owner

The mod that owns this inventory, if any.

weight

Gives a total weight of all items currently in this inventory.

max_weight

Gives a maximum weight of items that can be inserted into this inventory.

valid

Is 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.

object_name

The 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.

Methods

clear

LuaInventory.clear()

Call As

inventory.clear()

Call Convention

Clear this inventory of all items so that it becomes empty.

can_insert

LuaInventory.can_insert(items: ItemStackIdentification) -> boolean

Call As

inventory.can_insert(items)

Call Convention

Can at least some items be inserted?

Parameters

Returns

insert

LuaInventory.insert(items: ItemStackIdentification) -> uint32

Call As

inventory.insert(items)

Call Convention

Insert items into this inventory.

Parameters

Returns

remove

LuaInventory.remove(items: ItemStackIdentification) -> uint32

Call As

inventory.remove(items)

Call Convention

Remove items from this inventory.

Parameters

Returns

get_item_count

LuaInventory.get_item_count(item?: ItemWithQualityID) -> uint32

Call As

inventory.get_item_count()

Call Convention

Get the number of all or some items in this inventory.

Parameters

Returns

get_item_count_filtered

LuaInventory.get_item_count_filtered(filter: ItemFilter) -> uint32

Call As

inventory.get_item_count_filtered(filter)

Call Convention

Get the number of items in this inventory that match provided filter.

Parameters

Returns

get_item_quality_counts

LuaInventory.get_item_quality_counts(item?: ItemID) -> Dict<string, uint32>

Call As

inventory.get_item_quality_counts()

Call Convention

Get the number of all or some items in this inventory, aggregated by quality.

Parameters

Returns

is_empty

LuaInventory.is_empty() -> boolean

Call As

inventory.is_empty()

Call Convention

Does this inventory contain nothing?

Returns

is_full

LuaInventory.is_full() -> boolean

Call As

inventory.is_full()

Call Convention

Is 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.

Returns

get_contents

LuaInventory.get_contents() -> ItemWithQualityCounts

Call As

inventory.get_contents()

Call Convention

Get counts of all items in this inventory.

Returns

supports_bar

LuaInventory.supports_bar() -> boolean

Call As

inventory.supports_bar()

Call Convention

Does 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.

Returns

get_bar

LuaInventory.get_bar() -> uint32

Call As

inventory.get_bar()

Call Convention

Get the current bar. This is the index at which the red area starts.

Only useable if this inventory supports having a bar.

Returns

set_bar

LuaInventory.set_bar(bar?: uint32)

Call As

inventory.set_bar()

Call Convention

Set the current bar.

Only useable if this inventory supports having a bar.

Parameters

supports_filters

LuaInventory.supports_filters() -> boolean

Call As

inventory.supports_filters()

Call Convention

If this inventory supports filters.

Returns

is_filtered

LuaInventory.is_filtered() -> boolean

Call As

inventory.is_filtered()

Call Convention

If this inventory supports filters and has at least 1 filter set.

Returns

can_set_filter

LuaInventory.can_set_filter(index: uint32, filter: ItemFilter) -> boolean

Call As

inventory.can_set_filter(index, filter)

Call Convention

If the given inventory slot filter can be set to the given filter.

Parameters

Returns

get_filter

LuaInventory.get_filter(index: uint32) -> ItemFilter?

Call As

inventory.get_filter(index)

Call Convention

Gets the filter for the given item stack index.

Parameters

Returns

set_filter

LuaInventory.set_filter(index: uint32, filter: ItemFilter | nil) -> boolean

Call As

inventory.set_filter(index, filter)

Call Convention

Sets 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).

Parameters

Returns

find_item_stack

LuaInventory.find_item_stack(item: ItemWithQualityID) -> LuaItemStack?, uint32?

Call As

inventory.find_item_stack(item)

Call Convention

Finds the first LuaItemStack in the inventory that matches the given item name.

Parameters

Returns

find_empty_stack

LuaInventory.find_empty_stack(item?: ItemWithQualityID) -> LuaItemStack?, uint32?

Call As

inventory.find_empty_stack()

Call Convention

Finds the first empty stack. Filtered slots are excluded unless a filter item is given.

Parameters

Returns

count_empty_stacks

LuaInventory.count_empty_stacks(include_filtered?: boolean, include_bar?: boolean) -> uint32

Call As

inventory.count_empty_stacks()

Call Convention

Counts the number of empty stacks.

Parameters

Returns

get_insertable_count

LuaInventory.get_insertable_count(item: ItemWithQualityID) -> uint32

Call As

inventory.get_insertable_count(item)

Call Convention

Gets 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.

Parameters

Returns

sort_and_merge

LuaInventory.sort_and_merge()

Call As

inventory.sort_and_merge()

Call Convention

Sorts and merges the items in this inventory.

resize

LuaInventory.resize(size: uint16)

Call As

inventory.resize(size)

Call Convention

Resizes the inventory.

Items in slots beyond the new capacity are deleted.

Only inventories created by LuaGameScript::create_inventory can be resized.

Parameters

destroy

LuaInventory.destroy()

Call As

inventory.destroy()

Call Convention

Destroys this inventory.

Only inventories created by LuaGameScript::create_inventory can be destroyed this way.