Struct veloren_common_net::synced_components::inner::Item

pub struct Item {
    item_id: Arc<AtomicCell<Option<NonZero<u64>>>>,
    item_base: ItemBase,
    components: Vec<Item>,
    amount: NonZero<u32>,
    slots: Vec<Option<Item>>,
    item_config: Option<Box<ItemConfig>>,
    hash: u64,
    durability_lost: Option<u32>,
}
Expand description

NOTE: Do not call Item::clone without consulting the core devs! It only exists due to being required for message serialization at the moment, and should not be used for any other purpose.

FIXME: Turn on a Clippy lint forbidding the use of Item::clone using the disallowed_method feature.

Fields§

§item_id: Arc<AtomicCell<Option<NonZero<u64>>>>§item_base: ItemBase§components: Vec<Item>§amount: NonZero<u32>§slots: Vec<Option<Item>>§item_config: Option<Box<ItemConfig>>§hash: u64§durability_lost: Option<u32>

Implementations§

§

impl Item

pub const MAX_DURABILITY: u32 = 12u32

pub fn empty() -> Item

pub fn new_from_item_base( inner_item: ItemBase, components: Vec<Item>, ability_map: &AbilityMap, msm: &MaterialStatManifest, ) -> Item

pub fn new_from_item_definition_id( item_definition_id: ItemDefinitionId<'_>, ability_map: &AbilityMap, msm: &MaterialStatManifest, ) -> Result<Item, Error>

pub fn new_from_asset_expect(asset_specifier: &str) -> Item

Creates a new instance of an Item from the provided asset identifier Panics if the asset does not exist.

pub fn new_from_asset_glob(asset_glob: &str) -> Result<Vec<Item>, Error>

Creates a Vec containing one of each item that matches the provided asset glob pattern

pub fn new_from_asset(asset: &str) -> Result<Item, Error>

Creates a new instance of an `Item from the provided asset identifier if it exists

pub fn frontend_item( &self, ability_map: &AbilityMap, msm: &MaterialStatManifest, ) -> FrontendItem

Creates a FrontendItem out of this item for frontend use

pub fn duplicate( &self, ability_map: &AbilityMap, msm: &MaterialStatManifest, ) -> Item

Duplicates an item, creating an exact copy but with a new item ID

pub fn stacked_duplicates<'a>( &'a self, ability_map: &'a AbilityMap, msm: &'a MaterialStatManifest, count: u32, ) -> impl Iterator<Item = Item> + 'a

pub fn put_in_world(&mut self)

Removes the unique identity of an item - used when dropping an item on the floor. In the future this will need to be changed if we want to maintain a unique ID for an item even when it’s dropped and picked up by another player.

pub fn increase_amount( &mut self, increase_by: u32, ) -> Result<(), OperationFailure>

pub fn decrease_amount( &mut self, decrease_by: u32, ) -> Result<(), OperationFailure>

pub fn set_amount(&mut self, give_amount: u32) -> Result<(), OperationFailure>

pub fn persistence_access_add_component(&mut self, component: Item)

pub fn persistence_access_mutable_component( &mut self, index: usize, ) -> Option<&mut Item>

pub fn update_item_state( &mut self, ability_map: &AbilityMap, msm: &MaterialStatManifest, )

Updates state of an item (important for creation of new items, persistence, and if components are ever added to items after initial creation)

pub fn drain(&mut self) -> impl Iterator<Item = Item>

Returns an iterator that drains items contained within the item’s slots

pub fn item_definition_id(&self) -> ItemDefinitionId<'_>

pub fn is_same_item_def(&self, item_def: &ItemDef) -> bool

pub fn matches_recipe_input( &self, recipe_input: &RecipeInput, amount: u32, ) -> bool

pub fn is_salvageable(&self) -> bool

pub fn salvage_output(&self) -> impl Iterator<Item = (&str, u32)>

pub fn name(&self) -> Cow<'_, str>

👎Deprecated: since item i18n

pub fn description(&self) -> &str

👎Deprecated: since item i18n

pub fn kind(&self) -> Cow<'_, ItemKind>

pub fn amount(&self) -> u32

pub fn is_stackable(&self) -> bool

pub fn num_slots(&self) -> u16

pub fn max_amount(&self) -> u32

NOTE: invariant that amount() ≤ max_amount(), 1 ≤ max_amount(), and if !self.is_stackable(), self.max_amount() = 1.

pub fn quality(&self) -> Quality

pub fn components(&self) -> &[Item]

pub fn slots(&self) -> &[Option<Item>]

pub fn slots_mut(&mut self) -> &mut [Option<Item>]

pub fn item_config(&self) -> Option<&ItemConfig>

pub fn free_slots(&self) -> usize

pub fn populated_slots(&self) -> usize

pub fn slot(&self, slot: usize) -> Option<&Option<Item>>

pub fn slot_mut(&mut self, slot: usize) -> Option<&mut Option<Item>>

pub fn try_reclaim_from_block(block: Block) -> Option<Vec<(u32, Item)>>

pub fn ability_spec(&self) -> Option<Cow<'_, AbilitySpec>>

pub fn tags(&self) -> Vec<ItemTag>

pub fn is_modular(&self) -> bool

pub fn item_hash(&self) -> u64

pub fn persistence_item_id(&self) -> String

pub fn durability_lost(&self) -> Option<u32>

pub fn stats_durability_multiplier(&self) -> DurabilityMultiplier

pub fn has_durability(&self) -> bool

pub fn increment_damage( &mut self, ability_map: &AbilityMap, msm: &MaterialStatManifest, )

pub fn persistence_durability(&self) -> Option<NonZero<u32>>

pub fn persistence_set_durability(&mut self, value: Option<NonZero<u32>>)

pub fn reset_durability( &mut self, ability_map: &AbilityMap, msm: &MaterialStatManifest, )

pub fn take_half( &mut self, ability_map: &AbilityMap, msm: &MaterialStatManifest, ) -> Option<Item>

If an item is stackable and has an amount greater than 1, creates a new item with half the amount (rounded down), and decreases the amount of the original item by the same quantity.

pub fn can_merge(&self, other: &Item) -> bool

Checks if this item and another are suitable for grouping into the same [PickItem].

Also see Item::try_merge.

pub fn try_merge(&mut self, other: Item) -> Result<Option<Item>, Item>

Checks if this item and another are suitable for grouping into the same [PickItem] and combines stackable items if possible.

If the sum of both amounts is larger than their max amount, a remainder item is returned as Ok(Some(remainder)). A remainder item will always be produced for non-stackable items.

If the items are not suitable for grouping Err(other) will be returned.

pub fn persistence_item_base(&self) -> &ItemBase

Trait Implementations§

§

impl Clone for Item

§

fn clone(&self) -> Item

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl Debug for Item

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for Item

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Item, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl From<&Item> for Body

§

fn from(item: &Item) -> Body

Converts to this type from the input type.
§

impl Hash for Item

§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl ItemDesc for Item

§

fn description(&self) -> &str

👎Deprecated: since item i18n
§

fn name(&self) -> Cow<'_, str>

👎Deprecated: since item i18n
§

fn kind(&self) -> Cow<'_, ItemKind>

§

fn amount(&self) -> NonZero<u32>

§

fn quality(&self) -> Quality

§

fn num_slots(&self) -> u16

§

fn item_definition_id(&self) -> ItemDefinitionId<'_>

§

fn tags(&self) -> Vec<ItemTag>

§

fn is_modular(&self) -> bool

§

fn components(&self) -> &[Item]

§

fn has_durability(&self) -> bool

§

fn durability_lost(&self) -> Option<u32>

§

fn stats_durability_multiplier(&self) -> DurabilityMultiplier

§

fn tool_info(&self) -> Option<ToolKind>

§

fn i18n(&self, i18n: &ItemI18n) -> (Content, Content)

Return name’s and description’s localization descriptors
§

impl PartialEq for Item

NOTE: This PartialEq instance is pretty broken! It doesn’t check item amount or any child items (and, arguably, doing so should be able to ignore things like item order within the main inventory or within each bag, and possibly even coalesce amounts, though these may be more controversial). Until such time as we find an actual need for a proper PartialEq instance, please don’t rely on this for anything!

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for Item

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Item

§

impl RefUnwindSafe for Item

§

impl Send for Item

§

impl Sync for Item

§

impl Unpin for Item

§

impl UnwindSafe for Item

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
§

impl<T> CallHasher for T
where T: Hash,

§

fn get_hash<H>(&self, hasher: H) -> u64
where H: Hasher,

source§

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

impl<C, M> ConvertSaveload<M> for C

§

type Data = C

(De)Serializable data representation for data type
§

type Error = Infallible

Error may occur during serialization or deserialization of component
§

fn convert_into<F>( &self, _: F, ) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
where F: FnMut(Entity) -> Option<M>,

Convert this data type into serializable form (Data) using entity to marker mapping function
§

fn convert_from<F>( data: <C as ConvertSaveload<M>>::Data, _: F, ) -> Result<C, <C as ConvertSaveload<M>>::Error>
where F: FnMut(M) -> Option<Entity>,

Convert this data from a deserializable form (Data) using entity to marker mapping function
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<Context> SubContext<Context> for Context

§

fn sub_context(self) -> Context

source§

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

§

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>,

§

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>,

§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Event for T
where T: Send + Sync + 'static,

§

impl<T> Resource for T
where T: Any + Send + Sync,

§

impl<T> Storable for T
where T: Send + Sync + 'static,