Skip to main content

Preparedfoods

Based on game build 714014 | Last updated: 2026-03-06

Overview

The preparedfoods module is not a component itself, but a Prefab factory generator. It defines the MakePreparedFood(data) function, which programmatically constructs fully-featured food entities for DST. This includes setting up visual assets (animations and inventory images), attaching required components (edible, inventoryitem, perishable, stackable, bait, tradable), applying spiced food overlays when applicable, and configuring food-specific properties like health, hunger, sanity, temperature effects, and spoil time. It is used by preparedfoods.lua (generic foods), preparedfoods_warly.lua (Warly-specific foods), and spicedfoods.lua (spiced variants).

Usage example

local food_data = {
name = "my_custom_food",
basename = "mycustomfood",
health = 15,
hunger = 20,
sanity = 5,
foodtype = FOODTYPE.GENERIC,
perishtime = 40 * SECONDS,
spice = "chili",
}

local my_food_prefab = MakePreparedFood(food_data)

Dependencies & tags

Components used: edible, inventoryitem, perishable, stackable, inspectable, bait, tradable.
Tags added: preparedfood (always), spicedfood (when spice is present), plus any custom tags from data.tags.

Properties

No public properties are defined on a module-wide basis. The MakePreparedFood function accepts a data table with the following expected keys (derived from usage):

PropertyTypeDefault ValueDescription
data.namestring(required)Unique prefab name (e.g., "sweettea").
data.basenamestringnilBase filename override for animations and images.
data.healthnumber(required)Health value provided when eaten.
data.hungernumber(required)Hunger value provided when eaten.
data.sanitynumber0Sanity change when eaten.
data.foodtypeFOODTYPE.*FOODTYPE.GENERICFood classification (affects AI preferences).
data.secondaryfoodtypeFOODTYPE.*nilOptional secondary food classification.
data.temperaturenumber0Immediate temperature change on consumption.
data.temperaturedurationnumber0Duration (in seconds) of temperature effect.
data.nochillbooleannilIf true, food cannot be chilled (used for Warly).
data.spicestringnilSpice name (e.g., "chili") to apply visual spice overlay.
data.perishtimenumbernilPerish time in seconds; if > 0, perishable component is added.
data.oneatenfnfunctionnilCallback called when the food is eaten.
data.tagstablenilArray of custom tags to add to the entity.
data.floatertablenilParams for MakeInventoryFloatable: [x, y, z] offset.
data.overridebuildstringnilCustom animation build to use instead of default.
data.prefabstableprefabsAdditional prefabs to include in the asset list.

Main functions

MakePreparedFood(data)

  • Description: Constructs and returns a fully configured Prefab for a prepared food item. Handles asset loading, animation setup, component attachment, and network initialization.
  • Parameters:
    data (table) – Configuration table containing food properties (e.g., health, hunger, spice, perishtime).
  • Returns: Prefab – A callable prefab factory function suitable for use with Prefab().
  • Error states: Returns early on clients (non-master simulations) after instantiating only the visual entity, to prevent duplicate server-side initialization.

Events & listeners

This module itself does not define event handlers. However, the generated prefabs support the following events via component behavior:

  • Listens to: onputininventory (custom listener via data.OnPutInInventory if provided).
  • Pushes: imagechange (via inventoryitem:ChangeImageName), and standard component events (on eaten, perish, etc.) are handled by attached components (edible, perishable, etc.).