Cookbookupdater
Based on game build 714014 | Last updated: 2026-03-03
Overview
CookbookUpdater is a client-side component responsible for tracking learned recipes and food statistics in the cookbook. It initializes a local cookbook instance via cookbookdata.lua, listens for player activation events to bind to TheCookbook, and provides methods to learn new recipes and food stats with automatic network replication on dedicated servers or remote clients.
Usage example
local inst = ThePlayer
inst:AddComponent("cookbookupdater")
inst.components.cookbookupdater:LearnRecipe("apple_pie", { "apple", "apple", "honey" })
inst.components.cookbookupdater:LearnFoodStats("apple_pie")
Dependencies & tags
Components used: None (only uses global modules and RPC functions). Tags: None identified.
Properties
No public properties.
Main functions
LearnRecipe(product, ingredients)
- Description: Records a new recipe in the local cookbook and replicates it to connected clients if it is newly learned and the current instance is a remote player on a dedicated server or the master simulation.
- Parameters:
product(string or nil) — the recipe's output name.
ingredients(table or nil) — a list of ingredient names used in the recipe. - Returns: Nothing.
- Error states: Returns early if either
productoringredientsisnil. Only initiates RPC replication ifcookbook:AddRecipe()returnstrue(indicating a new recipe) and the entity has a validuserid.
LearnFoodStats(product)
- Description: Records food stats (e.g., hunger, health, sanity changes) for a dish in the local cookbook and replicates the update if newly discovered.
- Parameters:
product(string) — the dish name whose stats are being learned. - Returns: Nothing.
- Error states: Only triggers RPC replication if
cookbook:LearnFoodStats()returnstrueand the entity satisfies the same conditions asLearnRecipe(dedicated server or master sim with remote client, validuserid).
Events & listeners
- Listens to:
playeractivated— triggersonplayeractivatedto bind the localcookbookinstance toTheCookbookand enable saving, but only for the local player on non-dedicated clients. - Pushes: None.