Componentactions
Based on game build 714014 | Last updated: 2026-03-10
Overview
The componentactions.lua file implements a flexible Entity Component System (ECS) extension that enables dynamic, context-sensitive actions on entities based on their attached components and the user's input mode (e.g., INVENTORY, EQUIPPED, POINT). It provides registration and dispatch mechanisms for action collectors (functions that populate an actions table with valid actions), validation of actions (via ISVALID handlers), and support for both core game and modded components. Entities expose their action capability via CollectActions(actiontype, ...) and IsActionValid(action, right), while mods can register custom action handlers via AddComponentAction.
Usage example
-- Register a custom action collector for a component named "mycomponent"
local function MyComponentActionCollector(inst, doer, actions, right)
if doer:HasTag("player") and inst:HasTag("mytag") then
table.insert(actions, ACTIONS.MYACTION)
end
end
AddComponentAction("INVENTORY", "mycomponent", MyComponentActionCollector, "MyMod")
-- On an entity instance, collect and validate actions
local actions = {}
self.inst:CollectActions("INVENTORY", doer, actions, false)
for _, action in ipairs(actions) do
if self.inst:IsActionValid(action, false) then
-- Handle action
end
end
Dependencies & tags
Components used:
aoetargetingattunerboatringdataconstructionbuilderuidatacontainer_proxycontainerinstallableitemfloaterplayercontrollerpumpkincarvablepumpkinhatcarvablerevivablecorpsesinginginspirationskilltreeupdaterspellbookplantregistry(viaThePlantRegistry)
Tags:
"inactive","engineering","activatable_forceright""anchor_raised","anchor_transitioning""attuned""boat","overriderowaction","paired","fire","burnt","occupied","ammoloaded","turnedoff","rotating""bathingpool""battery","batteryuser""bundle","openedby","bundle_raised","bundle_lowered""cancatch","catchable","projectile","fishinghook","fishing_idle""channelable","channeled""combat","dead""container_proxy","bundle""critter","woby","hitcher","hitcher_locked","noabandon","fedbyall","handfed""crop","readyforharvest","withered""cancycle""deckcontainer","playingcard""dried""electrically_linked","fully_electrically_linked""farmplantstress","weedplantstress","tendable_farmplant""fertilizer","self_fertilizable""grabbable"(deprecated)"groomer","hitcher""harvestable""hauntable","haunted","catchable""heavy","heavylift_lmb","heavyobstacleusetarget","can_use_heavy""inventoryitemholder_take","takeitem""kitcoonden""lock","unlockable""machine","cooldown","fueldepleted","alwayson","emergency","enabled","groundonlymachine","turnedon""madsciencelab","readytocook","container_full","container_opened""magiciantool""markable","markable_proxy""mast","sailraised","saillowered","sail_transitioning","is_furling""mightygym","hasstrongman","loaded","strongman","player""mine","minesprung","mine_not_reusable""ghostgestalter","wendy_lunar_3""occupiable","occupied""oceantrawler","trawler_fish_escaped","trawler_lowered""pinnable","pinned""pickable","intense","searchable""plantresearchable","fertilizerresearchable","researchstage","fertilizerkey""portablestructure","portable_campfire","portable_campfire_user","mastercookware","masterchef","portableengineer","groundonlymachine","fueldepleted","enabled","cooldown""prototyper""pushable""tappable","tapped_harvestable","CHOP_tool""questing","questowner","CanBeActivatedBy_Client""repairable_sculpture","work_sculpture","repairable_moon_altar","work_moon_altar""revivablecorpse","corpse""rideable","hitched","dogrider_only","dogrider","woby""rider","mount""shelf","takeshelfitem""sittable","cansit""sleepingbag","hassleeper","insomniac","spiderden","spiderwhisperer","player""snowmandecoratable","waxedplant","heavy""spellbook","usingmagiciantool","usingmagictool","spellbook_open""steeringwheel","occupied""stewer","donecooking","readytocook","professionalcookware","professionalchef","mastercookware""stageactingprop","play_in_progress","stageactor""storytellingprop","portable_campfire","storyteller","portable_campfire_user""talkable","maxwellnottalking""teleporter","townportal","vault_teleporter","channeling""trap","trapsprung""trophyscale_","weighable_","trophycanbetaken","burnt","fire""unwrappable""walkingplank","interactable","plank_extended","on_walkable_plank""wardrobe","dressable""writeable""wobycourier","whistleaction","portable_campfire","portable_campfire_user""worldmigrator","migrator""yotb_sewer","readytosew""yotb_stager","yotb_conteststartable","has_prize","yotc_conteststartable""yotc_racecompetitor","has_prize","has_no_prize""yotc_racestart","race_on""equippable""healerbuffs""inuse","cannotuse""useabletargeteditem_inventorydisable","inuse_targeted""maxwellnottalking""ghostfriend_notsummoned","ghostfriend_summoned""pocketwatch_inactive","pocketwatchcaster","pocketwatch_castfrominventory","pocketwatch_mountedcast""accepts_oceanfishingtackle""engineering","handyperson""castfrominventory","crushitemcast""LunarBuildup""bearded"
Properties
| Property | Type | Default Value | Description |
|---|
Main functions
CanCastFishingNetAtPoint(thrower, target_x, target_z)
- Description: Determines if a fishing net can be cast at a given world point by verifying the point lies on ocean (real or virtual) and is at least
min_throw_distanceaway from the thrower. - Parameters:
thrower: Entity expected to have aTransformcomponent, representing the actor casting the net.target_x: X-coordinate (world space).target_z: Z-coordinate (world space; Y is ignored).
- Returns:
trueif distance and ocean conditions are satisfied; otherwisefalse.
Row(inst, doer, pos, actions)
- Description: Appends rowing actions to
actionsfor a player on a boat, accounting for controller vs keyboard input and platform changes. - Parameters:
inst: Unused (retained for interface consistency).doer: Player or entity attempting to row.pos: World position of the cursor or aiming point.actions: Mutable table into whichROWactions are appended.
- Returns:
nil. Modifiesactionsin-place.
PlantRegistryResearch(inst, doer, actions)
- Description: Appends plant registry research or plant stress assessment actions if the doer is wielding a plant inspector or is plantkin and the target has researchable or stress tags.
- Parameters:
inst: Target entity (typically a plant or fertilizer).doer: Player entity performing the check.actions: Mutable actions table.
- Returns:
nil.
GetFishingAction(doer, fishing_target)
- Description: Selects the correct ocean fishing action based on the
doer’s state andfishing_target’s properties (e.g., catchable, projectile). - Parameters:
doer: Player entity infishing_idlestate.fishing_target: Entity withfishinghook,catchable, orprojectiletags.
- Returns: One of
ACTIONS.OCEAN_FISHING_STOP,ACTIONS.OCEAN_FISHING_CATCH,ACTIONS.OCEAN_FISHING_REEL, ornil.
CheckRowOverride(doer, target)
- Description: Checks whether a nearby object (e.g., an
oceantrawler) overrides standard rowing behavior via proximity. - Parameters:
doer: Player or entity.target: Candidate override object withoverriderowactiontag.
- Returns:
trueif the target’s radius covers the doer (viaboatringdata:GetRadius()andTUNING.OVERRIDE_ROW_ACTION_DISTANCE); otherwisefalse.
IsValidScytheTarget(target)
- Description: Checks whether
targetis scythe-compatible. - Parameters:
target: Entity to test.
- Returns:
trueiftarget:HasOneOfTags(SCYTHE_ONEOFTAGS); otherwisefalse.
AddComponentAction(actiontype, component, fn, modname)
- Description: Registers a mod-defined action handler for a given action type and component. Adds the component to mod-specific tracking tables and validates mod sync.
- Parameters:
actiontype: Key inCOMPONENT_ACTIONS(e.g.,"INVENTORY","EQUIPPED","POINT").component: Name of the component (string) whose action is being registered.fn: Collector function accepting(inst, doer, actions, right)or equivalent parameters peractiontype.modname: Mod name used for synchronization diagnostics.
- Returns:
nil. Throws diagnostic warning if mod sync is broken.
EntityScript:RegisterComponentActions(name)
- Description: Registers the entity to respond to actions handled by a given component, updating
self.actioncomponentsandself.modactioncomponents. - Parameters:
name: Component name (string).
- Returns:
nil. Silent no-op ifACTION_COMPONENT_IDS[name]does not exist.
EntityScript:UnregisterComponentActions(name)
- Description: Removes the entity from a given component’s action list.
- Parameters:
name: Component name.
- Returns:
nil.
EntityScript:CollectActions(actiontype, ...)
- Description: Invokes all action collectors registered for
actiontypeon this entity, including modded ones. - Parameters:
actiontype: Key inCOMPONENT_ACTIONS(e.g.,"INVENTORY")....: Arguments passed to each collector (e.g.,doer,actions,right).
- Returns:
nil. Prints warning ifactiontypeis unknown.
EntityScript:IsActionValid(action, right)
- Description: Checks if
actionis valid for this entity by delegating to registeredISVALIDhandlers. - Parameters:
action: Action object (must contain.id,.rmbkeys).right: Boolean (truefor right-click context).
- Returns:
trueif any registered ISVALID handler returnstrue; otherwisefalse.
EntityScript:HasActionComponent(name)
- Description: Checks whether
nameis registered as an action component for this entity. - Parameters:
name: Component name.
- Returns:
trueif registered; otherwisefalse.
inventoryitem(inst, doer, target, actions, right)
- Description: Collection function that populates
actionsbased on the doer’s held or equipped item and target context. Handles storage, gifting, equipping, loadings, mounting, repair, cooking, harvesting, etc. This is the core dispatcher for item-related actions and is invoked per item tag/component when an item is used. - Parameters:
inst: Item being used (held/equipped).doer: Entity (typically player) using the item.target: Entity being acted upon.actions: Mutable actions table.right: Boolean (true= right-click).
- Returns:
nil.
inventoryitem_point(inst, doer, target, pos, actions, right)
- Description: Version of
inventoryitemfor actions triggered at a point (POINTtype). Used for dropping, deploying, casting fishing nets, till soil, etc. - Parameters: Same as
inventoryitem, pluspos(world position). - Returns:
nil.
inventoryitem_equipped(inst, doer, target, actions, right)
- Description: Version of
inventoryitemfor actions triggered on equipped items (EQUIPPEDtype). Handles charging, channeling, using in-hand tools, rowing, etc. - Parameters: Same as
inventoryitem, but contextually used with equipped items. - Returns:
nil.
Events & listeners
No events are defined or listened to in this file. It is purely an action registration and dispatch system. Event-driven behavior is handled in other files (e.g., stategraphs, components, actions.lua).