Cookiecutter
Based on game build 714014 | Last updated: 2026-03-04
Overview
The cookiecutter prefab represents the Cookiecutter Shark, a marine predator that patrols oceans and targets boats for wood consumption. It utilizes the stategraph and brain systems for autonomous behavior, and interacts with multiple components: locomotor (for ocean navigation), combat (for attacking), eater (to consume wood), health, sanityaura, lootdropper, sleeper, cookiecutterdrill, and homeseeker. It is part of the ECS architecture and does not define custom component logic itself—rather, this file configures the entity with components and sets up behavior hooks via event listeners and lifecycle callbacks.
Usage example
local inst = CreateEntity()
inst:AddTag("cookiecutter")
inst:AddComponent("locomotor")
inst:AddComponent("combat")
inst:AddComponent("eater")
-- ... additional setup as done in the cookiecutter prefab definition ...
inst:DoPeriodicTask(0.25, CheckForBoats) -- typical targeting behavior
Dependencies & tags
Components used: locomotor, health, sanityaura, combat, lootdropper, inspectable, eater, sleeper, cookiecutterdrill, knownlocations, childspawner (via DoReturn callback).
Tags added: monster, smallcreature, hostile, cookiecutter, ignorewalkableplatformdrowning.
Tags checked: boat, INLIMBO, fire, smolder, debuffed (via scarytocookiecutters shared tag logic).
Properties
No public properties are defined directly by this file. The prefab configures properties on attached components (e.g., inst.components.locomotor.runspeed), but does not expose new top-level variables.
Main functions
OnAttacked(inst, data)
- Description: Handler for
attackedevents; triggers fleeing behavior and temporarily marks the cookiecutter with thescarytocookiecutterstag. Cancels existing flee timer tasks and starts a new one if attack occurred outside drilling/jumping states. - Parameters:
inst(Entity) — the cookiecutter instance.
data(table) — event data (unused in this handler). - Returns: Nothing.
DoReturn(inst)
- Description: Attempts to return the cookiecutter to its home (e.g., a beach den) via the
childspawner:GoHomecomponent. If no valid home exists, removes the entity. - Parameters:
inst(Entity) — the cookiecutter instance. - Returns: Boolean
trueif successfully returned to home (viachildspawner:GoHome), otherwisenil.
findtargetcheck(target)
- Description: Validates that a potential target (boat) is located in ocean terrain, accounting for boat presence.
- Parameters:
target(Entity) — candidate boat entity. - Returns:
trueif target is in ocean;falseotherwise.
CanTargetBoats(inst)
- Description: Checks whether the cookiecutter can currently target boats—i.e., not fleeing and meeting the minimum time since last eating.
- Parameters:
inst(Entity) — the cookiecutter instance. - Returns:
trueif eligible to target boats;falseotherwise.
ShareBoatTarget(inst)
- **Description:**Broadcasts the current boat target to nearby cookiecutters within detection range, enabling cooperative targeting.
- Parameters:
inst(Entity) — the cookiecutter instance that found a target. - Returns: Nothing.
ValidateTargetWood(inst)
- Description: Verifies that the stored
target_woodentity is valid, within maximum follow distance, and not in an invalid state (INLIMBO,fire,smolder). - Parameters:
inst(Entity) — the cookiecutter instance. - Returns: The valid
target_woodentity if valid;nilotherwise.
CheckForBoats(inst)
- Description: Core targeting task; searches for boats within detection radius during idle states (
drilling,jumping,busy). Updatestarget_wood, triggers target sharing, and enforces eating cooldown. - Parameters:
inst(Entity) — the cookiecutter instance. - Returns: Nothing.
OnEatFn(inst)
- Description: Plays the bite sound effect upon eating wood.
- Parameters:
inst(Entity) — the cookiecutter instance. - Returns: Nothing.
ValidateSpawnPt(inst)
- Description: Ensures the cookiecutter spawns underwater (not on visual ground). Removes the entity if invalid.
- Parameters:
inst(Entity) — the cookiecutter instance. - Returns:
falseif removed due to invalid spawn point;trueotherwise.
OnEntitySleep(inst)
- Description: Cancels the periodic boat-finding task when the cookiecutter sleeps.
- Parameters:
inst(Entity) — the cookiecutter instance. - Returns: Nothing.
OnEntityWake(inst)
- Description: Restarts the periodic boat-finding task (every
0.25seconds) when the cookiecutter wakes. - Parameters:
inst(Entity) — the cookiecutter instance. - Returns: Nothing.
OnLoadPostPass(inst)
- Description: Finalization hook after world loading; checks if the cookiecutter spawned atop a boat and forces a
"resurface"state transition. - Parameters:
inst(Entity) — the cookiecutter instance. - Returns: Nothing.
Events & listeners
- Listens to:
attacked— triggersOnAttackedto initiate fleeing. - Pushes: None defined in this file (uses
inst:PushEventindirectly via stategraph/brain or via other components). - Lifecycle hooks:
inst.OnEntitySleep = OnEntitySleepinst.OnEntityWake = OnEntityWakeinst.DoReturnHome = DoReturninst.OnLoadPostPass = OnLoadPostPass