pub struct LuaInventory;Expand description
A storage of item stacks.
Implementations§
Source§impl LuaInventory
impl LuaInventory
Sourcepub fn entity_owner(&self) -> LuaEntity
pub fn entity_owner(&self) -> LuaEntity
The entity that owns this inventory, if any.
Sourcepub fn equipment_owner(&self) -> LuaEquipment
pub fn equipment_owner(&self) -> LuaEquipment
The equipment that owns this inventory, if any.
Sourcepub fn max_weight(&self) -> LuaAny
pub fn max_weight(&self) -> LuaAny
Gives a maximum weight of items that can be inserted into this inventory.
Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
Name of this inventory, if any. Names match keys of defines.inventory.
Sourcepub fn object_name(&self) -> &str
pub fn object_name(&self) -> &str
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.
Sourcepub fn player_owner(&self) -> LuaPlayer
pub fn player_owner(&self) -> LuaPlayer
The player that owns this inventory, if any.
Sourcepub fn valid(&self) -> bool
pub fn valid(&self) -> bool
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.
Sourcepub fn can_insert(&self, items: LuaAny) -> bool
pub fn can_insert(&self, items: LuaAny) -> bool
Can at least some items be inserted?
Sourcepub fn can_set_filter(&self, filter: ItemFilter, index: u32) -> bool
pub fn can_set_filter(&self, filter: ItemFilter, index: u32) -> bool
If the given inventory slot filter can be set to the given filter.
Sourcepub fn count_empty_stacks(
&self,
include_bar: Option<bool>,
include_filtered: Option<bool>,
) -> u32
pub fn count_empty_stacks( &self, include_bar: Option<bool>, include_filtered: Option<bool>, ) -> u32
Counts the number of empty stacks.
Sourcepub fn destroy(&self)
pub fn destroy(&self)
Destroys this inventory.
Only inventories created by LuaGameScript::create_inventory can be destroyed this way.
Sourcepub fn find_empty_stack(
&self,
item: Option<LuaAny>,
) -> (Option<LuaItemStack>, Option<u32>)
pub fn find_empty_stack( &self, item: Option<LuaAny>, ) -> (Option<LuaItemStack>, Option<u32>)
Finds the first empty stack. Filtered slots are excluded unless a filter item is given.
Sourcepub fn find_item_stack(
&self,
item: LuaAny,
) -> (Option<LuaItemStack>, Option<u32>)
pub fn find_item_stack( &self, item: LuaAny, ) -> (Option<LuaItemStack>, Option<u32>)
Finds the first LuaItemStack in the inventory that matches the given item name.
Sourcepub fn get_bar(&self) -> u32
pub fn get_bar(&self) -> u32
Get the current bar. This is the index at which the red area starts.
Only useable if this inventory supports having a bar.
Sourcepub fn get_contents(&self) -> Vec<ItemWithQualityCount>
pub fn get_contents(&self) -> Vec<ItemWithQualityCount>
Get counts of all items in this inventory.
Sourcepub fn get_filter(&self, index: u32) -> Option<ItemFilter>
pub fn get_filter(&self, index: u32) -> Option<ItemFilter>
Gets the filter for the given item stack index.
Sourcepub fn get_insertable_count(&self, item: LuaAny) -> u32
pub fn get_insertable_count(&self, item: LuaAny) -> u32
Gets the number of the given item that can be inserted into this inventory.
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.
Sourcepub fn get_item_count(&self, item: Option<LuaAny>) -> u32
pub fn get_item_count(&self, item: Option<LuaAny>) -> u32
Get the number of all or some items in this inventory.
Sourcepub fn get_item_count_filtered(&self, filter: ItemFilter) -> u32
pub fn get_item_count_filtered(&self, filter: ItemFilter) -> u32
Get the number of items in this inventory that match provided filter.
Sourcepub fn get_item_quality_counts(
&self,
item: Option<LuaAny>,
) -> HashMap<String, u32>
pub fn get_item_quality_counts( &self, item: Option<LuaAny>, ) -> HashMap<String, u32>
Get the number of all or some items in this inventory, aggregated by quality.
Sourcepub fn is_filtered(&self) -> bool
pub fn is_filtered(&self) -> bool
If this inventory supports filters and has at least 1 filter set.
Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Is every stack in this inventory full? Ignores stacks blocked by the current bar.
For the input slots of crafting machines that allow counts larger than the item stack size, this may return true even when more items can still be inserted.
Sourcepub fn resize(&self, size: u16)
pub fn resize(&self, size: u16)
Resizes the inventory.
Items in slots beyond the new capacity are deleted.
Only inventories created by LuaGameScript::create_inventory can be resized.
Sourcepub fn set_bar(&self, bar: Option<u32>)
pub fn set_bar(&self, bar: Option<u32>)
Set the current bar.
Only useable if this inventory supports having a bar.
Sourcepub fn set_filter(&self, filter: Option<ItemFilter>, index: u32) -> bool
pub fn set_filter(&self, filter: Option<ItemFilter>, index: u32) -> bool
Sets the filter for the given item stack index.
Some inventory slots don’t allow some filters (gun ammo can’t be filtered for non-ammo).
Sourcepub fn sort_and_merge(&self)
pub fn sort_and_merge(&self)
Sorts and merges the items in this inventory.
Sourcepub fn supports_bar(&self) -> bool
pub fn supports_bar(&self) -> bool
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.
Sourcepub fn supports_filters(&self) -> bool
pub fn supports_filters(&self) -> bool
If this inventory supports filters.
Sourcepub fn transfer_from_inventory(
&self,
filter: Option<ItemFilter>,
source: LuaInventory,
) -> u32
pub fn transfer_from_inventory( &self, filter: Option<ItemFilter>, source: LuaInventory, ) -> u32
Transfer items from provided LuaInventory into this inventory.
Note that source inventory must be different than this inventory.
Sourcepub fn transfer_from_stack(&self, source: LuaItemStack) -> u32
pub fn transfer_from_stack(&self, source: LuaItemStack) -> u32
Transfer items from provided LuaItemStack into this inventory.
Note that source stack must not belong to this inventory.
Trait Implementations§
Source§impl Clone for LuaInventory
impl Clone for LuaInventory
Source§fn clone(&self) -> LuaInventory
fn clone(&self) -> LuaInventory
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more