Entity.Inventory
For working with inventories.
@usage local Inventory = require('kry_stdlib/stdlib/entity/inventory')
Methods8
function Inventory.each(inventory: LuaInventory, func: function, ...: any[opt]) -> LuaItemStack | nil
Given a function, apply it to each slot in the given inventory. Passes the index of a slot as the second argument to the given function. <p>Iteration is aborted if the applied function returns true for any element during iteration.
inventoryLuaInventorythe inventory to iterate
funcfunctionthe function to apply to values
...any[opt]additional arguments passed to the function
- LuaItemStack | nil
the slot where the iteration was aborted OR nil if not aborted
function Inventory.each_reverse(inventory: LuaInventory, func: function, ...: any[opt]) -> LuaItemStack | nil
Given a function, apply it to each slot in the given inventory. Passes the index of a slot as the second argument to the given function. <p>Iteration is aborted if the applied function returns true for any element during iteration. <p>Iteration is performed from last to first in order to support dynamically sized inventories.
inventoryLuaInventorythe inventory to iterate
funcfunctionthe function to apply to values
...any[opt]additional arguments passed to the function
- LuaItemStack | nil
the slot where the iteration was aborted OR nil if not aborted
function Inventory.copy_as_simple_stacks(src: LuaInventory, dest: LuaInventory, clear: boolean[opt]) -> ItemStackDefinition[]
Copies the contents of source inventory to destination inventory by using @{ItemStackDefinition}.
srcLuaInventorythe source inventory
destLuaInventorythe destination inventory
clearboolean[opt]
- ItemStackDefinition[]
an array of left over items that could not be inserted into the destination
function Inventory.get_blueprint(stack: LuaItemStack, is_bp_setup: nil | boolean, no_book: nil | boolean) -> LuaItemStack | nil
Return a blueprint stack from either stack or blueprint_book
stackLuaItemStackis_bp_setupnil | boolean[opt]
no_booknil | boolean[opt]
- LuaItemStack | nil
function Inventory.is_named_bp(stack: LuaItemStack, label: string) -> boolean
Is the stack a blueprint whose label begins with the specified text?
function Inventory.get_item_or_filter(inventory: LuaInventory, idx: integer, item_only: nil | boolean, filter_only: nil | boolean) -> any
Returns either the item at a position, or the filter at the position if there isn't an item there.
inventoryLuaInventoryidxintegeritem_onlynil | boolean[opt]
filter_onlynil | boolean[opt]
- any
the item or filter
function Inventory.transfer_inventory(source: LuaInventory, destination: LuaInventory, source_filters: table[opt]) -> nil | table
Transfer items from 1 inventory to another.
sourceLuaInventorydestinationLuaInventorysource_filterstable[opt]
- nil | table
the filters if the destination does not support filters
function Inventory.swap_inventory(source: LuaInventory, destination: LuaInventory) -> nil
Swap items from 1 inventory to another.
Fields2
Inventory.__class: string = "Inventory"
Inventory.__index : StdLib.Core