TL;DR
The on_post_entity_died event should include a way to associate the event with the entity that died.What ?
The event for on_post_entity_died should include a field entity_unit_number containing the unit_number of the entity that died or nil.Why ?
In many mods the entities unit_number is used as key to store information about entities. The information is usually created when an entity is built and removed when an entity is mined or destroyed. Unlike entities or other keys the unit_number is preserved across game save and load so the mods global data remains valid and remains associated to the same entity.Now in 0.17.67 LuaItemStack.set_blueprint_entity_tag() and LuaEntity.tags for ghosts was added so mods could store custom data in blueprints and ghost to recreate an entities configuration when the the entity is blueprinted. I want to use the same so that the configuration of an entity is preserved when it dies and is rebuild from the ghost.
In on_entity_died() the event contains the entity that has died before it gets destroyed. But at that time the ghost does not yet exist. In on_post_entity_died() the event contains the ghost but no reference is made to the (now invalid) entity and the entity no longer exists. So mods have to save the entities data in on_entity_died() to some temporary location and transfer it to tags in on_post_entity_died(). This is complicated by the fact that multiple on_entity_died() events can be triggered recursively (the mod can kill another entity in on_entity_died) and then on_post_entity_died() events happen in the reverse order. So it's not enough to simply remember the last entity that died.
This makes it hard to copy configuration from the entity into tags of the ghost. But if the event also included the originals entity.unit_number then that could be used to lookup the entities LUA data in the mod, transfer that to the ghosts tags and remove the data from the mods lookup table. In most cases a on_entity_died() event handler wouldn't be needed anymore and complex mods would have a simple way of associating the ghosts with previous entities.