pub struct KnownRecipes { /* private fields */ }Expand description
Set of recipes a player has unlocked, plus the protocol’s
numeric display_id mapping.
The protocol uses an i32 per recipe (allocated server-side, sent
in Recipe Book Add and referenced by Recipe Book Remove and
Place Recipe). Display IDs are stable for the lifetime of the
connection but are not persisted across sessions.
unlock/lock allocate / drop the display_ids mapping but
keep the reverse by_display lookup so a stale Place Recipe
packet from the client (e.g. arriving in the same tick as a remove
dispatch) can still resolve the recipe id rather than being silently
dropped.
Implementations§
Source§impl KnownRecipes
impl KnownRecipes
Sourcepub fn unlock(&mut self, id: RecipeId) -> i32
pub fn unlock(&mut self, id: RecipeId) -> i32
Records the recipe as unlocked for this player.
Allocates a new display_id if the recipe was not already
known. Returns the recipe’s display_id (existing or newly
allocated) so the caller can include it in the
Recipe Book Add S2C packet.
Sourcepub fn lock(&mut self, id: &RecipeId) -> Option<i32>
pub fn lock(&mut self, id: &RecipeId) -> Option<i32>
Removes the recipe from the unlocked set.
Returns the display_id if the recipe was previously
unlocked, otherwise None. The reverse by_display mapping
is preserved so late-arriving Place Recipe packets can still
resolve which recipe they referred to.
Sourcepub fn has(&self, id: &RecipeId) -> bool
pub fn has(&self, id: &RecipeId) -> bool
Returns true if the recipe is unlocked for this player.
Sourcepub fn display_id(&self, id: &RecipeId) -> Option<i32>
pub fn display_id(&self, id: &RecipeId) -> Option<i32>
Returns the display id assigned to the recipe, if any.
Reads the forward map only — locked recipes return None
even though the reverse map may still hold them.
Sourcepub fn recipe_for_display(&self, display_id: i32) -> Option<&RecipeId>
pub fn recipe_for_display(&self, display_id: i32) -> Option<&RecipeId>
Resolves a display_id back to a recipe id.
Used by Phase 2 to handle incoming Place Recipe packets.
Returns the recipe even if it has since been locked — the
caller decides whether to honour the request.
Trait Implementations§
Source§impl Clone for KnownRecipes
impl Clone for KnownRecipes
Source§fn clone(&self) -> KnownRecipes
fn clone(&self) -> KnownRecipes
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more