Skip to main content

LuaInventory

Struct LuaInventory 

Source
pub struct LuaInventory;
Expand description

A storage of item stacks.

Implementations§

Source§

impl LuaInventory

Source

pub fn entity_owner(&self) -> LuaEntity

The entity that owns this inventory, if any.

Source

pub fn equipment_owner(&self) -> LuaEquipment

The equipment that owns this inventory, if any.

Source

pub fn index(&self) -> &str

The inventory index this inventory uses, if any.

Source

pub fn max_weight(&self) -> LuaAny

Gives a maximum weight of items that can be inserted into this inventory.

Source

pub fn mod_owner(&self) -> &str

The mod that owns this inventory, if any.

Source

pub fn name(&self) -> &str

Name of this inventory, if any. Names match keys of defines.inventory.

Source

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.

Source

pub fn player_owner(&self) -> LuaPlayer

The player that owns this inventory, if any.

Source

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.

Source

pub fn weight(&self) -> LuaAny

Gives a total weight of all items currently in this inventory.

Source

pub fn can_insert(&self, items: LuaAny) -> bool

Can at least some items be inserted?

Source

pub fn can_set_filter(&self, filter: ItemFilter, index: u32) -> bool

If the given inventory slot filter can be set to the given filter.

Source

pub fn clear(&self)

Clear this inventory of all items so that it becomes empty.

Source

pub fn count_empty_stacks( &self, include_bar: Option<bool>, include_filtered: Option<bool>, ) -> u32

Counts the number of empty stacks.

Source

pub fn destroy(&self)

Destroys this inventory.

Only inventories created by LuaGameScript::create_inventory can be destroyed this way.

Source

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.

Source

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.

Source

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.

Source

pub fn get_contents(&self) -> Vec<ItemWithQualityCount>

Get counts of all items in this inventory.

Source

pub fn get_filter(&self, index: u32) -> Option<ItemFilter>

Gets the filter for the given item stack index.

Source

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.

Source

pub fn get_item_count(&self, item: Option<LuaAny>) -> u32

Get the number of all or some items in this inventory.

Source

pub fn get_item_count_filtered(&self, filter: ItemFilter) -> u32

Get the number of items in this inventory that match provided filter.

Source

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.

Source

pub fn insert(&self, items: LuaAny) -> u32

Insert items into this inventory.

Source

pub fn is_empty(&self) -> bool

Does this inventory contain nothing?

Source

pub fn is_filtered(&self) -> bool

If this inventory supports filters and has at least 1 filter set.

Source

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.

Source

pub fn remove(&self, items: LuaAny) -> u32

Remove items from this inventory.

Source

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.

Source

pub fn set_bar(&self, bar: Option<u32>)

Set the current bar.

Only useable if this inventory supports having a bar.

Source

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).

Source

pub fn sort_and_merge(&self)

Sorts and merges the items in this inventory.

Source

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.

Source

pub fn supports_filters(&self) -> bool

If this inventory supports filters.

Source

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.

Source

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

Source§

fn clone(&self) -> LuaInventory

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LuaInventory

Source§

impl Debug for LuaInventory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LuaInventory

Source§

fn default() -> LuaInventory

Returns the “default value” for a type. Read more
Source§

impl Eq for LuaInventory

Source§

impl From<LuaInventory> for LuaAny

Source§

fn from(_: LuaInventory) -> Self

Converts to this type from the input type.
Source§

impl LuaObject for LuaInventory

Source§

impl PartialEq for LuaInventory

Source§

fn eq(&self, other: &LuaInventory) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LuaInventory

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.