Hi! You only listen to on_built_entity and on_entity_died. However, you will miss entities that are placed by bots or script, or mined by the player etc. I think you should listen to the following events instead:
Build events:
- on_built_entity
- on_entity_cloned
- on_robot_built_entity
- script_raised_built
- script_raised_revive
Removal events:
- on_entity_destroyed
- on_entity_died
- on_player_mined_entity
- on_robot_mined_entity
- script_raised_destroy
Some of these may use different event data, so you can reuse your existing event handlers with slight adjustments. Here's an example from the handler for build-events in one of my mods:
-- We use the same function for different events, so we must cover all different
-- key names to get the entity!
local vehicle = event.created_entity or -- on_built_entity/on_robot_built_entity
event.destination or -- on_entity_cloned
event.entity -- script_raised_*