Container Classified
Based on game build 714014 | Last updated: 2026-03-04
Overview
Container Classified is a specialized container component used to manage the client-side preview state and RPC-driven synchronization of inventory slots during player-driven interactions (e.g., crafting, building, item transfer). It operates alongside the container component on the same entity, providing non-blocking, optimistic UI updates via preview state (_itemspreview) until server confirmation is received. It is typically attached to entities that act as containers in crafting/building workflows (e.g., workbenches, chests, crafting tables) and works in coordination with inventory_classified to handle active-item operations.
Usage example
-- Creating a classified container entity (server-side)
local inst = CreateEntity()
inst:AddTag("container")
inst:AddComponent("container")
inst:AddComponent("container_classified")
-- Client-side, it is attached automatically via OnEntityReplicated
-- No direct manual instantiation needed on the client
Dependencies & tags
Components used:
container(viainst._parent.replica.container)inventoryitem(viaitem.replica.inventoryitem)stackable(viaitem.replica.stackable)constructionbuilderuidata(indirectly, for crafting ingredient slot mapping)
Tags:
- Adds
CLASSIFIEDto the entity viainst:AddTag("CLASSIFIED"). - No tags are checked or removed dynamically.
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
infinitestacksize | net_bool | false | Networked boolean indicating whether overstacked items are allowed. |
readonlycontainer | net_bool | false | Networked boolean; triggers "readonlycontainerdirty" event on change. |
_items | table of net_entity | {} | Networked slot entities; one per container slot. |
_itemspool | table of net_entity | {} | Reusable networked entity pool for slots. |
_itemspreview | table or nil | nil | Client-side preview buffer for slot items; non-nil during pending operations. |
_slottasks | table or nil | nil | Tracks deferred slot tasks (e.g., dirty handlers) on the client. |
_refreshtask | GScriptTask or nil | nil | Task scheduled to reset preview state after TIMEOUT. |
_busy | boolean | true | Server-side flag indicating if the container is unavailable for interaction. |
_parent | entity or nil | nil | Entity that owns this classified container (only set on client after replication). |
Main functions
InitializeSlots(inst, numslots)
- Description: Adjusts the number of active inventory slots to match
numslots. Can only be called once beforeRegisterNetListeners. Adds or removes slots using the internal_itemspool. - Parameters:
numslots(number) — target number of slots (must be>= 1and<= containers.MAXITEMSLOTS).
- Returns: Nothing.
- Error states: Throws an
asserterror if called after_slottaskshas been initialized.
IsBusy(inst)
- Description: Returns
trueif the container is busy or has no parent (client-side). - Parameters: None.
- Returns:
boolean. - Error states: None.
GetItemInSlot(inst, slot)
- Description: Retrieves the item in the specified slot, using either the live
_items(server/normal state) or_itemspreview(client preview state). - Parameters:
slot(number) — 1-indexed slot index.
- Returns:
entityornil. - Error states: Returns
nilfor out-of-bounds slots.
GetItems(inst)
- Description: Returns an array of actual items in all slots (from
_items:value()), or preview items if_itemspreviewis set. - Parameters: None.
- Returns:
table(array ofentityornil).
IsEmpty(inst)
- Description: Returns
trueif all slots are empty (emptynilentries in both live and preview states). - Parameters: None.
- Returns:
boolean.
IsFull(inst)
- Description: Returns
trueif all slots are occupied (nonilentries in both live and preview states). - Parameters: None.
- Returns:
boolean.
Has(inst, prefab, amount, iscrafting)
- Description: Counts total items of
prefabup toamount, optionally excluding items tagged"nocrafting". - Parameters:
prefab(string) — prefab name.amount(number) — required minimum count.iscrafting(boolean) — whether to excludenocraftingitems.
- Returns:
count >= amount(boolean),count(number).
HasItemWithTag(inst, tag, amount)
- Description: Counts total items with
tagup toamount. - Parameters:
tag(string) — tag name to match.amount(number) — required minimum count.
- Returns:
count >= amount(boolean),count(number).
FindItem(inst, fn)
- Description: Returns the first item satisfying predicate
fn(item), checking either_itemspreviewor live_items. - Parameters:
fn(function) — predicate accepting anentity.
- Returns:
entityornil.
ReceiveItem(inst, item, count, forceslot)
- Description: Attempts to insert
iteminto the container. Handles stacking, overstacking (respectinginfinitestacksize), and overflow accounting. Called during item placement (e.g.,MoveItemFromAllOfSlot). - Parameters:
item(entity) — item to insert.count(number ornil) — max number of items to accept (defaults to full stack ifnil).forceslot(number ornil) — specific slot index to attempt insertion (1-based).
- Returns:
number— number of leftover items (0 if fully accepted). - Error states: Returns
0if container is busy orforceslotis invalid.
ConsumeByName(inst, prefab, amount)
- Description: Removes items by
prefabup toamount, consuming entire stacks or splitting stacks as needed. - Parameters:
prefab(string) — prefab name to consume.amount(number) — number of items to remove (<= 0returns early).
- Returns: Nothing.
TakeActionItem(inst, item, slot)
- Description: Removes
itemfromslotduring active UI interaction (e.g., drag/drop). - Parameters:
item(entity) — must matchGetItemInSlot(slot).slot(number) — slot index.
- Returns: Nothing.
- Error states: No-op if container is busy or item mismatch.
Events & listeners
-
Listens to:
"items[<N>]dirty"— triggered per slot on server update; defersOnItemsDirtyby one frame."readonlycontainerdirty"— triggers immediate refresh."stackitemdirty"(world event) — if item is held in this container, triggersOnStackItemDirty.
-
Pushes (client):
"refresh"— fires on container refresh."itemget"/"itemlose"— fired when item is added/removed in preview."gotnewitem"— fired on gaining item (if held byThePlayer)."stacksizechange"— pushed on item stack size change."stacksizepreview"— pushed when previewing stack size changes."refreshcrafting"/"cancelrefreshcrafting"— fired to synchronize crafting UI.
-
Pushes (server): none directly — only via parent entity (e.g.,
inst._parent:PushEvent("refresh")).