Provide actual ItemStack in on(_robot)_built_entity

Post Reply
User avatar
mickael9
Fast Inserter
Fast Inserter
Posts: 112
Joined: Mon Mar 14, 2016 4:04 am
Contact:

Provide actual ItemStack in on(_robot)_built_entity

Post by mickael9 »

Currently, there is no easy way to get the actual ItemStack that is being used for building an entity in a reliable way.
My use case here is copying the inventory of an item-with-inventory into the entity its being placed (a container) without loosing any state (item-with-inventory, blueprints, item-with-tags, labels, etc.)

My actual solution is to create the entity myself in on_put_item and use the player's cursor_stack to transfer the inventory to the created entity, but it has a major drawback:
I can't differentiate between the user placing a ghost and the user placing a real entity, which means a real entity will always be built even if the player intended to place a ghost.

For robots (on_robot_built_entity), the issue is worse since there is no way to access the real ItemStack at all (you only get the item name and its tags).

My suggestion is to add a new event parameter to on_robot_built_entity and on_built_entity. This parameter could either be a LuaItemStack or a LuaInventory (much like the buffer parameter to on_player_mined_entity) and it would contain the single item that was used to build the entity

Rseding91
Factorio Staff
Factorio Staff
Posts: 13202
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Provide actual ItemStack in on(_robot)_built_entity

Post by Rseding91 »

Ah, I guess I forgot about those events. I made the mined event useful in that it gives you the actual items but forgot about the built ones :)

I'll think about changing around the built events so they always give the item in the event. I don't know if it will make it into 0.15 though - it depends how complicated it ends up being making it work with validation that the stack is still valid.
If you want to get ahold of me I'm almost always on Discord.

Post Reply

Return to “Implemented mod requests”