placed_item in on_built_entity/on_robot_built_entity

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
mknejp
Fast Inserter
Fast Inserter
Posts: 154
Joined: Wed Apr 27, 2016 8:29 pm
Contact:

placed_item in on_built_entity/on_robot_built_entity

Post by mknejp »

Is it possible to add the field "placed_item" to the event data of "on_built_entity" and "on_robot_built_entity" if that information is available?

The rationale for this is being able to return the item used to build it if placing the entity fails for some mod-specific reason after the fact. Since there are multiple items that can be placed for an entity it's not reliably possible to return exactly the same item type.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: placed_item in on_built_entity/on_robot_built_entity

Post by aubergine18 »

+1 from me. Currently I'm having to keep checking what player has in their hand and cache that so if the entity built event gets fired I know what item was used (but in this context, only if it was player who built it - I still have no clue what item a robot used without doing lots of extra digging).

I was going to suggest a method on entities something like someEntity.get_item_used_to_create() but then realised that increasingly mods are creating multiple entities when an item is placed (the concrete lamppost mod is a good example). As such, the only reliable point at which we could get details about what item was used to create the entity is in those events as described in OP.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: placed_item in on_built_entity/on_robot_built_entity

Post by aubergine18 »

If you dig through to an entity prototype, you can find items used to create the entity:

http://lua-api.factorio.com/latest/LuaE ... place_this

Looks like a list of any item that can be used to place the entity. Problem is, there is no indication of which specific item was used (usually there will only be one such item so possibly not that big a problem?)
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14273
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: placed_item in on_built_entity/on_robot_built_entity

Post by Rseding91 »

Factorio doesn't properly handle multiple items able to build the same entity. It always defaults to the first item if there are more than 1 that can build a given entity.

So, at the moment if there's an entity built the game will only ever know that "it was either built from the first item that builds this or I have no idea".
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding interface requests”