I wanted to create a solution to run this code without freezing the screen, even if only in parts. But something that works.
Code: Select all
local surface = game.player.surface
for _, e in pairs(surface.find_entities_filtered{type="resource"}) do
if e.prototype.infinite_resource then
e.amount = e.initial_amount
else
e.destroy()
end
end
local non_infinites = {}
for resource, prototype in pairs(prototypes.get_entity_filtered{{filter="type", type="resource"}}) do
if not prototype.infinite_resource then
table.insert(non_infinites, resource)
end
end
surface.regenerate_entity(non_infinites)
for _, e in pairs(surface.find_entities_filtered{type="mining-drill"}) do
e.update_connections()
end