Shadowheart Infused
Based on game build 722832 | Last updated: 2026-04-28
Overview
shadowheart_infused.lua registers a spawnable socketable item entity. The prefab's fn() constructor builds the physics body, attaches client-side components and visual effects, then branches into master-only initialization on the server where gameplay components (drownable, sanityaura, lootdropper, inventoryitem) are attached. The entity emits periodic shadow heart sounds while active and spawns a client-side shadow FX particle that follows the item. It is referenced by name "shadowheart_infused" and instantiated with SpawnPrefab("shadowheart_infused").
Usage example
-- Spawn at world origin:
local inst = SpawnPrefab("shadowheart_infused")
inst.Transform:SetPosition(0, 0, 0)
-- Check socket quality on server:
if TheWorld.ismastersim and inst.components.socketable ~= nil then
local quality = inst.components.socketable.socketquality
end
Dependencies & tags
External dependencies:
prefabs/wx78_common-- providesMakeItemSocketableserver-side socketable setupbrains/shadowheart_infusedbrain-- AI brain attached on masterstategraphs/SGshadowheart_infused-- animation stategraph attached on masterMakeInventoryPhysics-- applies physics and floatable behavior for inventory itemsMakeItemSocketable_Client-- client-side socketable component registrationMakeHauntable-- registers ghost interaction behavior
Components used:
drownable-- detects drowning state in waterinspectable-- overrides display name to "shadowheart"locomotor-- sets movement speed toTUNING.SHADOWHEART_HOP_SPEEDlootdropper-- dropsshadowheart_infusedon trap starvationsanityaura-- applies-TUNING.SANITYAURA_MEDsanity drainsocketable-- set toSOCKETQUALITY.HIGHtradable-- enables trading between playersinventoryitem-- handles pickup/drop with customOnDroppedFnhighlightchild-- attached to shadow FX entity for selection highlightingfollower-- attached to shadow FX entity to follow parent item
Tags:
canbetrapped-- added in fn(); enables trap targetingshadowheart-- added in fn(); identifies entity type for queriesFX-- added to shadow FX child entity; marks as visual effect
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
assets | table | {...} | Array of Asset(...) entries; loads anim/shadowheart_infused.zip animation bank. |
STARVED_ONTRAP_LOOT | table | { "shadowheart_infused" } | Loot table dropped when trap starves; contains single entry for self-spawn. |
| inst.beattask | task | nil | Periodic task handle for shadow heart sound playback; cancelled on sleep/limbo. |
| inst.scrapbook_anim | string | "scrapbook" | Animation name used for scrapbook/collection UI display. |
Main functions
fn()
- Description: Prefab constructor that runs on both client and master. Creates the entity, builds physics, attaches AnimState and SoundEmitter, adds tags, sets up client-side shadow FX, then returns early on client. On master, continues to attach gameplay components (drownable, sanityaura, lootdropper, inventoryitem, locomotor, socketable, tradable, inspectable), sets stategraph and brain, and registers entity lifecycle callbacks.
- Parameters: None
- Returns: entity instance
- Error states: None — engine guarantees valid entity creation.
DoBeat(inst) (local)
- Description: Plays the shadow heart sound effect and schedules the next beat via
DoTaskInTimewith random delay between 0.75 and 1.5 seconds. Creates the periodic audio loop while the entity is active. - Parameters:
inst-- entity instance - Returns: None
- Error states: Errors if
inst.SoundEmitteris nil (no nil guard before PlaySound call).
OnEntityWake(inst) (local)
- Description: Called when entity becomes active (player nearby). Cancels any existing
beattaskand restarts the shadow heart sound loop. Also triggered byexitlimboevent. Returns early if entity is in limbo or asleep. - Parameters:
inst-- entity instance - Returns: None
- Error states: None — guards against nil
beattaskand checks limbo/sleep state.
OnEntitySleep(inst) (local)
- Description: Called when entity goes idle (no players nearby). Cancels the
beattaskto stop sound playback and clears the task handle. Also triggered byenterlimboevent. - Parameters:
inst-- entity instance - Returns: None
- Error states: None — guards against nil
beattaskbefore cancel.
OnDropped(inst) (local)
- Description: Callback set on
inventoryitemcomponent viaSetOnDroppedFn. Triggers thestunnedstategraph state when the item is dropped on the ground. - Parameters:
inst-- entity instance - Returns: None
- Error states: Errors if
inst.sgis nil (no nil guard before GoToState call).
OnLanded(inst) (local)
- Description: Called on
on_landedevent. Checks thedrownablecomponent and callsCheckDrownable()to evaluate drowning state after landing in water. - Parameters:
inst-- entity instance - Returns: None
- Error states: None — guards against nil
drownablecomponent before calling method.
CLIENT_AttachShadowFx(inst) (local)
- Description: Client-only function that creates a non-networked shadow FX entity parented to the item. Sets up AnimState with shadow bank/build, plays looping
dark_loopanimation, attacheshighlightchildandfollowercomponents, and configures follower to track thefollow_symbolon the parent item. Returns the FX entity. - Parameters:
inst-- parent item entity - Returns: shadow FX entity instance
- Error states: Errors if
CreateEntityfails or if parentinsthas no valid GUID (engine guarantees both).
Events & listeners
- Listens to:
exitlimbo— triggersOnEntityWake; restarts shadow heart sound loop when entity exits limbo state - Listens to:
enterlimbo— triggersOnEntitySleep; cancels shadow heart sound task when entity enters limbo - Listens to:
on_landed— triggersOnLanded; checks drowning state after landing in water