I experience quite a lot of stuttering, every second or so, when I tried this mod. So I took a look at the code and made the following changes, which seem to fix it. Feel free to use these changes.
As far as I can tell, the issue stems from the fact that the current code removes the resources from the entire chunk, instead of only removing resources from the chunk that was generated, so I added the surface and area parameters to the remove_ores_on_Nauvis function and removed the loop over all surfaces inside this function.
-- control.lua
local function remove_ores_on_Nauvis(surface, resources, area)
if surface.name ~= "nauvis" then
return
end
for _, resource_name in pairs(resources) do
for _, entity in pairs(surface.find_entities_filtered {
type = "resource",
name = resource_name,
area = area
}) do
entity.destroy()
end
end
end
script.on_init(function()
for _, surface in pairs(game.surfaces) do
remove_ores_on_Nauvis(surface, resources_to_remove, nil)
end
end)
script.on_event(defines.events.on_chunk_generated, function(event)
remove_ores_on_Nauvis(event.surface, resources_to_remove, event.area)
end)