Home

LuaItemStack

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

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.

Parent

Attributes

valid_for_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

Prototype of the item held in this stack.

name

Prototype name of the item held in this stack.

type

Type of the item prototype.

count

Number of items in this stack.

health

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

quality

The quality of this item.

spoil_tick

The tick this item spoils, or 0 if it does not spoil. When writing, setting to anything < the current game tick will spoil the item instantly.

spoil_percent

The percent spoiled this item is if it spoils. 0 in the case of the item not spoiling.

item

If the item has additional data, returns LuaItem pointing at the extra data, otherwise returns nil.

is_module

If this is a module

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

add_ammo

LuaItemStack.add_ammo(amount: float)

Call As

itemStack.add_ammo(amount)

Call Convention

Add ammo to this ammo item.

Parameters

drain_ammo

LuaItemStack.drain_ammo(amount: float)

Call As

itemStack.drain_ammo(amount)

Call Convention

Remove ammo from this ammo item.

Parameters

add_durability

LuaItemStack.add_durability(amount: double)

Call As

itemStack.add_durability(amount)

Call Convention

Add durability to this tool item.

Parameters

drain_durability

LuaItemStack.drain_durability(amount: double)

Call As

itemStack.drain_durability(amount)

Call Convention

Remove durability from this tool item.

Parameters

use_capsule

LuaItemStack.use_capsule(entity: LuaEntity, target_position: MapPosition) -> Array<LuaEntity>

Call As

itemStack.use_capsule(entity, target_position)

Call Convention

Use the capsule item with the entity as the source, targeting the given position.

Parameters

Returns

can_set_stack

LuaItemStack.can_set_stack(stack?: ItemStackIdentification) -> boolean

Call As

itemStack.can_set_stack()

Call Convention

Would a call to LuaItemStack::set_stack succeed?

Parameters

Returns

set_stack

LuaItemStack.set_stack(stack?: ItemStackIdentification) -> boolean

Call As

itemStack.set_stack()

Call Convention

Set this item stack to another item stack.

Parameters

Returns

transfer_stack

LuaItemStack.transfer_stack(stack: ItemStackIdentification, amount?: uint32) -> boolean

Call As

itemStack.transfer_stack(stack, amount)

Call Convention

Transfers the given item stack into this item stack.

Parameters

Returns

export_stack

LuaItemStack.export_stack() -> string

Call As

itemStack.export_stack()

Call Convention

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

Returns

import_stack

LuaItemStack.import_stack(data: string) -> int32

Call As

itemStack.import_stack(data)

Call Convention

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

Parameters

Returns

swap_stack

LuaItemStack.swap_stack(stack: LuaItemStack) -> boolean

Call As

itemStack.swap_stack(stack)

Call Convention

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

Parameters

Returns

clear

LuaItemStack.clear()

Call As

itemStack.clear()

Call Convention

Clear this item stack.

create_grid

LuaItemStack.create_grid() -> LuaEquipmentGrid

Call As

itemStack.create_grid()

Call Convention

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

Returns

spoil

LuaItemStack.spoil()

Call As

itemStack.spoil()

Call Convention

Spoils this item if the item can spoil.