pub struct Experience {
level: i32,
progress: f32,
total_points: i32,
enchantment_seed: i32,
pub dirty: bool,
}Expand description
Player experience state.
Level, progress, and total points are independent: commands and save data
can change one without recomputing the others. The player’s score belongs
to super::Player’s synchronized entity data.
Fields§
§level: i32§progress: f32§total_points: i32§enchantment_seed: i32§dirty: boolWhether the client experience packet needs to be sent.
Implementations§
Source§impl Experience
impl Experience
Sourcepub fn new(total_points: i32) -> Self
pub fn new(total_points: i32) -> Self
Builds a coherent experience state from a total point count.
Sourcepub const fn from_parts(level: i32, progress: f32, total_points: i32) -> Self
pub const fn from_parts(level: i32, progress: f32, total_points: i32) -> Self
Restores the three independent vanilla experience fields without normalizing them.
Sourcepub const fn points_for_level(level: i32) -> i32
pub const fn points_for_level(level: i32) -> i32
Points required to advance from level to level + 1.
Sourcepub const fn total_points_at_level(level: i32) -> i32
pub const fn total_points_at_level(level: i32) -> i32
Returns a coherent cumulative point count at the start of level.
This is a Steel construction helper, not a field vanilla derives at runtime.
Sourcepub const fn total_points(&self) -> i32
pub const fn total_points(&self) -> i32
Total experience points earned, independent of the current level or progress.
Sourcepub const fn enchantment_seed(&self) -> i32
pub const fn enchantment_seed(&self) -> i32
Returns the enchantment seed; zero until loaded or the player first enchants
Sourcepub const fn with_enchantment_seed(self, seed: i32) -> Self
pub const fn with_enchantment_seed(self, seed: i32) -> Self
Returns this state with the given enchantment seed, used when restoring saves.
Sourcepub fn with_loaded_enchantment_seed(
self,
saved: i32,
reroll: impl FnOnce() -> i32,
) -> Self
pub fn with_loaded_enchantment_seed( self, saved: i32, reroll: impl FnOnce() -> i32, ) -> Self
Replaces a missing or zero saved XpSeed with a seed drawn from reroll
Sourcepub const fn add_levels(&mut self, additional_levels: i32)
pub const fn add_levels(&mut self, additional_levels: i32)
Adds levels with saturation, clearing progress and points if the result is negative.
Sourcepub const fn on_enchantment_performed(
&mut self,
enchantment_cost: i32,
next_seed: i32,
)
pub const fn on_enchantment_performed( &mut self, enchantment_cost: i32, next_seed: i32, )
Spends enchantment_cost levels and installs next_seed
Sourcepub fn add_points(&mut self, additional_points: i32)
pub fn add_points(&mut self, additional_points: i32)
Adds raw points, updating progress and level as thresholds are crossed.
Sourcepub const fn set_levels(&mut self, level: i32)
pub const fn set_levels(&mut self, level: i32)
Sets the current level without changing progress or total experience.
Sourcepub const fn can_set_points(&self, points: i32) -> bool
pub const fn can_set_points(&self, points: i32) -> bool
Whether /experience set ... points accepts points at the current level.
Sourcepub fn set_points(&mut self, points: i32)
pub fn set_points(&mut self, points: i32)
Sets points within the current level like ServerPlayer.setExperiencePoints.
Sourcepub const fn death_xp_reward(&self) -> i32
pub const fn death_xp_reward(&self) -> i32
Base XP reward dropped on death: min(level * 7, 100).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Experience
impl RefUnwindSafe for Experience
impl Send for Experience
impl Sync for Experience
impl Unpin for Experience
impl UnsafeUnpin for Experience
impl UnwindSafe for Experience
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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 moreArc<SyncMutex<>>