Skip to main content

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.

Constructors​

MemberWhat it is
Cookable()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
protected NetworkPrefab burntVersionPrefab the item turns into when burnt.
protected NetworkPrefab cookedVersionPrefab the item turns into when cooked.
protected CookingTemperatures cookingTemperaturesThe temperature settings asset.
13 private and internal fields
MemberWhat it is
private PooledObjectDefinition burntEffectEffect played when the item burns.
private float burntProgressBacking field for BurntProgress. Saved.
private Transform burntSpawnPointSpawn point passed to ReplaceWith for the burnt version. ReplaceWith ignores it.
private CookableItem cookableItemCache for CookableItem.
private PooledObjectDefinition cookedEffectEffect played when the item finishes cooking.
private float cookedProgressBacking field for CookedProgress. Saved.
private Transform cookedSpawnPointSpawn point passed to ReplaceWith for the cooked version. ReplaceWith ignores it.
private CookingPoint cookingPointBacking field for CookingPoint.
private int experienceAwardedWhenRoastedNot read anywhere in this build.
private bool isBurnableBacking field for IsBurnable.
private bool isCookableBacking field for IsCookable.
private Pickup pickupCache for Pickup.
private MethodSyncStruct<bool> syncEffectMethod sync that plays the cooked or burnt effect on clients.

Properties​

MemberWhat 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
MemberWhat it is
private float BurningDuration { get; }Seconds above the burning temperature before the item burns.
private float InstantBurnTemperature { get; }Temperature at which the item burns at once.
private float OptimalCookingDuration { get; }Seconds to cook at the optimal temperature.
private float WeakCookingDuration { get; }Seconds to cook at the weak temperature.

Events​

MemberWhat it is
event NetworkEntityHandler SwappedToBurntVersionRaised with the new entity (or null) when the item burns.
event NetworkEntityHandler SwappedToCookedVersionRaised with the new entity (or null) when the item finishes cooking. Stews listen to it.

Methods​

MemberWhat 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
MemberWhat 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: