LuaItemStack

class LuaItemStack
is_blueprint_setup() → boolean Is this blueprint item setup?
get_blueprint_entities() → array of blueprint entity Entities in this blueprint.
set_blueprint_entities(entities) 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.
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.
clear() Clear this item stack.
get_blueprint_tiles() → array of blueprint tile Tiles in this blueprint
set_blueprint_tiles(tiles) Set tiles in this blueprint
valid :: boolean [R] Is this object valid?
valid_for_read :: boolean [R] Is this valid for reading?
prototype :: LuaItemPrototype [R] Prototype of the item held in this stack.
name :: string [R] Prototype name of the item held in this stack.
type :: string [R] Type of the item prototype.
count :: uint [RW] Number of items in this stack.
has_grid :: boolean [R] true if this item has an equipment grid.
grid :: LuaEquipmentGrid [R] The equipment grid of this item.
health :: float [RW] How much health the item has, as a number in range [0, 1].
durability :: uint [RW] Durability of the contained item.
ammo :: uint [RW] Number of bullets left in the magazine.
blueprint_icons :: array of Icon [RW] Icons of a blueprint item.
cost_to_build :: dictionary stringuint [R] Raw materials required to build this blueprint.

An item and a count.

is_blueprint_setup() → boolean

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

get_blueprint_entities() → array of blueprint entity

Entities in this blueprint.

Return value
The fields of an entity table depend on the type of the entity. Every entity has at least the following fields:
  • entity_number :: uint: Entity's unique identifier in this blueprint
  • name :: string: Prototype name of the entity
  • position :: Position: Position of the entity
  • direction :: defines.direction (optional): The direction the entity is facing. Only present for entities that can face in different directions.
  • other: Entity-specific fields...
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 of blueprint entity: New blueprint entities. The format is the same as in LuaItemStack::get_blueprint_entities.
Can only be used if this is BlueprintItem
add_ammo(amount)

Add ammo to this ammo item.

Parameters
amount :: uint: Amount of ammo to add.
Can only be used if this is AmmoItem
drain_ammo(amount)

Remove ammo from this ammo item.

Parameters
amount :: uint: Amount of ammo to remove.
Can only be used if this is AmmoItem
can_set_stack(stack) → boolean

Would a call to LuaItemStack::set_stack succeed?

Parameters
stack :: LuaItemStack or SimpleItemStack (optional): Stack that would be set, possibly nil.
set_stack(stack) → boolean

Set this item stack to another item stack.

Parameters
stack :: LuaItemStack or SimpleItemStack (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?
clear()

Clear this item stack.

get_blueprint_tiles() → array of blueprint tile

Tiles in this blueprint

Return value
A blueprint tile is a table:
Can only be used if this is BlueprintItem
set_blueprint_tiles(tiles)

Set tiles in this blueprint

Parameters
tiles :: array of blueprint tile: Tiles to be a part of the blueprint; the format is the same as is returned from the corresponding get function; see LuaItemStack::get_blueprint_tiles.
Can only be used if this is BlueprintItem
valid :: boolean [Read-only]

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.

valid_for_read :: boolean [Read-only]

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-only]

Prototype of the item held in this stack.

name :: string [Read-only]

Prototype name of the item held in this stack.

type :: string [Read-only]

Type of the item prototype.

count :: uint [Read-Write]

Number of items in this stack.

has_grid :: boolean [Read-only]

true if this item has an equipment grid.

grid :: LuaEquipmentGrid [Read-only]

The equipment grid of this item.

Note: Only useable when has_grid is true.
health :: float [Read-Write]

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

durability :: uint [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.

Can only be used if this is AmmoItem
blueprint_icons :: array of Icon [Read-Write]

Icons of a blueprint item. Every entry of this array has the following fields:

  • name :: string: Prototype name of the item whose icon to use
  • index :: uint: Index of the icon in the blueprint icons slots. Has to be in {1, 2, 3, 4}.

Can only be used if this is BlueprintItem
cost_to_build :: dictionary stringuint [Read-only]

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

Can only be used if this is BlueprintItem