I would like the ability to build/deploy an entity directly from an item, so that if there is entity data saved in the item it would be carried over to the new entity automatically just as though the entity had been built by a player.
Ideally the function would be similar to surface.create_entity except that instead of specifying a name you specify item = LuaItemStack
The entity I'm struggling with is the spidertron as an item. I can't create a spider that properly matches the item because not all values are readable (as far as I can tell), but even if they were the ability to do this in 1 call would be much better than lengthy code trying to replicate the item placement process in lua.
surface.create_entity_from_item(...)
Re: surface.create_entity_from_item(...)
A workaround may be to put the item in a player's cursor and then use LuaPlayer#build_from_cursor() to place it, before restoring the player's cursor to whatever it was before. "Temporarily saving the cursor" could be done by creating a one-slot script inventory, swapping the player's cursor into the script inventory's slot, then putting the item to place in the cursor, building it, and finally swapping it back and destroying the temporary inventory.
It's a hack, but if it all happens in one tick then it's completely invisible to the player.
A simple method to do this would be much better though!
It's a hack, but if it all happens in one tick then it's completely invisible to the player.
A simple method to do this would be much better though!
Re: surface.create_entity_from_item(...)
The player hack is a good idea but has some unwanted side-effects and would stop working if nobody was logged onto the server. My use case is rocket-deployed spidertrons for colonising alien planets that are different surfaces.
Re: surface.create_entity_from_item(...)
Ok, I added "item" to create_entity for the next release.
If you want to get ahold of me I'm almost always on Discord.