InventoryItem
Based on game build 722832 | Last updated: 2026-04-28
Overview
InventoryItem is the master component that manages inventory item state. Declares netvars for network synchronization, creates classified entity on master for UI state, attaches existing classified on client. Handles pickup restrictions, deploy logic, moisture, wetness, and image overrides. Uses classified entity pattern for network optimization - item UI state is stored in a separate classified entity parented to the item, reducing bandwidth by only syncing relevant fields. Constructor behavior differs based on TheWorld.ismastersim - master spawns classified entity and registers listeners, client attaches existing classified.
Usage example
-- Read item state (safe on both client and master):
if inst.components.inventoryitem ~= nil then
local isWet = inst.components.inventoryitem:IsWet()
local deployMode = inst.components.inventoryitem:GetDeployMode()
local attackRange = inst.components.inventoryitem:AttackRange()
end
-- Modify item state (netvar setters work on both sides):
inst.components.inventoryitem:SetIsWet(true)
inst.components.inventoryitem:SetDeployMode(DEPLOYMODE.DEFAULT)
inst.components.inventoryitem:SetAttackRange(2)
inst.components.inventoryitem:CanBePickedUp(doer)
Dependencies & tags
External dependencies:
TheWorld.ismastersim-- gates master-only initialization and logicSpawnPrefab-- creates classified entity on masterDEPLOYMODE-- deploy mode constantsDEPLOYSPACING_RADIUS-- spacing radius lookup tableTUNING.MAX_WETNESS-- moisture percentage calculation
Components used:
deployable-- reads mode, spacing, restrictedtag on master; mirrors to classifiedweapon-- reads attackrange on master; mirrors to classifiedequippable-- reads walkspeedmult, restrictedtag on master; mirrors to classifiedsaddler-- reads speedmult on master (alternative to equippable)armor-- reads GetPercent() for usage serializationfiniteuses-- reads GetPercent() for usage serializationfueled-- reads GetPercent() for usage serializationperishable-- reads GetPercent() for perish serializationrechargeable-- reads GetPercent()/GetRechargeTime() for recharge serializationinventoryitemmoisture-- reads moisture value on mastercontainer-- reads opencount, openlist for owner determinationreplica.inventory-- accessed via deployer.replica.inventory on client for holding checks (not inst.components)replica.rider-- accessed via deployer.replica.rider on client for riding checks (not inst.components)replica.equippable-- accessed via deployer.replica.equippable on client for equip checks (not inst.components)
Tags:
spider-- checked in CanBePickedUp(); blocks pickup unless doer has "spiderwhisperer"spiderwhisperer-- allows spider-tagged entities to be picked upcomplexprojectile-- required for deploy while ridingboatbuilder-- required for deploy while floating
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
_cannotbepickedup | net_bool | --- | Mirrors pickup restriction state. Read via CanBePickedUp(). |
_iswet | net_bool | --- | Mirrors wet status. Dirty event: iswetdirty. Pushes wetnesschange on change. |
_isacidsizzling | net_bool | --- | Mirrors acid sizzling status. Dirty event: isacidsizzlingdirty. Pushes acidsizzlingchange on change. |
_grabbableoverridetag | net_hash | --- | Override tag for grab restrictions. Read in CanBePickedUp(). |
classified | entity | nil | Classified entity for networked state. Created on master via SpawnPrefab. On client, attached via AttachClassified() from inst.inventoryitem_classified. |
overrideimage | string | nil | Local image override (not networked). Set via OverrideImage(). |
ondetachclassified | function | nil | Callback registered when classified is attached. Fires on classified removal. |
Main functions
AttachClassified(classified)
- Description: Attaches an existing classified entity on the client side. Registers
ondetachclassifiedcallback and listens for "onremove" event on the classified entity. - Parameters:
classified-- entity instance to attach - Returns: nil
- Error states: None.
DetachClassified()
- Description: Detaches the classified entity reference and clears the
ondetachclassifiedcallback. - Parameters: None
- Returns: nil
- Error states: None.
OnRemoveEntity()
- Description: Cleanup handler called when the entity is removed. Removes the classified entity on master (guarded by
if self.classified and TheWorld.ismastersim). - Parameters: None
- Returns: nil
- Error states: None.
SetCanBePickedUp(canbepickedup)
- Description: Sets the
_cannotbepickedupnetvar (inverted logic:truemeans can be picked up). Netvar :set() works on both sides (queues network update). - Parameters:
canbepickedup-- boolean - Returns: nil
- Error states: None.
CanBePickedUp(doer)
- Description: Checks if the item can be picked up by
doer. Returnstrueif doer has the grabbable override tag,falseif doer lacks "spiderwhisperer" tag and item has "spider" tag, otherwise returns inverted_cannotbepickedupvalue. - Parameters:
doer-- entity attempting pickup - Returns: boolean
- Error states: None.
SetCanGoInContainer(cangoincontainer)
- Description: Sets the
cangoincontainerfield on the classified entity. - Parameters:
cangoincontainer-- boolean - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.cangoincontainer:set access).
CanGoInContainer()
- Description: Returns whether the item can go in a container.
- Parameters: None
- Returns: boolean or
nilif classified is nil - Error states: None.
SetCanOnlyGoInPocket(canonlygoinpocket)
- Description: Sets the
canonlygoinpocketfield on the classified entity. - Parameters:
canonlygoinpocket-- boolean - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.canonlygoinpocket:set access).
SetCanOnlyGoInPocketOrPocketContainers(canonlygoinpocketorpocketcontainers)
- Description: Sets the
canonlygoinpocketorpocketcontainersfield on the classified entity. - Parameters:
canonlygoinpocketorpocketcontainers-- boolean - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.canonlygoinpocketorpocketcontainers:set access).
CanOnlyGoInPocket()
- Description: Returns whether the item can only go in a pocket.
- Parameters: None
- Returns: boolean or
nilif classified is nil - Error states: None.
CanOnlyGoInPocketOrPocketContainers()
- Description: Returns whether the item can only go in a pocket or pocket containers.
- Parameters: None
- Returns: boolean or
nilif classified is nil - Error states: None.
SetIsLockedInSlot(locked)
- Description: Sets the
islockedinslotfield on the classified entity. - Parameters:
locked-- boolean - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.islockedinslot:set access).
IsLockedInSlot()
- Description: Returns whether the item is locked in its inventory slot.
- Parameters: None
- Returns: boolean or
nilif classified is nil - Error states: None.
SetImage(imagename)
- Description: Sets the image texture on the classified entity. Appends ".tex" extension if not nil.
- Parameters:
imagename-- string or nil - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.image:set access).
OverrideImage(imagename)
- Description: Sets a local (non-networked) image override. Pushes "imagechange" event. Does not sync to clients.
- Parameters:
imagename-- string or nil - Returns: nil
- Error states: None.
GetImage()
- Description: Returns the current image texture path. Checks client-side overrides first, then local override, then classified value, then defaults to prefab name.
- Parameters: None
- Returns: string texture path
- Error states: None.
SetAtlas(atlasname)
- Description: Sets the atlas path on the classified entity. Resolves file path if not nil.
- Parameters:
atlasname-- string or nil - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.atlas:set access).
GetClientSideInventoryImageOverride(self) (local)
- Description: Local helper function that checks for client-side inventory image overrides. Returns override data table with
imageandatlasfields, or nil if no override exists. - Parameters:
self-- InventoryItem component instance - Returns: Table with
imageandatlasfields, or nil - Error states: None.
GetAtlas()
- Description: Returns the current atlas path. Checks client-side overrides first, then classified value, then defaults via
GetInventoryItemAtlas(). - Parameters: None
- Returns: string atlas path
- Error states: None.
SetOwner(owner)
- Description: Sets the owner and updates classified target. Handles multi-slot container edge cases by forcing out of limbo and clearing classified target if
opencount > 1. - Parameters:
owner-- entity or nil - Returns: nil
- Error states: None (nil guards present for owner and owner.components.container access:
owner ~= nil and owner.components.container ~= nil and owner.components.container.opencount or 0).
IsHeld()
- Description: Returns whether the item is currently held. Checks master
inventoryitemcomponent first, then falls back to classified existence on client. - Parameters: None
- Returns: boolean
- Error states: None.
IsHeldBy(guy)
- Description: Returns whether the item is held by
guy. On client, checks ifguyisThePlayerand usesreplica.inventory:IsHolding(). - Parameters:
guy-- entity to check - Returns: boolean
- Error states: None.
IsGrandOwner(guy)
- Description: Returns whether
guyis the grand owner (owner of owner). On client, checks ifguyisThePlayerand usesreplica.inventory:IsHolding(..., true). - Parameters:
guy-- entity to check - Returns: boolean
- Error states: None.
SetPickupPos(pos)
- Description: Sets the pickup position on the classified entity's
src_posnetvars. Marks position as valid or invalid. - Parameters:
pos-- Vector3 or nil - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.src_pos access).
GetPickupPos()
- Description: Returns the stored pickup position as a Vector3, or nil if position is invalid.
- Parameters: None
- Returns: Vector3 or nil
- Error states: None.
SerializeUsage()
- Description: Serializes usage stats (percent used, perish, recharge) to the classified entity. Reads from
armor,finiteuses,fueled,perishable, andrechargeablecomponents. - Parameters: None
- Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified:SerializePercentUsed access).
DeserializeUsage()
- Description: Deserializes usage stats from the classified entity on the client.
- Parameters: None
- Returns: nil
- Error states: None (guarded by
if self.classified ~= nil).
SetChargeTime(t)
- Description: Sets the recharge time and pushes "rechargetimechange" event.
- Parameters:
t-- number (time in seconds) - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified:SerializeRechargeTime access).
SetDeployMode(deploymode)
- Description: Sets the deploy mode on the classified entity.
- Parameters:
deploymode-- DEPLOYMODE constant - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.deploymode:set access).
GetDeployMode()
- Description: Returns the deploy mode. Checks master
deployablecomponent first, then classified value, then defaults toDEPLOYMODE.NONE. - Parameters: None
- Returns: DEPLOYMODE constant
- Error states: None.
IsDeployable(deployer)
- Description: Checks if the item can be deployed by
deployer. On client, checks restricted tag, riding state (requires "complexprojectile" tag), and floating state (requires "boatbuilder" tag). - Parameters:
deployer-- entity attempting deploy - Returns: boolean
- Error states: None.
SetDeploySpacing(deployspacing)
- Description: Sets the deploy spacing on the classified entity.
- Parameters:
deployspacing-- DEPLOYSPACING constant - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.deployspacing:set access).
DeploySpacingRadius()
- Description: Returns the deploy spacing radius. Checks master
deployablecomponent first, then looks up classified value inDEPLOYSPACING_RADIUS, then defaults. - Parameters: None
- Returns: number (radius)
- Error states: None.
SetDeployRestrictedTag(restrictedtag)
- Description: Sets the deploy restricted tag on the classified entity.
- Parameters:
restrictedtag-- string or nil (converted to 0 if nil) - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.deployrestrictedtag:set access).
CanDeploy(pt, mouseover, deployer, rot)
- Description: Checks if the item can be deployed at point
pt. Delegates to masterdeployablecomponent if present, otherwise uses classified deploy mode to check map passability, turf placement, plant/wall deployment, water deployment, or custom deployment logic. - Parameters:
pt-- Vector3 deployment pointmouseover-- entity under mousedeployer-- entity attempting deployrot-- rotation for deployment
- Returns: boolean
- Error states: None.
SetUseGridPlacer(usegridplacer)
- Description: Sets the grid placer flag on the classified entity.
- Parameters:
usegridplacer-- boolean - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.usegridplacer:set access).
GetDeployPlacerName()
- Description: Returns the placer prefab name. Returns "gridplacer" if grid placer is enabled, otherwise returns
overridedeployplacernameor prefab-based default. - Parameters: None
- Returns: string placer name
- Error states: None.
SetAttackRange(attackrange)
- Description: Sets the attack range on the classified entity.
- Parameters:
attackrange-- number - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.attackrange:set access).
AttackRange()
- Description: Returns the attack range. Checks master
weaponcomponent first, then classified value (if> -99), then defaults to 0. - Parameters: None
- Returns: number
- Error states: None.
IsWeapon()
- Description: Returns whether the item is a weapon. Checks for master
weaponcomponent or classified attack range> -99. - Parameters: None
- Returns: boolean
- Error states: None.
SetWalkSpeedMult(walkspeedmult)
- Description: Sets the walk speed multiplier on the classified entity. Uses string conversion to avoid floating-point precision errors. Asserts value is in range
0-255and has at most 0.01 precision. - Parameters:
walkspeedmult-- number or nil - Returns: nil
- Error states: Asserts if value is out of range or has too much precision. Errors if
classifiedis nil (no nil guard before classified.walkspeedmult:set access).
GetWalkSpeedMult()
- Description: Returns the walk speed multiplier. Checks master
equippablecomponent first, then calculates from classified value (divided by 100). Applies "vigorbuff" bonus andinventory_EquippableWalkSpeedMultModifiercallback on client if equipped. - Parameters: None
- Returns: number (multiplier)
- Error states: None.
SetEquipRestrictedTag(restrictedtag)
- Description: Sets the equip restricted tag on the classified entity.
- Parameters:
restrictedtag-- string or nil (converted to 0 if nil) - Returns: nil
- Error states: Errors if
classifiedis nil (no nil guard before classified.equiprestrictedtag:set access).
GetEquipRestrictedTag()
- Description: Returns the equip restricted tag. Checks master
equippablecomponent first, then classified value. - Parameters: None
- Returns: string or nil
- Error states: None.
SetMoistureLevel(moisture)
- Description: Sets the moisture level on the classified entity.
- Parameters:
moisture-- number - Returns: nil
- Error states: None (guarded by
if self.classified ~= nil).
GetMoisture()
- Description: Returns the moisture value. Checks master
inventoryitemmoisturecomponent first, then classified value, then defaults to 0. - Parameters: None
- Returns: number
- Error states: None.
GetMoisturePercent()
- Description: Returns the moisture as a percentage of
TUNING.MAX_WETNESS. - Parameters: None
- Returns: number (0-1 range)
- Error states: None.
SetIsWet(iswet)
- Description: Sets the wet status. Only updates and pushes "wetnesschange" event if value changed.
- Parameters:
iswet-- boolean - Returns: nil
- Error states: None.
IsWet()
- Description: Returns the wet status from the
_iswetnetvar. - Parameters: None
- Returns: boolean
- Error states: None.
SetIsAcidSizzling(isacidsizzling)
- Description: Sets the acid sizzling status. Only updates and pushes "acidsizzlingchange" event if value changed.
- Parameters:
isacidsizzling-- boolean - Returns: nil
- Error states: None.
IsAcidSizzling()
- Description: Returns the acid sizzling status from the
_isacidsizzlingnetvar. - Parameters: None
- Returns: boolean
- Error states: None.
SetGrabbableOverrideTag(tag)
- Description: Sets the grabbable override tag. Converted to 0 if nil.
- Parameters:
tag-- string or nil - Returns: nil
- Error states: None.
Events & listeners
-
Listens to (registered on master):
percentusedchange-- serializes percent used to classified entity. Data:{percent = number}perishchange-- serializes perish percent to classified entity. Data:{percent = number}forceperishchange-- forces perish dirty on classified entity. Data: nonerechargechange-- serializes recharge percent and overtime to classified entity. Data:{percent = number, overtime = number}onremove(on classified) -- triggersDetachClassified()on client. Data: none
-
Pushes:
imagechange-- fired whenOverrideImage()is called. Data: nonewetnesschange-- fired when wet status changes. Data: boolean (new wet status)acidsizzlingchange-- fired when acid sizzling status changes. Data: boolean (new sizzling status)rechargetimechange-- fired when charge time is set. Data:{t = number}