Factorio API Docs

1.1.53 <>

Class LuaItemStack

A reference to an item and count owned by some external entity.

Notes

In most instances this is a simple reference as in: it points at a specific slot in an inventory and not the item in the slot.

In the instance this references an item on a LuaTransportLine the reference is only guaranteed to stay valid (and refer to the same item) as long as nothing changes the transport line.

boolean

Is this blueprint item setup?


→ array[BlueprintEntity]

The entities in this blueprint.


Set new entities to be a part of this blueprint.


add_ammo(amount)

Add ammo to this ammo item.


drain_ammo(amount)

Remove ammo from this ammo item.


add_durability(amount)

Add durability to this tool item.


Remove durability from this tool item.


can_set_stack(stack)
boolean

Would a call to LuaItemStack::set_stack succeed?


set_stack(stack)
boolean

Set this item stack to another item stack.


boolean

Transfers the given item stack into this item stack.


string

Export a supported item (blueprint, blueprint-book, deconstruction-planner, upgrade-planner, item-with-tags) to a string.


import_stack(data)
int

Import a supported item (blueprint, blueprint-book, deconstruction-planner, upgrade-planner, item-with-tags) from a string.


swap_stack(stack)
boolean

Swaps this item stack with the given item stack if allowed.


clear()

Clear this item stack.


→ array[Tile]

A list of the tiles in this blueprint.


Set specific tiles in this blueprint.


get_inventory(inventory)

Access the inner inventory of an item.


build_blueprint{surface, force, position, force_build, direction, skip_fog_of_war, by_player, raise_built}
→ array[LuaEntity]

deconstruct_area{surface, force, area, skip_fog_of_war, by_player}

Deconstruct the given area with this deconstruction item.


cancel_deconstruct_area{surface, force, area, skip_fog_of_war, by_player}

Cancel deconstruct the given area with this deconstruction item.


create_blueprint{surface, force, area, always_include_tiles, include_entities, include_modules, include_station_names, include_trains, include_fuel}
→ dictionary[uintLuaEntity]

Sets up this blueprint using the found blueprintable entities/tiles on the surface.


get_tag(tag_name)
AnyBasic

Gets the tag with the given name or returns nil if it doesn't exist.


set_tag(tag_name, tag)
AnyBasic

Sets the tag with the given name and value.


remove_tag(tag)
boolean

Removes a tag with the given name.


Clears this blueprint item.


string

Gets the entity filter at the given index for this deconstruction item.


set_entity_filter(index, filter)
boolean

Sets the entity filter at the given index for this deconstruction item.


string

Gets the tile filter at the given index for this deconstruction item.


set_tile_filter(index, filter)
boolean

Sets the tile filter at the given index for this deconstruction item.


Clears all settings/filters on this deconstruction item resetting it to default values.


Clears all settings/filters on this upgrade item resetting it to default values.


get_mapper(index, type)

Gets the filter at the given index for this upgrade item.


set_mapper(index, type, filter)

Sets the module filter at the given index for this upgrade item.


uint

Gets the number of entities in this blueprint item.


Tags

Gets the tags for the given blueprint entity index in this blueprint item.


Sets the tags on the given blueprint entity index in this blueprint item.


AnyBasic

Gets the given tag on the given blueprint entity index in this blueprint item.


set_blueprint_entity_tag(index, tag, value)

Sets the given tag on the given blueprint entity index in this blueprint item.


Creates the equipment grid for this item if it doesn't exist and this is an item-with-entity-data that supports equipment grids.


help()
string

All methods and properties that this object supports.


:: boolean
[R]

Is this valid for reading?


[R]

Prototype of the item held in this stack.


:: string
[R]

Prototype name of the item held in this stack.


:: string
[R]

Type of the item prototype.


:: uint
[RW]

Number of items in this stack.


[R]

The equipment grid of this item or nil if this item doesn't have a grid.


:: float
[RW]

How much health the item has, as a number in range [0, 1].


:: double
[RW]

Durability of the contained item.


:: uint
[RW]

Number of bullets left in the magazine.


[RW]

Icons of a blueprint item, blueprint book, deconstruction item or upgrade planner.


[RW]

The snapping grid size in this blueprint item or nil if snapping is not enabled.


[RW]

The offset from the absolute grid or nil if absolute snapping is not enabled.


:: boolean
[RW]

If absolute snapping is enabled on this blueprint item.


:: string
[RW]

The current label for this item.


:: Color
[RW]

The current label color for this item.


:: boolean
[RW]

If the label for this item can be manually changed.


:: dictionary[stringuint]
[R]

Raw materials required to build this blueprint.


:: boolean
[RW]

If this item extends the inventory it resides in (provides its contents for counts, crafting, insertion).


:: string
[RW]

The insertion mode priority this ItemWithInventory uses when items are inserted into an inventory it resides in.


:: array[BlueprintItemIcon]
[R]

The default icons for a blueprint item.


:: Tags
[RW]

[RW]

The custom description this item-with-tags.


:: array[string]
[RW]

The entity filters for this deconstruction item.


:: array[string]
[RW]

The tile filters for this deconstruction item.


[RW]

The blacklist/whitelist entity filter mode for this deconstruction item.


[RW]

The blacklist/whitelist tile filter mode for this deconstruction item.


[RW]

The tile selection mode for this deconstruction item.


:: boolean
[RW]

If this deconstruction item is set to allow trees and rocks only.


:: uint
[R]

The number of entity filters this deconstruction item supports.


:: uint
[R]

The number of tile filters this deconstruction item supports.


:: uint
[RW]

The active blueprint index for this blueprint book.


:: uint
[R]

The unique identifier for this item if it has one, nil otherwise.


[RW]

If this item is a spidertron remote that has a spidertron bound to it, it returns the connected spider-vehicle entity, nil otherwise.


:: boolean
[R]

If this is a blueprint item.


:: boolean
[R]

If this is a blueprint book item.


:: boolean
[R]

If this is a module item.


:: boolean
[R]

If this is a tool item.


:: boolean
[R]

If this is a mining tool item.


:: boolean
[R]

If this is an armor item.


:: boolean
[R]

If this is a repair tool item.


:: boolean
[R]

If this is an item with label item.


:: boolean
[R]

If this is an item with inventory item.


:: boolean
[R]

If this is an item with entity data item.


:: boolean
[R]

If this is a selection tool item.


:: boolean
[R]

If this is an item with tags item.


:: boolean
[R]

If this is a deconstruction tool item.


:: boolean
[R]

If this is a upgrade item.


:: boolean
[R]

Is this object valid?


:: string
[R]

The class name of this object.

Methods

is_blueprint_setup () → boolean

Is this blueprint item setup? I.e. is it a non-empty blueprint?


get_blueprint_entities () → array[BlueprintEntity]

The entities in this blueprint.

Can only be used if this is BlueprintItem

set_blueprint_entities (entities)

Set new entities to be a part of this blueprint.

Parameters

entities
:: array[BlueprintEntity]

The new blueprint entities.

Can only be used if this is BlueprintItem

add_ammo (amount)

Add ammo to this ammo item.

Parameters

amount
:: float

Amount of ammo to add.

Can only be used if this is AmmoItem

drain_ammo (amount)

Remove ammo from this ammo item.

Parameters

amount
:: float

Amount of ammo to remove.

Can only be used if this is AmmoItem

add_durability (amount)

Add durability to this tool item.

Parameters

amount
:: double

Amount of durability to add.

Can only be used if this is ToolItem

drain_durability (amount)

Remove durability from this tool item.

Parameters

amount
:: double

Amount of durability to remove.

Can only be used if this is ToolItem

can_set_stack (stack) → boolean

Would a call to LuaItemStack::set_stack succeed?

Parameters

stack
Optional

Stack that would be set, possibly nil.


set_stack (stack) → boolean

Set this item stack to another item stack.

Parameters

stack
Optional

Item stack to set this one to. Omitting this parameter or passing nil will clear this item stack, as if by calling LuaItemStack::clear.

Return value

Was the stack set successfully?


transfer_stack (stack) → boolean

Transfers the given item stack into this item stack.

Parameters

Return value

True if the full stack was transferred.


export_stack () → string

Export a supported item (blueprint, blueprint-book, deconstruction-planner, upgrade-planner, item-with-tags) to a string.

Return value

The exported string


import_stack (data) → int

Import a supported item (blueprint, blueprint-book, deconstruction-planner, upgrade-planner, item-with-tags) from a string.

Parameters

data
:: string

The string to import

Return value

0 if the import succeeded with no errors. -1 if the import succeeded with errors. 1 if the import failed.


swap_stack (stack) → boolean

Swaps this item stack with the given item stack if allowed.

Parameters

stack

Return value

if the 2 stacks were swapped successfully.


clear ()

Clear this item stack.


get_blueprint_tiles () → array[Tile]

A list of the tiles in this blueprint.

Can only be used if this is BlueprintItem

set_blueprint_tiles (tiles)

Set specific tiles in this blueprint.

Parameters

tiles
:: array[Tile]

Tiles to be a part of the blueprint.

Can only be used if this is BlueprintItem

get_inventory (inventory) → LuaInventory

Access the inner inventory of an item.

Parameters

inventory

Index of the inventory to access -- currently can only be defines.inventory.item_main.

Return value

or nil if there is no inventory with the given index.


build_blueprint {surface, force, position, force_build, direction, skip_fog_of_war, by_player, raise_built} → array[LuaEntity]

Parameters

Table with the following fields:
surface

Surface to build on


force

Force to use for the building


position

The position to build at


force_build
:: boolean
Optional

When true, anything that can be built is else nothing is built if any one thing can't be built


direction
Optional

The direction to use when building


skip_fog_of_war
:: boolean
Optional

If chunks covered by fog-of-war are skipped.


by_player
Optional

The player to use if any. If provided defines.events.on_built_entity will also be fired on successful entity creation.


raise_built
:: boolean
Optional

If true; defines.events.script_raised_built will be fired on successful entity creation. Note: this is ignored if by_player is provided.

Return value

Array of created ghosts

Note

Built entities can be come invalid between the building of the blueprint and the function returning if by_player or raise_built is used and one of those events invalidates the entity.


deconstruct_area {surface, force, area, skip_fog_of_war, by_player}

Deconstruct the given area with this deconstruction item.

Parameters

Table with the following fields:
surface

Surface to deconstruct on


force

Force to use for the deconstruction


area

The area to deconstruct


skip_fog_of_war
:: boolean
Optional

If chunks covered by fog-of-war are skipped.


by_player
Optional

The player to use if any.


cancel_deconstruct_area {surface, force, area, skip_fog_of_war, by_player}

Cancel deconstruct the given area with this deconstruction item.

Parameters

Table with the following fields:
surface

Surface to cancel deconstruct on


force

Force to use for canceling deconstruction


area

The area to deconstruct


skip_fog_of_war
:: boolean
Optional

If chunks covered by fog-of-war are skipped.


by_player
Optional

The player to use if any.


create_blueprint {surface, force, area, always_include_tiles, include_entities, include_modules, include_station_names, include_trains, include_fuel} → dictionary[uintLuaEntity]

Sets up this blueprint using the found blueprintable entities/tiles on the surface.

Parameters

Table with the following fields:
surface

Surface to create from


force

Force to use for the creation


area

The bounding box


always_include_tiles
:: boolean
Optional

When true, blueprintable tiles are always included in the blueprint. When false they're only included if no entities exist in the setup area.


include_entities
:: boolean
Optional

When true, entities are included in the blueprint. Defaults to true.


include_modules
:: boolean
Optional

When true, modules are included in the blueprint. Defaults to true.


include_station_names
:: boolean
Optional

When true, station names are included in the blueprint. Defaults to false.


include_trains
:: boolean
Optional

When true, trains are included in the blueprint. Defaults to false.


include_fuel
:: boolean
Optional

When true, train fuel is included in the blueprint, Defaults to true.

Return value

The blueprint entity index to source entity mapping.


get_tag (tag_name) → AnyBasic

Gets the tag with the given name or returns nil if it doesn't exist.

Parameters

tag_name
:: string
Can only be used if this is ItemWithTags

set_tag (tag_name, tag) → AnyBasic

Sets the tag with the given name and value.

Parameters

tag_name
:: string

tag
Can only be used if this is ItemWithTags

remove_tag (tag) → boolean

Removes a tag with the given name.

Parameters

tag
:: string

Return value

If the tag existed and was removed.

Can only be used if this is ItemWithTags

clear_blueprint ()

Clears this blueprint item.

Can only be used if this is BlueprintItem

get_entity_filter (index) → string

Gets the entity filter at the given index for this deconstruction item.

Parameters

index
:: uint
Can only be used if this is DeconstructionItem

set_entity_filter (index, filter) → boolean

Sets the entity filter at the given index for this deconstruction item.

Parameters

index
:: uint

filter

Setting to nil erases the filter.

Return value

If the new filter was set (was valid.)

Can only be used if this is DeconstructionItem

get_tile_filter (index) → string

Gets the tile filter at the given index for this deconstruction item.

Parameters

index
:: uint
Can only be used if this is DeconstructionItem

set_tile_filter (index, filter) → boolean

Sets the tile filter at the given index for this deconstruction item.

Parameters

index
:: uint

filter

Setting to nil erases the filter.

Return value

If the new filter was set (was valid.)

Can only be used if this is DeconstructionItem

clear_deconstruction_item ()

Clears all settings/filters on this deconstruction item resetting it to default values.

Can only be used if this is DeconstructionItem

clear_upgrade_item ()

Clears all settings/filters on this upgrade item resetting it to default values.

Can only be used if this is UpgradeItem

get_mapper (index, type) → UpgradeFilter

Gets the filter at the given index for this upgrade item.

Parameters

index
:: uint

The index of the mapper to read.


type
:: string

'from' or 'to'.

Can only be used if this is UpgradeItem

set_mapper (index, type, filter)

Sets the module filter at the given index for this upgrade item.

Parameters

index
:: uint

The index of the mapper to set.


type
:: string

from or to.


filter

The filter to set or nil

Can only be used if this is UpgradeItem

get_blueprint_entity_count () → uint

Gets the number of entities in this blueprint item.

Can only be used if this is BlueprintItem

get_blueprint_entity_tags (index) → Tags

Gets the tags for the given blueprint entity index in this blueprint item.

Parameters

index
:: uint
Can only be used if this is BlueprintItem

set_blueprint_entity_tags (index, tags)

Sets the tags on the given blueprint entity index in this blueprint item.

Parameters

index
:: uint

The entity index


tags
:: Tags
Can only be used if this is BlueprintItem

get_blueprint_entity_tag (index, tag) → AnyBasic

Gets the given tag on the given blueprint entity index in this blueprint item.

Parameters

index
:: uint

The entity index.


tag
:: string

The tag to get.

Can only be used if this is BlueprintItem

set_blueprint_entity_tag (index, tag, value)

Sets the given tag on the given blueprint entity index in this blueprint item.

Parameters

index
:: uint

The entity index.


tag
:: string

The tag to set.


value

The tag value to set or nil to clear the tag.

Can only be used if this is BlueprintItem

create_grid () → LuaEquipmentGrid

Creates the equipment grid for this item if it doesn't exist and this is an item-with-entity-data that supports equipment grids.

Can only be used if this is ItemWithEntityData

help () → string

All methods and properties that this object supports.

Attributes

valid_for_read :: boolean [Read]

Is this valid for reading? Differs from the usual valid in that valid will be true even if the item stack is blank but the entity that holds it is still valid.


prototype :: LuaItemPrototype [Read]

Prototype of the item held in this stack.


name :: string [Read]

Prototype name of the item held in this stack.


type :: string [Read]

Type of the item prototype.


count :: uint [Read/Write]

Number of items in this stack.


grid :: LuaEquipmentGrid [Read]

The equipment grid of this item or nil if this item doesn't have a grid.


health :: float [Read/Write]

How much health the item has, as a number in range [0, 1].


durability :: double [Read/Write]

Durability of the contained item. Automatically capped at the item's maximum durability.

Note

When used on a non-tool item, the value of this attribute is nil.


ammo :: uint [Read/Write]

Number of bullets left in the magazine.


blueprint_icons :: array[BlueprintSignalIcon] [Read/Write]

Icons of a blueprint item, blueprint book, deconstruction item or upgrade planner. An item that doesn't have icons returns nil on read and throws error on write.


blueprint_snap_to_grid :: Position [Read/Write]

The snapping grid size in this blueprint item or nil if snapping is not enabled.


blueprint_position_relative_to_grid :: Position [Read/Write]

The offset from the absolute grid or nil if absolute snapping is not enabled.


blueprint_absolute_snapping :: boolean [Read/Write]

If absolute snapping is enabled on this blueprint item.


label :: string [Read/Write]

The current label for this item. Nil when none.


label_color :: Color [Read/Write]

The current label color for this item. Nil when none.


allow_manual_label_change :: boolean [Read/Write]

If the label for this item can be manually changed. When false the label can only be changed through the API.


cost_to_build :: dictionary[stringuint] [Read]

Raw materials required to build this blueprint. Result is a dictionary mapping each item prototype name to the required count.


extends_inventory :: boolean [Read/Write]

If this item extends the inventory it resides in (provides its contents for counts, crafting, insertion). Only callable on items with inventories.


prioritize_insertion_mode :: string [Read/Write]

The insertion mode priority this ItemWithInventory uses when items are inserted into an inventory it resides in. Only callable on items with inventories.


default_icons :: array[BlueprintItemIcon] [Read]

The default icons for a blueprint item.


tags :: Tags [Read/Write]


custom_description :: LocalisedString [Read/Write]

The custom description this item-with-tags. This is shown over the normal item description if this is set to a non-empty value.


entity_filters :: array[string] [Read/Write]

The entity filters for this deconstruction item. The attribute is a sparse array with the keys representing the index of the filter. All strings in this array must be entity prototype names that don't have the "not-deconstructable" flag set and are either a cliff or marked as minable.


tile_filters :: array[string] [Read/Write]

The tile filters for this deconstruction item. The attribute is a sparse array with the keys representing the index of the filter. All strings in this array must be tile prototype names.


entity_filter_mode :: defines.deconstruction_item.entity_filter_mode [Read/Write]

The blacklist/whitelist entity filter mode for this deconstruction item.


tile_filter_mode :: defines.deconstruction_item.tile_filter_mode [Read/Write]

The blacklist/whitelist tile filter mode for this deconstruction item.


tile_selection_mode :: defines.deconstruction_item.tile_selection_mode [Read/Write]

The tile selection mode for this deconstruction item.


trees_and_rocks_only :: boolean [Read/Write]

If this deconstruction item is set to allow trees and rocks only.


entity_filter_count :: uint [Read]

The number of entity filters this deconstruction item supports.


tile_filter_count :: uint [Read]

The number of tile filters this deconstruction item supports.


active_index :: uint [Read/Write]

The active blueprint index for this blueprint book. May be nil.


item_number :: uint [Read]

The unique identifier for this item if it has one, nil otherwise. Note that this ID stays the same no matter where the item is moved to.

Only these types of items have unique IDs:
- "armor"
- "spidertron-remote"
- "selection-tool"
- "copy-paste-tool"
- "upgrade-item"
- "deconstruction-item"
- "blueprint"
- "blueprint-book"
- "item-with-entity-data"
- "item-with-inventory"
- "item-with-tags"


connected_entity :: LuaEntity [Read/Write]

If this item is a spidertron remote that has a spidertron bound to it, it returns the connected spider-vehicle entity, nil otherwise.


is_blueprint :: boolean [Read]

If this is a blueprint item.


is_blueprint_book :: boolean [Read]

If this is a blueprint book item.


is_module :: boolean [Read]

If this is a module item.


is_tool :: boolean [Read]

If this is a tool item.


is_mining_tool :: boolean [Read]

If this is a mining tool item.


is_armor :: boolean [Read]

If this is an armor item.


is_repair_tool :: boolean [Read]

If this is a repair tool item.


is_item_with_label :: boolean [Read]

If this is an item with label item.


is_item_with_inventory :: boolean [Read]

If this is an item with inventory item.


is_item_with_entity_data :: boolean [Read]

If this is an item with entity data item.


is_selection_tool :: boolean [Read]

If this is a selection tool item.


is_item_with_tags :: boolean [Read]

If this is an item with tags item.


is_deconstruction_item :: boolean [Read]

If this is a deconstruction tool item.


is_upgrade_item :: boolean [Read]

If this is a upgrade item.


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.

|<

Classes

Events

Concepts

Defines

Builtin types

>|