Cooker
Overview
The Cooker component enables an entity to function as a cooking station within Don't Starve Together. It provides robust functionality to determine if a given item can be cooked by a specific chef and to execute the cooking process, transforming the raw item into its cooked counterpart. This component also handles sound effects and custom callback functions post-cooking, making it a central piece for any cooking-related entity like a Crock Pot or Campfire.
Dependencies & Tags
- Tags:
cooker: Added to the entity when this component is initialized, and removed when the component is detached. This identifies the entity as a cooking station.dangerouscooker: A tag that, if present on the cooker, restricts cooking to entities with theexpertcheftag.expertchef: A tag checked on thechefentity to allow cooking ondangerouscookerstations.
- Other Components:
item.components.cookable: Essential for an item to be eligible for cooking and for the actual cooking transformation. Without this component, an item cannot be cooked.self.inst.components.fueled: The cooker may require fuel to operate. This component is checked inCanCookto ensure the cooker is not empty if it uses fuel.item.components.burnable: Checked inCanCookto prevent cooking items that are currently burning.item.components.projectile: Checked inCanCookto prevent cooking items that are currently thrown as projectiles.self.inst.components.inventoryitem: Used inCookItemto locate the sound emitter for cooking sounds, typically when the cooker is part of a larger inventory (e.g., a portable cooker held by a player).
Properties
No public properties were explicitly initialized in the _ctor beyond self.inst. However, the following properties are expected to be set externally to define callback behaviors:
| Property | Type | Default Value | Description |
|---|---|---|---|
oncookitem | function | nil | A callback function function(old_item, new_item) that is invoked immediately after an item is cooked. old_item is the original item that was cooked, and new_item is the resulting cooked item. |
oncookfn | function | nil | A callback function function(cooker_inst, new_item, chef) that is invoked after an item is cooked. This provides more context than oncookitem, including the cooker entity itself, the newly cooked item, and the chef who performed the action. |
Main Functions
OnRemoveFromEntity()
- Description: This function is called automatically by the Entity Component System when the
Cookercomponent is removed from its associated entity. Its primary purpose is to clean up by removing the "cooker" tag that was added during initialization. - Parameters: None.
CanCook(item, chef)
- Description: Determines whether a given
itemcan be cooked by achefusing this cooker. It performs several validation checks: ensuring the item has acookablecomponent, verifying the cooker has fuel (if applicable), confirming the item is not currently burning or thrown, and checking if the cooker's "dangerouscooker" tag permits thechefto cook (requiring an "expertchef" tag on the chef). - Parameters:
item: (Entity) TheEntityobject representing the item intended for cooking.chef: (Entity) TheEntityobject representing the character attempting to cook.
- Returns: (
boolean)trueif the item meets all criteria and can be cooked;falseotherwise.
CookItem(item, chef)
- Description: Executes the cooking process for a specified
itemby achef, provided thatCanCookreturnstrue. This function handles the transformation of the original item into its cooked version, updates player statistics ("cooked_" + prefab name), triggers custom callback functions (oncookitemandoncookfnif defined), plays a cooking sound, and removes the original item from the world. - Parameters:
item: (Entity) TheEntityobject representing the item to be cooked.chef: (Entity) TheEntityobject representing the character performing the cooking.
- Returns: (
Entityornil) The newly created cooked item entity if the cooking was successful andCanCookallowed it; otherwise,nil.