Forgerepair
Based on game build 714014 | Last updated: 2026-03-03
Overview
Forgerepair is a utility component that enables an item (typically a tool or consumable) to repair damaged equipment items such as armor, finite-use items, or fueled items. When OnRepair is called with a target entity, it restores the target's condition to full and consumes the repairer item (either decrementing finite uses, splitting and removing from stack, or deleting the item entirely). The component also manages dynamic tags (e.g., forgerepair_log or forgerepair_moonrock) based on the configured repairmaterial value.
Usage example
local inst = CreateEntity()
inst:AddComponent("forgerepair")
inst.components.forgerepair:SetRepairMaterial("moonrock")
inst.components.forgerepair:SetOnRepaired(function(repairer, target, doer)
print("Repaired item with moonrock forge tool")
end)
Dependencies & tags
Components used: armor, finiteuses, fueled, stackable
Tags: Adds or removes forgerepair_<material> tags (e.g., forgerepair_moonrock), based on repairmaterial.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
repairmaterial | string? | nil | The type of material used for repair; used to generate dynamic tags (e.g., "moonrock" → forgerepair_moonrock). |
onrepaired | function? | nil | Optional callback fired after a successful repair; signature: (repairer_inst, target_inst, doer_inst). |
Main functions
SetRepairMaterial(material)
- Description: Sets the repair material type, which updates the entity’s
forgerepair_<material>tag. - Parameters:
material(string?) — the material identifier;nilclears the tag. - Returns: Nothing.
SetOnRepaired(fn)
- Description: Registers a callback function to be invoked after a successful repair.
- Parameters:
fn(function) — a function accepting three arguments:repairer(the item performing repair),target(the repaired item), anddoer(the actor initiating repair). - Returns: Nothing.
OnRepair(target, doer)
- Description: Attempts to fully repair the target entity’s condition. If successful, consumes the repairer item and fires the
onrepairedcallback. - Parameters:
target(Entity) — the entity to repair; must have one ofarmor,finiteuses, orfueledcomponents in a damaged state.
doer(Entity) — the entity performing the repair (passed to the callback). - Returns:
trueif repair succeeded;nilotherwise. - Error states:
- Returns
niliftargetlacks a compatible component or is already at full condition (1.0). - Repairer item consumption logic:
- If
self.inst.components.finiteusesexists: calls:Use(1). - Else if
self.inst.components.stackableexists: splits and removes the split item via:Get():Remove(). - Else: directly removes
self.inst.
- If
- Returns
Events & listeners
None identified.