Corpses
Based on game build 714014 | Last updated: 2026-03-04
Overview
corpses.lua defines prefabricated entities for creature corpses and provides shared logic for their behavior in DST. It implements a system for corpse mutation (both regular lunar mutation and rift-based gestalt possession), decay via erosion timers, meat-level looting mechanics, and interaction with burning/extinguishing states. It does not define a standalone component class but instead serves as a prefab factory that constructs and configures corpse entities using various components like burnable, lootdropper, timer, entitytracker, and others.
Usage example
This file is not added to entities directly; it returns Prefab constructors for corpse types. Example usage within a mod:
local Corpse = require "prefabs/corpses"
local my_corpse_prefab = Corpse.MakeCreatureCorpse({
creature = "beefalo",
build = "beefalo",
bank = "beefalo",
sg = "SGbeefalo_corpse",
shadowsize = {0.5, 0.25},
assets = { Asset("ANIM", "anim/beefalo.zip") },
has_pre_rift_mutation = true,
has_rift_mutation = true,
sanityaura = -TUNING.SANITYAURA_MED,
})
Dependencies & tags
Components used:
burnable(conditionally added)lootdropperinspectablesanityauratimerentitytrackersavedscaleupdatelooper(conditionally added for flash effects)
Tags added by corpse prefabs:
"creaturecorpse""deadcreature""blocker"(ifuse_inventory_physicsis enabled)"NOCLICK"(added when eroding starts)- Custom tag (
data.tag) and arbitrary tags (data.tags) if provided incorpse_data.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
creature | string | nil | Name of the original creature (e.g., "beefalo"). Used for loot name lookups and name generation. |
mutantprefab | string | nil | Prefab name for the regular lunar-mutated creature (e.g., "mutatedbeefalo"). |
riftmutantprefab | string | nil | Prefab name for the rift (gestalt) mutated creature (e.g., "mutatedbeefalo_gestalt"). |
corpse_loot | table | nil | List of loot prefabs dropped upon erosion. Initialized by SetCorpseData() or via defaults in corpse_defs. |
meat | number | max value | Current meat amount. Used to determine looting reduction and腐烂 (meat_level). |
meat_level | number | 1 | Integer from 1 (full meat) to 4 (empty/corpses eroding). Set automatically by SetMeat(). |
persist_sources | SourceModifierList | instance | Tracks entities/tasks preventing erosion (e.g., player proximity, active timers). |
no_destroy_on_burn | boolean | false | If true, prevents destruction on burning (e.g., Willow’s torch corpse). |
noburn | boolean | false | If true, removes the burnable component entirely. |
corpseerodefn | function | nil | Optional custom function called when corpse erodes. Overrides default fade-away delay. |
Main functions
MakeCreatureCorpse(data)
- Description: Factory function that returns a
Prefabconstructor for a fully configured creature corpse. Accepts adatatable with creature-specific configuration (creature name, animation build/bank, stategraph, mutation flags, loot, burn behavior, etc.). - Parameters:
data(table) — Configuration object. Required keys:creature,build,bank,sg. Optional keys:has_pre_rift_mutation,has_rift_mutation,burntime,meat,loot,scale,faces,tag,tags,custom_physicsfn,makeburnablefn,OnSave,OnLoad,master_postinit, etc.
- Returns:
Prefab— A prefab definition ready for use inPrefabsregistration.
MakeCreatureCorpse_Prop(data)
- Description: Factory function that returns a
Prefabfor a simpler "prop" variant of a corpse (e.g., display-only corpses in static layouts). Lacks mutation, loot, and many gameplay features of fullMakeCreatureCorpse. - Parameters:
data(table) — Similar structure toMakeCreatureCorpse, butbuild,bank,scale, andfacesare required for visuals; no mutation-related keys needed.
- Returns:
Prefab— A lightweight prefab definition.
inst:StartLunarMutation(loading)
- Description: Begins the regular lunar mutation process (e.g., Horror Hound from Hound). Cancels timers, disables burnable callbacks, and transitions the stategraph and prefab to the mutated version.
- Parameters:
loading(boolean) — Iftrue, skips pre-mutation state transitions for fast-reload scenarios.
- Returns: Nothing.
inst:StartLunarRiftMutation(loading)
- Description: Begins rift-based mutation (e.g., Gestalt Possession). May spawn a
corpse_gestaltproxy and triggers flash animation effects. Firesms_gestalt_possessionevent (unlessloading). - Parameters:
loading(boolean) — Same semantics asStartLunarMutation.
- Returns: Nothing.
inst:StartReviveMutateTimer(time)
- Description: Starts a timer to trigger lunar mutation after
timeseconds. Used for non-gestalt mutations with delay. - Parameters:
time(number) — Duration in seconds before mutation triggers.
- Returns: Nothing.
inst:StartFadeTimer(time)
- Description: Starts the erosion timer (default: fade away after time passes). Enables persistent fade behavior.
- Parameters:
time(number) — Duration in seconds before erosion completes.
- Returns: Nothing.
inst:StartGestaltTimer(time)
- Description: Starts a timer to spawn a gestalt entity. Skipped for puffin corpses (unsupported mutation).
- Parameters:
time(number) — Duration in seconds before gestalt spawns.
- Returns: Nothing.
inst:SetGestaltCorpse()
- Description: Immediately initiates gestalt mutation (spawns
corpse_gestaltand sets tracking). Drops loot if corpse is epic or a warg corpse. - Parameters: None.
- Returns: Nothing.
inst:SetNonGestaltCorpse()
- Description: Sets up non-gestalt (regular lunar) mutation by starting the revive timer.
- Parameters: None.
- Returns: Nothing.
inst:DropCorpseLoot()
- Description: Drops loot based on current meat percentage. Reduces loot count/quality if meat level is low (level ≥ 2). Uses
lootdropper:DropLoot(). - Parameters: None.
- Returns: Nothing.
inst:SetMeat(meat)
- Description: Sets the current meat amount (0 to max) and automatically updates
meat_level. - Parameters:
meat(number) — New meat quantity. Clamped to [0,GetMaxMeat()].
- Returns: Nothing.
inst:SetMeatPercent(percent)
- Description: Convenience method to set meat by percentage (0.0–1.0). Internally clamps and scales to max meat.
- Parameters:
percent(number) — Meat percentage. Clamped to[0, 1].
- Returns: Nothing.
inst:GetMeatPercent()
- Description: Returns the current meat as a percentage of maximum meat.
- Parameters: None.
- Returns:
number— meat percentage (e.g.,0.75).
inst:GetMaxMeat()
- Description: Returns the maximum meat capacity for this corpse, based on creature size.
- Parameters: None.
- Returns:
number— Maximum meat value.
inst:IsMutating()
- Description: Returns
trueif the corpse is currently in a mutation state (prerift_mutatingorlunarrift_mutating). - Parameters: None.
- Returns:
boolean.
inst:WillMutate()
- Description: Returns
trueif mutation is scheduled (timer exists or already mutating). - Parameters: None.
- Returns:
boolean.
inst:HasGestaltArriving()
- Description: Returns
trueif a gestalt entity is currently tracked (e.g., before spawning). - Parameters: None.
- Returns:
boolean.
inst:SetPersistSource(source, persists)
- Description: Adds or removes a persistence source (e.g., player proximity) that prevents erosion. When
persistsistrue, prevents eroding. - Parameters:
source(string) — Unique identifier for the source.persists(boolean) —trueto prevent erosion,falseto allow erosion.
- Returns: Nothing.
inst:RemovePersistSource(source)
- Description: Removes a persistence source and schedules a check for immediate erosion if no other sources exist.
- Parameters:
source(string) — Unique identifier for the source to remove.
- Returns: Nothing.
Events & listeners
-
Listens to:
"chomped"— CallsOnChompedto reduce meat."timerdone"— CallsOnTimerDoneto handle erosion, gestalt spawn, or mutation timers."loot_prefab_spawned"— CallsOnSpawnedLootto apply damage/perish reduction to loots based on meat quality."onremove"— Managed internally byentitytrackerto clean up entity references."propreveal"— Optional listener added ifdata.onrevealfnis provided in props."electrocute"— Disabled by default (sg.mem.noelectrocute = true), butOnElectrocutehook exists in code.
-
Pushes:
"ms_gestalt_possession"— Fired duringStartLunarRiftMutationwhen a gestalt takes over (not during loading)."ms_registercorpse"— Fired infn()to register the corpse with the world."entity_droploot"— Fired bylootdropper:DropLoot."perishchange"— Not used here; listed for completeness (handled byperishablecomponent, not in use in this file).