pub struct FoodData {
pub food_level: i32,
pub saturation_level: f32,
pub exhaustion_level: f32,
pub tick_timer: i32,
}Expand description
Tracks a player’s hunger, saturation, and exhaustion state.
One instance is stored per player behind a SyncMutex.
Fields§
§food_level: i32Current food level (0–20). Displayed as the hunger bar on the client.
saturation_level: f32Saturation buffer — consumed before the food level drops.
exhaustion_level: f32Accumulated exhaustion from actions (sprinting, jumping, damage, …).
tick_timer: i32Internal tick counter shared between regeneration and starvation logic.
Implementations§
Source§impl FoodData
impl FoodData
Sourcepub const fn needs_food(&self) -> bool
pub const fn needs_food(&self) -> bool
Returns true if the player’s food level is below maximum and they
could benefit from eating.
Sourcepub const fn has_enough_food(&self) -> bool
pub const fn has_enough_food(&self) -> bool
Returns true if the player has enough food to perform exhaustive
maneuvers (for example sprinting).
Sourcepub fn add_exhaustion(&mut self, amount: f32)
pub fn add_exhaustion(&mut self, amount: f32)
Adds exhaustion from an action (sprinting, jumping, taking damage, …).
The value is clamped so exhaustion_level never exceeds 40.
Sourcepub fn eat(&mut self, nutrition: i32, saturation_modifier: f32)
pub fn eat(&mut self, nutrition: i32, saturation_modifier: f32)
Applies the nutrition from eating food, given a saturation modifier.
Sourcepub fn tick(
&mut self,
difficulty: Difficulty,
natural_regen: bool,
current_health: f32,
max_health: f32,
) -> FoodTickResult
pub fn tick( &mut self, difficulty: Difficulty, natural_regen: bool, current_health: f32, max_health: f32, ) -> FoodTickResult
Runs one tick of the hunger system.
Returns a FoodTickResult describing what happened this tick so the
caller (Player::tick) can apply healing or starvation damage
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FoodData
impl RefUnwindSafe for FoodData
impl Send for FoodData
impl Sync for FoodData
impl Unpin for FoodData
impl UnsafeUnpin for FoodData
impl UnwindSafe for FoodData
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<>>