Since ghosts don't raise build events
Not sure when this was last the case, but that is not true.
I was wondering why you were scanning instead of just listening to events. As the performance annoyed me a bit as well.
Started a quick mod to mock that, and it seems very possible. I saw you are not actively developing/maintaining mods anymore, so I'll continue on mine for personal use.
If there is any desire from the community I might upload it. Or of course this mod can be updated accordingly too.
(With listening to events there might be a performance hit if there are many bots placing items. But at least no computing power when there are no construction jobs, and the combinator is updated instantly. )
Here are all the events for keeping track of construction jobs:
-- creating ghosts/upgrades
script.on_event(defines.events.on_built_entity, function(event) entity_created(event.created_entity) end)
script.on_event(defines.events.on_marked_for_upgrade, function(event) entity_created(event.entity, event.target) end)
script.on_event(defines.events.on_entity_cloned, function(event) entity_created(event.source) end)
script.on_event(defines.events.script_raised_built, function(event) entity_created(event.entity) end)
-- both creating and deleting ghosts/upgrades
script.on_event(defines.events.on_pre_ghost_upgraded, function(event)
entity_removed(event.ghost)
entity_created(event.ghost, event.target)
end)
-- deleting ghosts/upgrades
script.on_event(defines.events.on_robot_built_entity, function(event) entity_removed(event.created_entity, event.created_entity.prototype) end)
script.on_event(defines.events.on_player_mined_entity, function(event) entity_removed(event.entity) end)
script.on_event(defines.events.on_cancelled_upgrade, function(event) entity_removed(event.entity, event.target) end)
script.on_event(defines.events.on_marked_for_deconstruction, function(event) entity_removed(event.entity) end)
script.on_event(defines.events.on_pre_ghost_deconstructed, function(event) entity_removed(event.ghost) end)
script.on_event(defines.events.on_entity_died, function(event) entity_removed(event.entity) end)
script.on_event(defines.events.script_raised_destroy, function(event) entity_removed(event.entity) end)
script.on_event(defines.events.script_raised_revive, function(event) entity_removed(event.entity) end)
And then entity_removed/created start with
local function entity_created(entity, target)
if not target and entity.type ~= "entity-ghost" then return end
local required_item = (target or entity.ghost_prototype).items_to_place_this[1]
Edit. Forgot about tiles, but easy enough to add too