Constructionsite Replica
Based on game build 714014 | Last updated: 2026-03-03
Overview
constructionsite_replica is a client-side component that synchronizes and exposes key construction site state (such as enabled status, builder assignment, and slot counts) from the server. It works in conjunction with the server-side constructionsite component and maintains a lightweight constructionsite_classified entity for replicated data. This component ensures the client has read access to essential construction state without requiring direct server component access.
Usage example
local inst = CreateEntity()
inst:AddComponent("constructionsite_replica")
inst.components.constructionsite_replica:SetEnabled(true)
inst.components.constructionsite_replica:SetBuilder(some_builder)
inst.components.constructionsite_replica:SetSlotCount(1, 3)
Dependencies & tags
Components used: constructionsite (accessed via inst.components.constructionsite on the server), classified (via constructionsite_classified prefab)
Tags: None identified.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
_enabled | net_bool | net_bool(inst.GUID, "constructionsite._enabled") | Networked boolean indicating if the construction site is enabled. |
classified | Entity? | nil | Reference to the constructionsite_classified entity; exists only on client or if late-attached. |
Main functions
OnRemoveEntity()
- Description: Cleans up the
classifiedentity on the server when the host entity is removed. - Parameters: None.
- Returns: Nothing.
- Error states: Only acts when
TheWorld.ismastersimis true andclassifiedis notnil.
AttachClassified(classified)
- Description: Attaches an existing
constructionsite_classifiedentity to this component and registers a listener so it detaches automatically if the classified entity is removed. - Parameters:
classified(Entity) — the classified entity to attach. - Returns: Nothing.
DetachClassified()
- Description: Detaches the current
classifiedentity and clears associated listeners and references. - Parameters: None.
- Returns: Nothing.
SetEnabled(enabled)
- Description: (Server-only) Sets whether the construction site is enabled by updating the networked
_enabledboolean. - Parameters:
enabled(boolean) — new state of the construction site. - Returns: Nothing.
SetBuilder(builder)
- Description: (Server-only) Sets the builder of the construction site on the classified entity. If no
constructionsitecomponent is attached yet, asserts thatbuilderisnil. - Parameters:
builder(Entity ornil) — the entity acting as builder; ifnil, builder is cleared. - Returns: Nothing.
SetSlotCount(slot, num)
- Description: (Server-only) Updates the material count for a specific construction slot via the classified entity.
- Parameters:
slot(string or number) — the slot identifier.num(number) — the number of materials required in that slot.
- Returns: Nothing.
IsEnabled()
- Description: (Client or server) Returns whether the construction site is enabled.
- Parameters: None.
- Returns:
boolean—trueif enabled,falseotherwise.
IsBuilder(guy)
- Description: (Client or server) Checks if the given entity is currently assigned as the builder.
- Parameters:
guy(Entity ornil) — the entity to check. - Returns:
boolean—trueifguyis the current builder,falseotherwise. - Error states: On client, if
constructionsitecomponent is not present, returnstrueonly ifclassifiedexists andguy == ThePlayer.
GetSlotCount(slot)
- Description: (Client or server) Returns the required material count for the specified slot.
- Parameters:
slot(string or number) — the slot identifier. - Returns:
number— material count required for the slot;0ifclassifiedisnilon client. - Error states: On client, returns
0ifclassifiedisnil; on server, delegates toconstructionsite:GetSlotCount(slot).
GetIngredients()
- Description: (Client or server) Returns the construction plan ingredients for the prefab.
- Parameters: None.
- Returns:
table— the ingredients table fromCONSTRUCTION_PLANS[self.inst.prefab], or empty table if not found.
Events & listeners
- Listens to:
onremove— fired when theclassifiedentity is removed; triggersDetachClassified. - Pushes: None identified.