Page 1 of 1

entity.destroy() makes new item-on-the-ground

Posted: Fri Oct 19, 2018 4:18 pm
by darkfrei
Hi all!

I have a problem with my mod https://mods.factorio.com/mod/SmogSolarPanels

How it works:
If the player places solar panel, then this panel will be added to the global table.
Every tick will be checked one entity from the table. If in this position is another pollution as expected, then new entity with lower/higher power will be placed on this position.
Here is not fast_replaceable_group by solar panels and I need to destroy old solar panel. On the destroying I get new item-on-the-ground under this entity.

The bug cannot be reproduced due

Code: Select all

/c game.player.selected.destroy()

Re: entity.destroy() makes new item-on-the-ground

Posted: Sat Oct 20, 2018 1:06 am
by Nexela
entity.destroy() is not making a new item, fast_replace = true is

It simulates fast_replacing an entity, if there is no player associated to the create_entity event then the item from mining is spilled to the ground. so you need to add spill=false

I think this next bit applies to later versions of .16 also
Also the original entity is already destroyed when fast_replacing but you can destroy() invalid stuff without an error thanks to rseding :)

Also when items are not in the same fast_replace_group they are not fast_replacable and they won't spill an item.

Re: entity.destroy() makes new item-on-the-ground

Posted: Sat Oct 20, 2018 9:54 am
by darkfrei
Nexela wrote:
Sat Oct 20, 2018 1:06 am
entity.destroy() is not making a new item, fast_replace = true is

It simulates fast_replacing an entity, if there is no player associated to the create_entity event then the item from mining is spilled to the ground. so you need to add spill=false
By solar panels is no fast replacing, but with "spill=false" it works, thanks!