A storage of item stacks.
clear() |
Make this inventory empty. |
|
Make this inventory empty. |
||
can_insert(items) | → boolean |
Can at least some items be inserted? |
Can at least some items be inserted? |
||
insert(items) | → uint |
Insert items into this inventory. |
Insert items into this inventory. |
||
remove(items) | → uint |
Remove items from this inventory. |
Remove items from this inventory. |
||
get_item_count(item?) | → uint |
Get the number of all or some items in this inventory. |
Get the number of all or some items in this inventory. |
||
is_empty() | → boolean |
Does this inventory contain nothing? |
Does this inventory contain nothing? |
||
is_full() | → boolean |
Is every stack in this inventory full? |
Is every stack in this inventory full? |
||
get_contents() | → dictionary[string → uint] |
Get counts of all items in this inventory. |
Get counts of all items in this inventory. |
||
supports_bar() | → boolean |
Does this inventory support a bar? |
Does this inventory support a bar? |
||
get_bar() | → uint |
Get the current bar. |
Get the current bar. |
||
set_bar(bar?) |
Set the current bar. |
|
Set the current bar. |
||
supports_filters() | → boolean |
If this inventory supports filters. |
If this inventory supports filters. |
||
is_filtered() | → boolean |
If this inventory supports filters and has at least 1 filter set. |
If this inventory supports filters and has at least 1 filter set. |
||
can_set_filter(index, filter) | → boolean |
If the given inventory slot filter can be set to the given filter. |
If the given inventory slot filter can be set to the given filter. |
||
get_filter(index) | → string? |
Gets the filter for the given item stack index. |
Gets the filter for the given item stack index. |
||
set_filter(index, filter) | → boolean |
Sets the filter for the given item stack index. |
Sets the filter for the given item stack index. |
||
find_item_stack(item) | → LuaItemStack?, uint? |
Finds the first LuaItemStack in the inventory that matches the given item name. |
Finds the first LuaItemStack in the inventory that matches the given item name. |
||
find_empty_stack(item?) | → LuaItemStack?, uint? |
Finds the first empty stack. |
Finds the first empty stack. |
||
count_empty_stacks(include_filtered?, include_bar?) | → uint |
Counts the number of empty stacks. |
Counts the number of empty stacks. |
||
get_insertable_count(item) |
Gets the number of the given item that can be inserted into this inventory. |
|
Gets the number of the given item that can be inserted into this inventory. |
||
sort_and_merge() |
Sorts and merges the items in this inventory. |
|
Sorts and merges the items in this inventory. |
||
resize(size) |
Resizes the inventory. |
|
Resizes the inventory. |
||
destroy() |
Destroys this inventory. |
|
Destroys this inventory. |
||
help() | → string |
All methods and properties that this object supports. |
All methods and properties that this object supports. |
||
index [R] | :: defines.inventory? |
The inventory index this inventory uses, if any. |
The inventory index this inventory uses, if any. |
||
entity_owner [R] | :: LuaEntity? |
The entity that owns this inventory, if any. |
The entity that owns this inventory, if any. |
||
player_owner [R] | :: LuaPlayer? |
The player that owns this inventory, if any. |
The player that owns this inventory, if any. |
||
equipment_owner [R] | :: LuaEquipment? |
The equipment that owns this inventory, if any. |
The equipment that owns this inventory, if any. |
||
mod_owner [R] | :: string? |
The mod that owns this inventory, if any. |
The mod that owns this inventory, if any. |
||
valid [R] | :: boolean |
Is this object valid? |
Is this object valid? |
||
object_name [R] | :: string |
The class name of this object. |
The class name of this object. |
||
# (length) [R] | :: uint |
Get the number of slots in this inventory. |
Get the number of slots in this inventory. |
||
[] (index) [R] | :: LuaItemStack |
The indexing operator. |
The indexing operator. |
Can at least some items be inserted?
items | :: ItemStackIdentification |
Items that would be inserted. |
Items that would be inserted. |
→ boolean |
|
Insert items into this inventory.
items | :: ItemStackIdentification |
Items to insert. |
Items to insert. |
→ uint |
Number of items actually inserted. |
Remove items from this inventory.
items | :: ItemStackIdentification |
Items to remove. |
Items to remove. |
→ uint |
Number of items actually removed. |
Get the number of all or some items in this inventory.
item | :: string? |
Prototype name of the item to count. If not specified, count all items. |
Prototype name of the item to count. If not specified, count all items. |
Does this inventory contain nothing?
Is every stack in this inventory full? Ignores stacks blocked by the current bar.
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 the current bar. This is the index at which the red area starts.
Only useable if this inventory supports having a bar.
Set the current bar.
bar | :: uint? |
The new limit. Omitting this parameter will clear the limit. |
The new limit. Omitting this parameter will clear the limit. |
Only useable if this inventory supports having a bar.
If this inventory supports filters.
If this inventory supports filters and has at least 1 filter set.
Sets the filter for the given item stack index.
index | :: uint |
The item stack index. |
The item stack index. |
||
filter | :: string or nil |
The new filter. |
The new filter. |
→ boolean |
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).
Finds the first LuaItemStack in the inventory that matches the given item name.
item | :: string |
The item name to find |
The item name to find |
→ LuaItemStack? |
The first matching stack, or |
→ uint? |
The stack index of the matching stack, if any is found. |
Finds the first empty stack. Filtered slots are excluded unless a filter item is given.
item | :: string? |
If given, empty stacks that are filtered for this item will be included. |
If given, empty stacks that are filtered for this item will be included. |
→ LuaItemStack? |
The first empty stack, or |
→ uint? |
The stack index of the matching stack, if any is found. |
Counts the number of empty stacks.
include_filtered | :: boolean? |
If true, filtered slots will be included. Defaults to false. |
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. |
If true, slots blocked by the current bar will be included. Defaults to true. |
Gets the number of the given item that can be inserted into this inventory.
item | :: string |
The item to check. |
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.
Resizes the inventory.
size | :: uint16 |
New size of a inventory |
New size of a inventory |
on_pre_script_inventory_resized instantly |
|
on_script_inventory_resized instantly |
|
Items in slots beyond the new capacity are deleted.
Only inventories created by LuaGameScript::create_inventory can be resized.
Destroys this inventory.
Only inventories created by LuaGameScript::create_inventory can be destroyed this way.
All methods and properties that this object supports.
The inventory index this inventory uses, if any.
The entity that owns this inventory, if any.
The player that owns this inventory, if any.
The equipment that owns this inventory, if any.
The mod that owns this inventory, if any.
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.
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.
Get the number of slots in this inventory.
Will print the number of slots in the player's main inventory.
|
The indexing operator.
Will get the first item in the player's inventory.
|