Forgerepairable
Overview
This component integrates with the Entity Component System to make an entity repairable using forge-compatible repair items. It tracks whether the entity is repairable, which material is used for repairs, and manages the associated "forgerepairable_<material>" tag. Repair is initiated through the Repair() method, which validates compatibility and executes the repair process.
Dependencies & Tags
- Component Dependencies:
armor(used to determine initialrepairablestate if present)fueled(used as fallback to determine initialrepairablestate ifarmoris absent)forgerepair(required on the repair item passed toRepair())
- Tags:
- Adds
"forgerepairable_<material>"whenrepairableistrueandrepairmaterialis non-nil. - Removes the same tag on
SetRepairable(false)orOnRemoveFromEntity(), or whenrepairmaterialchanges.
- Adds
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
repairmaterial | string or nil | nil | The material name (e.g., "gold", "iron") required to repair this entity. Used to generate the repair tag and validate compatible repair items. |
repairable | boolean or nil | nil | Indicates whether the entity is currently in a repairable state. Derived initially from armor:IsDamaged() or fueled:GetPercent() < 1. |
onrepaired | function or nil | nil | Optional callback invoked after a successful repair; signature: fn(inst, doer, repair_item). |
Main Functions
SetRepairMaterial(material)
- Description: Sets the repair material used by this entity and updates the
"forgerepairable_<material>"tag based on currentrepairablestate. - Parameters:
material(stringornil): The repair material identifier.
SetRepairable(repairable)
- Description: Updates whether the entity is currently repairable and ensures the
"forgerepairable_<material>"tag is correctly added or removed. - Parameters:
repairable(boolean): Whether the entity is repairable.
SetOnRepaired(fn)
- Description: Registers a callback to be executed after a successful repair.
- Parameters:
fn(functionornil): Callback function taking(inst, doer, repair_item)as arguments.
Repair(doer, repair_item)
- Description: Attempts to repair the entity using the provided repair item. Returns
trueif successful,falseotherwise. Performs checks for material compatibility, current repairable state, and delegates torepair_item.components.forgerepair:OnRepair(). - Parameters:
doer(Entity): The entity performing the repair (e.g., a player).repair_item(Entity): The item used for repair; must have aforgerepaircomponent with matchingrepairmaterial.
OnRemoveFromEntity()
- Description: Cleans up the
"forgerepairable_<material>"tag when the component is removed from the entity.
Events & Listeners
- Listens for changes to:
repairmaterial→ callsonrepairmaterialto update tags.repairable→ callsonrepairableto update tags.
- Triggers no events itself, but invokes
self.onrepaired(...)on successful repair.