Shaveable
Based on game build 714014 | Last updated: 2026-03-03
Overview
The Shaveable component enables an entity to be shaved (e.g., a beefalo), optionally producing loot items when shaved. It integrates with the inventory and inventoryitem components to drop items, handles wetness inheritance for dropped loot, and supports custom validation and side-effect callbacks. It also manages the bearded tag based on prize count and serializes state for network sync and save/load.
Usage example
local inst = CreateEntity()
inst:AddComponent("shaveable")
inst.components.shaveable:SetPrize("beefalofur", 2)
inst.components.shaveable.can_shave_test = function(inst, shaver, implement)
return implement ~= nil and implement.prefab == "razor" and "Not using a razor"
end
inst.components.shaveable.on_shaved = function(inst, shaver, implement)
print("Beefalo was shaved!")
end
Dependencies & tags
Components used: inventory, inventoryitem, inventoryitemmoisture, rainimmunity (via InheritWorldWetnessAtTarget)
Tags: Adds/Removes bearded based on prize_count (non-zero → bearded present)
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
prize_prefab | string or nil | nil | The prefab name of the item(s) to spawn on shave. |
prize_count | number or nil | nil | Number of prize_prefab items to spawn. |
can_shave_test | function or nil | nil | Optional predicate (inst, shaver, implement) -> can_shave, reason. |
on_shaved | function or nil | nil | Optional callback (inst, shaver, implement) triggered after successful shave. |
Main functions
SetPrize(prize_prefab, prize_count)
- Description: Configures the loot to drop when this entity is shaved.
- Parameters:
prize_prefab(string ornil) — prefab name of the item to spawn;nildisables looting.
prize_count(number ornil) — how many items to spawn; non-positive values clear loot. - Returns: Nothing.
- Side effect: Updates the
beardedtag: adds it ifprize_count > 0, removes otherwise.
CanShave(shaver, shaving_implement)
- Description: Validates whether shaving is allowed. Delegates to
can_shave_testif set; otherwise returnstrue. - Parameters:
shaver(entity ornil) — the entity performing the shave.
shaving_implement(entity ornil) — the tool or item used to shave. - Returns:
can_shave(boolean) —trueif allowed;reason(string ornil) — optional failure message for UI display. - Error states: Never fails; if
can_shave_testisnil, returnstrue, nil.
Shave(shaver, shaving_implement)
- Description: Performs the shave action: validates, spawns loot (if configured), and runs
on_shavedcallback. - Parameters:
shaver(entity ornil) — the entity performing the shave.
shaving_implement(entity ornil) — the tool or item used to shave. - Returns:
trueon success;false, reasonifCanShavefails. - Error states:
- Loot is skipped if
prize_prefaborprize_countisnil. - Loot items inherit world wetness from the target if
inventoryitemmoistureis present and the target lacksrainimmunity. - Items are given to
shaver's inventory if possible; otherwise, they are launched away.
- Loot is skipped if
OnSave()
- Description: Returns component state for serialization.
- Parameters: None.
- Returns:
{ prize_count = number or nil }.
OnLoad(data)
- Description: Restores component state from saved data.
- Parameters:
data(table) — must containprize_count(number ornil). - Returns: Nothing.
GetDebugString()
- Description: Returns a human-readable debug string for inspecting the component.
- Parameters: None.
- Returns: string in the format
"{prize_count} {prize_prefab}".
Events & listeners
- Listens to:
prize_count— internal listener (viaprize_count = on_prize_countin class metatable) callson_prize_count(self, prize_count)to update thebeardedtag. - Pushes: None.
Notes
- The
on_prize_countfunction automatically toggles thebeardedtag based onprize_count. This tag is also removed duringOnRemoveFromEntity. - Loot items use
InventoryItem:InheritWorldWetnessAtTarget(self.inst)to match the target's wetness state, honoringrainimmunityon the target. - The
shaverargument may benil(e.g., in world-gen or cutscenes); the component handles this gracefully by launching loot.