Skip to main content

ItemData

Struct ItemData 

Source
pub struct ItemData<T> { /* private fields */ }
Expand description

A value kept in the data of the stack a player holds, at its key (the mod’s own: <mod>:<key>); its default where the stack has none yet.

ⓘ
static CHARGES: ItemData<u32> = ItemData::new("charges");
CHARGES.update(&use_item.player, use_item.off_hand, |n| *n = n.saturating_sub(1));

Implementations§

Source§

impl<T: Schema + Default> ItemData<T>

Source

pub const fn new(key: &'static str) -> Self

Source

pub fn get(&self, player: &str, off_hand: bool) -> T

The value on the stack player holds (off_hand: in its other hand); its default when the stack has none (or there’s no stack).

Source

pub fn held_here(&self, off_hand: bool) -> T

The value on the stack this client’s player holds (off_hand: in its other hand), as the server last sent the stack — the game sends stacks, so every ItemData is synced; its default when the stack has none (or there’s no stack).

Source

pub fn set(&self, player: &str, off_hand: bool, value: &T) -> bool

Puts value on the stack player holds; false when it holds nothing.

Source

pub fn update<R>( &self, player: &str, off_hand: bool, change: impl FnOnce(&mut T) -> R, ) -> Option<R>

The value on the stack player holds changed by change, and put back; what change returns, none when it holds nothing.

Auto Trait Implementations§

§

impl<T> Freeze for ItemData<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> RefUnwindSafe for ItemData<T>
where PhantomData<fn() -> T>: RefUnwindSafe,

§

impl<T> Send for ItemData<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Sync for ItemData<T>
where PhantomData<fn() -> T>: Sync,

§

impl<T> Unpin for ItemData<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for ItemData<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for ItemData<T>
where PhantomData<fn() -> T>: UnwindSafe,

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> Arg<T> for T

Source§

fn arg(self) -> T

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.