Cookable
A class in Root.Township, Alta.Cooking.
Makes an item cook and burn from the heat at its CookingPoint, then replace itself with a cooked or burnt prefab. Only runs on the server: it is enabled once the item is hot enough and not docked. Progress is saved.
- Listed in Crafting and making
- Inherits or implements
NetworkEntityBehaviour,ISavable<CookableSaveData>,ISavableSave<CookableSaveData>,ISavableSaveBase,ICookableSettings - Derived types
CookableEvent,CookableSaveData,CookableUnityEvent - Documented in Cooking
Constructors
| Member | What it is |
|---|---|
Cookable() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
protected NetworkPrefab burntVersion | Prefab the item turns into when burnt. |
protected NetworkPrefab cookedVersion | Prefab the item turns into when cooked. |
protected CookingTemperatures cookingTemperatures | The temperature settings asset. |
13 private and internal fields
| Member | What it is |
|---|---|
private PooledObjectDefinition burntEffect | Effect played when the item burns. |
private float burntProgress | Backing field for BurntProgress. Saved. |
private Transform burntSpawnPoint | Spawn point passed to ReplaceWith for the burnt version. ReplaceWith ignores it. |
private CookableItem cookableItem | Cache for CookableItem. |
private PooledObjectDefinition cookedEffect | Effect played when the item finishes cooking. |
private float cookedProgress | Backing field for CookedProgress. Saved. |
private Transform cookedSpawnPoint | Spawn point passed to ReplaceWith for the cooked version. ReplaceWith ignores it. |
private CookingPoint cookingPoint | Backing field for CookingPoint. |
private int experienceAwardedWhenRoasted | Not read anywhere in this build. |
private bool isBurnable | Backing field for IsBurnable. |
private bool isCookable | Backing field for IsCookable. |
private Pickup pickup | Cache for Pickup. |
private MethodSyncStruct<bool> syncEffect | Method sync that plays the cooked or burnt effect on clients. |
Properties
| Member | What it is |
|---|---|
float BurningTemperature { get; } | Temperature above which the item starts burning. |
float BurntProgress { get; } | Burn progress from 0 to 1. Resets when the item cools below the burning temperature. |
CookableItem CookableItem { get; } | The CookableItem on the pickup's item. |
float CookedProgress { get; } | Cooking progress. The item becomes the cooked version when it passes 1; it decays back while cool. |
CookingPoint CookingPoint { get; } | The heat point on the same object that gives the temperature. |
CookingTemperatures CookingTemperatures { get; } | The temperature and duration settings for weak, optimal and burning cooking. |
float CookingValue { get; private set; } | How close the heat is to optimal, from 0 (weak) to 1 (optimal). 0 while too cool. |
float CurrentTemperature { get; } | Current temperature of the cooking point. |
bool IsBurnable { get; } | Whether the item can burn. |
bool IsBurning { get; private set; } | True while above the burning temperature. |
bool IsCookable { get; } | Whether the item can cook. |
bool IsUsingSimpleCookingMode { get; set; } | Set by cooking pots for their ingredients: progress only goes up and the item never swaps or burns. |
float OptimalCookingTemperature { get; } | Temperature at which cooking is fastest. |
Pickup Pickup { get; } | The pickup this belongs to, found in parents. |
float WeakCookingTemperature { get; } | Lowest temperature that cooks at all. |
4 private and internal properties
Events
| Member | What it is |
|---|---|
event NetworkEntityHandler SwappedToBurntVersion | Raised with the new entity (or null) when the item burns. |
event NetworkEntityHandler SwappedToCookedVersion | Raised with the new entity (or null) when the item finishes cooking. Stews listen to it. |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Sets up the network message that plays the cooked or burnt effect on clients. |
override void InitializeAsServer(SpawnData spawnData) | Server: enables cooking straight away if the item is already hot or part done, otherwise waits for heat. |
NetworkEntity ReplaceWith(uint prefabHash, PooledObjectDefinition effect, Transform spawnPosition) | Plays the effect, spawns the given prefab in place (if the hash is not 0) and destroys this item. Returns the new entity. |
void ResetProgress() | Sets cooked progress back to 0. |
10 private and internal methods
| Member | What it is |
|---|---|
private void AdvanceCookedProgressForTemperature(float temperature) | Adds cooking progress for this frame: faster the closer the heat is to optimal. Also sets CookingValue. |
private void Awake() | Finds the cooking point and pickup and starts disabled until heat is high enough. |
private void CheckEnable(HeatPoint point) | Heat change handler: enables cooking once the point is above the weak temperature and the item is not docked. |
private bool HandleBurnableTemperatures(float temperature) | Adds burn progress while above the burning temperature (resets it below). True when the item should burn now. |
private bool HandleNormalCookingTemperature(float temperature) | Cooks while above the weak temperature, decays progress below it. True when cooked progress passes 1. |
private void OnDestroy() | Unhooks CheckEnable from the cooking point. |
private void SpawnCookedVersion() | Swaps to the cooked prefab, raises SwappedToCookedVersion and counts a cooked food stat for the last holder. |
private void SwapToBurntVersion() | Swaps to the burnt prefab and raises SwappedToBurntVersion. |
private void SyncEffect(IPlayer player, Stream stream, bool isCooked) | Method sync handler: plays the cooked or burnt effect at the item on receivers. |
private void Update() | Server, while enabled: stops and resets when docked, otherwise advances burning and cooking and swaps the item when done. |
Used in
Members of other types that take, return or hold a Cookable:
CookingPot.ContainedCookables, CookingPot.convertedCookabled, CookingPot.DisableNormalCookingOnIngredients, CookingPot.HandleIngredientAddedWhenLocked, CookingPot.HandleNewIngredient, CookingPot.IngredientAdded, CookingPot.IngredientRemoved, CookingPot.RejectIngredient, CookingPot.ResetCookableIngredient, StewComponent.cookable, StewComponent.Cookable, StewManager.AddCookableToStew, StewManager.AddIngredient.