Rabbit
Based on game build 714014 | Last updated: 2026-03-06
Overview
The rabbit prefab implements behavior for the in-game rabbit, a small animal that transforms between seasonal forms (normal and winter) and can be forced into a nightmare state ("beardling") via world events. It integrates with multiple systems including cooking, sanity, inventory, combat, and loot, and handles state transitions via timers and world-state listeners (iswinter). Key behaviors include seasonal morphing, sanity aura emission, transformation effects, and conditional loot generation based on transform state or observer sanity.
Usage example
local inst = Prefab("rabbit", fn, assets, prefabs)()
inst:AddComponent("health")
inst.components.health:SetMaxHealth(25)
inst:AddTag("rabbit")
inst.components.lootdropper:SetLoot({"smallmeat"})
Dependencies & tags
Components used: locomotor, drownable, eater, inventoryitem, sanityaura, cookable, knownlocations, timer, health, lootdropper, combat, inspectable, sleeper, tradable, followable, hauntable.
Tags added: animal, prey, rabbit, smallcreature, canbetrapped, cattoy, catfood, stunnedbybomb, cookable.
Tags checked: INLIMBO, dappereffects.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
sounds | table (nil) | nil | Holds sound paths for scream/hurt events; set by BecomeRabbit, BecomeWinterRabbit, or BecomeBeardling. |
task | task handle (nil) | nil | Timer task for delayed seasonal transformation. Cancelled and reassigned during morphs. |
has_nightmare_state | boolean | true | Indicates this entity supports transformation to beardling state. Used by shadow_trap interaction. |
Main functions
BecomeRabbit(inst)
- Description: Transforms the rabbit to its normal form. Sets animation build, inventory image, and sound set. Cannot occur if nightmare state is active or dead. Cancels pending transformation tasks.
- Parameters:
inst(Entity) — the rabbit instance. - Returns: Nothing.
- Error states: Early return if
IsForcedNightmare(inst)is true orinst.components.health:IsDead()is true.
BecomeWinterRabbit(inst)
- Description: Transforms the rabbit to its winter form. Sets animation build, inventory image, and sound set. Cannot occur if nightmare state is active or dead.
- Parameters:
inst(Entity) — the rabbit instance. - Returns: Nothing.
- Error states: Early return if
IsForcedNightmare(inst)is true orinst.components.health:IsDead()is true.
BecomeBeardling(inst, duration)
- Description: Transforms the rabbit into a beardling (nightmare state) for a specified duration. Sets animation/build to
beard_monster, sound set, and schedules a timer to revert. Listens fortimerdone,enterlimbo, andexitlimboevents. - Parameters:
inst(Entity) — the rabbit instance.duration(number or nil) — duration in seconds for nightmare state; nil means do not schedule timer (used during save/load).
- Returns: Nothing.
- Error states: Early return if
inst.components.health:IsDead()is true. If aforcenightmaretimer exists, extends only if new duration is longer.
OnForceNightmareState(inst, data)
- Description: Callback for
ms_forcenightmarestateevent. Triggers shadow effects and beardling transformation with the provided duration. - Parameters:
inst(Entity) — the rabbit instance.data(table or nil) — event data; expectsdata.durationto be a number.
- Returns: Nothing.
OnIsWinter(inst, iswinter)
- Description: Listener for world-state changes to
iswinter. Triggers seasonal transformation (normal ↔ winter) with a small random delay unless forced into nightmare state. - Parameters:
inst(Entity) — the rabbit instance.iswinter(boolean) — current winter state of the world.
- Returns: Nothing.
OnWake(inst)
- Description: Handles rabbit waking from sleep. Re-applies seasonal morph if needed and resumes watching
iswinterworld state. - Parameters:
inst(Entity) — the rabbit instance. - Returns: Nothing.
OnSleep(inst)
- Description: Handles rabbit sleeping. Stops listening for
iswinterchanges and cancels pending transformation tasks. - Parameters:
inst(Entity) — the rabbit instance. - Returns: Nothing.
OnLoad(inst)
- Description: Restores nightmare state timer and transform on load. Pauses/resumes
forcenightmaretimer based on limbo status. - Parameters:
inst(Entity) — the rabbit instance. - Returns: Nothing.
LootSetupFunction(lootdropper)
- Description: Configures loot drop rules based on transformation state and cause of death. Applies beardling loot if forced, otherwise checks if killer was a dapper beardling, else default rabbit loot.
- Parameters:
lootdropper(LootDropper) — the component instance. - Returns: Nothing.
CalcSanityAura(inst, observer)
- Description: Computes sanity aura based on whether this rabbit is a beardling or the observer is in dapper insanity mode.
- Parameters:
inst(Entity) — the rabbit instance.observer(Entity or nil) — the observing entity.
- Returns:
-TUNING.SANITYAURA_MEDif beardling or observer is dapper insane, else0.
GetCookProductFn(inst, cooker, chef)
- Description: Returns product name for cooking:
cookedmonstermeatif beardling or chef is dapper insane, elsecookedsmallmeat. - Parameters:
inst(Entity) — the rabbit instance.cooker(Entity) — the cooking pot entity.chef(Entity or nil) — the chef entity.
- Returns:
"cookedmonstermeat"or"cookedsmallmeat"(string).
OnCookedFn(inst, cooker, chef)
- Description: Plays the appropriate hurt sound when cooked based on transformation state or chef type.
- Parameters:
inst(Entity) — the rabbit instance.cooker(Entity) — the cooking pot entity.chef(Entity or nil) — the chef entity.
- Returns: Nothing.
OnAttacked(inst, data)
- Description: When attacked, gathers up to five nearby rabbits (tags: must be
rabbit, must not beINLIMBO) and pushesgohomeevent to scatter them. - Parameters:
inst(Entity) — the rabbit instance.data(table or nil) — attack event data; ignored if beardling state and event is internally triggered.
- Returns: Nothing.
DrawImageOverride(inst, canvas, viewer)
- Description: Returns inventory image name
beard_monsterfor observers in dapper mode or beardlings, else matches transformation state. - Parameters:
inst(Entity) — the rabbit instance.canvas(Entity or nil) — rendering canvas (unused).viewer(Entity or nil) — the observing entity.
- Returns:
"beard_monster"or"rabbit"/"rabbit_winter"(string).
Events & listeners
-
Listens to:
ms_forcenightmarestate— triggers beardling transformation viaOnForceNightmareState.attacked— scatters nearby rabbits viaOnAttacked.timerdone— triggers seasonal reversion whenforcenightmaretimer completes viaOnTimerDone.enterlimbo— pausesforcenightmaretimer viaOnEnterLimbo.exitlimbo— resumesforcenightmaretimer viaOnExitLimbo.OnEntityWake— world-state and morph reapplication.OnEntitySleep— stops world-state watch.OnLoad— restores nightmare state on save load.
-
Pushes:
gohome— pushed to nearby rabbits upon attack (viaOnAttacked).imagechange— fired internally viaInventoryItem.ChangeImageName.