LuaInventory
A storage of item stacks.
LuaInventory
Get the number of slots in this inventory.
The indexing operator.
Make this inventory empty.
Can at least some items be inserted?
Get the number of all or some items in this inventory.
Get counts of all items in this inventory.
Does this inventory support a bar?
Set the current bar.
If this inventory supports filters.
If this inventory supports filters and has at least 1 filter set.
If the given inventory slot filter can be set to the given filter.
Gets the filter for the given item stack index.
Sets the filter for the given item stack index.
Gets the first LuaItemStack in the inventory that matches the given item name.
Finds the first empty stack.
Counts the number of empty stacks.
Gets the number of the given item that can be inserted into this inventory.
Sorts and merges the items in this inventory.
Resizes the inventory.
Destroys this inventory.
The inventory index this inventory uses, or nil
if the inventory doesn't have an index.
The entity that owns this inventory or nil
if this isn't owned by an entity.
The player that owns this inventory or nil
if this isn't owned by a player.
The equipment that owns this inventory or nil
if this isn't owned by an equipment.
The class name of this object.
operator #
Get the number of slots in this inventory.
Will print the number of slots in the player's main inventory.
game.player.print(#game.player.get_main_inventory())
can_insert(items)
→
boolean
Can at least some items be inserted?
Items that would be inserted.
true
if at least a part of the given items could be inserted into this inventory.
insert(items)
→
uint
Insert items into this inventory.
Items to insert.
Number of items actually inserted.
remove(items)
→
uint
Remove items from this inventory.
Items to remove.
Number of items actually removed.
get_item_count(item)
→
uint
supports_bar()
→
boolean
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.
get_bar()
→
uint
Get the current bar. This is the index at which the red area starts.
Only useable if this inventory supports having a bar.
set_bar(bar)
Set the current bar.
The new limit. Omitting this parameter will clear the limit.
Only useable if this inventory supports having a bar.
is_filtered()
→
boolean
can_set_filter(index,
filter)
→
boolean
get_filter(index)
→
string?
set_filter(index,
filter)
→
boolean
Sets the filter for the given item stack index.
If the filter was allowed to be set.
Some inventory slots don't allow some filters (gun ammo can't be filtered for non-ammo).
find_item_stack(item)
→
LuaItemStack?,
uint?
Gets the first LuaItemStack in the inventory that matches the given item name.
The item name to find
The first matching stack, or nil
if none match.
The stack index of the matching stack, if any is found.
find_empty_stack(item)
→
LuaItemStack?,
uint?
Finds the first empty stack. Filtered slots are excluded unless a filter item is given.
If given, empty stacks that are filtered for this item will be included.
The first empty stack, or nil
if there aren't any empty stacks.
The stack index of the matching stack, if any is found.
count_empty_stacks(include_filtered)
→
uint
get_insertable_count(item)
Gets the number of the given item that can be inserted into this inventory.
The item to check.
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.
resize(size)
Resizes the inventory.
New size of a inventory
Items in slots beyond the new capacity are deleted.
Only inventories created by LuaGameScript::create_inventory can be resized.
destroy()
Destroys this inventory.
Only inventories created by LuaGameScript::create_inventory can be destroyed this way.
index
:: defines.inventory
[Read]
The inventory index this inventory uses, or nil
if the inventory doesn't have an index.
entity_owner
:: LuaEntity
[Read]
The entity that owns this inventory or nil
if this isn't owned by an entity.
player_owner
:: LuaPlayer
[Read]
The player that owns this inventory or nil
if this isn't owned by a player.
equipment_owner
:: LuaEquipment
[Read]
The equipment that owns this inventory or nil
if this isn't owned by an equipment.
mod_owner
:: string
[Read]
The mod that owns this inventory or nil
if this isn't owned by a mod.
valid
:: boolean
[Read]
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
:: string
[Read]
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.