Struct veloren_common_net::synced_components::inner::inventory::item::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
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
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>
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>
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
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
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)
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,
)
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>
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>
pub fn description(&self) -> &str
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
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 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>
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
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>
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<'de> Deserialize<'de> for Item
impl<'de> Deserialize<'de> for Item
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Item, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Item, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl ItemDesc for Item
impl ItemDesc for Item
§fn description(&self) -> &str
fn description(&self) -> &str
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 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>
§impl PartialEq for Item
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!
§impl Serialize for Item
impl Serialize for Item
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<C, M> ConvertSaveload<M> for C
impl<C, M> ConvertSaveload<M> for C
§type Error = Infallible
type Error = Infallible
§fn convert_into<F>(
&self,
_: F,
) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
fn convert_into<F>( &self, _: F, ) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
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>
fn convert_from<F>( data: <C as ConvertSaveload<M>>::Data, _: F, ) -> Result<C, <C as ConvertSaveload<M>>::Error>
Data
) using
entity to marker mapping function§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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