Skip to main content

Carnival Food

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

Overview

This file defines a factory pattern for creating carnival-themed food prefabs in DST. It uses a shared MakeFood function to instantiate multiple food items with varying properties (e.g., hunger, health, sanity, perish time). Each generated prefab includes components for inventory interaction, floating behavior, perishability, tradability, and burnability. The prefabs are registered via Prefab() and returned as unpacked values for use elsewhere in the codebase.

Usage example

local carnivalfood_corntea = require("prefabs/carnival_food")

-- The function returns unpacked prefabs; use one directly:
local food_entity = carnivalfood_corntea()

-- Then spawn it in the world:
food_entity.Transform:SetPosition(x, y, z)
TheWorld:SpawnEntity(food_entity)

Dependencies & tags

Components used: transform, animstate, soundemitter, network, physics, inventoryfloatable, floater, edible, perishable, stackable, tradable, inspectable, inventoryitem, smallburnable, smallpropagator, hauntablelaunch
Tags: Adds fooddrink, pre-preparedfood (and any custom tags from def.tags)

Properties

No public properties are defined for this file itself — it is a generator of prefabs. The generated prefabs expose properties via attached components:

PropertyTypeDefault ValueDescription
inst.components.edible.foodtypeFOODTYPE enumdef.foodFood category (e.g., VEGGIE).
inst.components.edible.hungervaluenumberdef.hungerHunger restored on consumption.
inst.components.edible.healthvaluenumberdef.healthHealth restored on consumption.
inst.components.edible.sanityvaluenumberdef.sanitySanity change on consumption.
inst.components.perishable.perishtimenumberdef.perishtimeTime in seconds until the item spoils.
inst.components.stackable.maxsizenumberTUNING.STACK_SIZE_SMALLITEMMaximum stack size.
inst.components.floater.sizestringdef.floater[1]Floating physics size (e.g., "small").
inst.components.floater.xscale/yscale/zscalenumberdef.floater[2]Scale applied to floating FX.

Main functions

MakeFood(def)

  • Description: Factory function that constructs and configures a food prefab based on the input definition table def.
  • Parameters: def (table) - A table containing keys like name, anim, art, tags, food, hunger, health, sanity, perishtime, temperature, temperatureduration, and floater.
  • Returns: Prefab — A fully configured prefab definition ready for world spawning.
  • Error states: Returns early on clients (when TheWorld.ismastersim == false) before adding server-only components like edible and perishable; no error occurs, but components are only present on the master sim.

Events & listeners

None identified. This file does not register or fire any custom events.