Regenerate Resources Help

Place to get help with not working mods / modding interface.
User avatar
louanbastos
Burner Inserter
Burner Inserter
Posts: 9
Joined: Tue Dec 24, 2024 9:31 pm
Contact:

Regenerate Resources Help

Post by louanbastos »

I want to implement this code in my mod. The main issue is that I'm having a problem. Even using just the command, using it on large maps (approximately 15,100 generated chunks) causes the screen to freeze for a while. Despite this, the code works normally.

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
eugenekay
Filter Inserter
Filter Inserter
Posts: 577
Joined: Tue May 15, 2018 2:14 am
Contact:

Re: Regenerate Resources Help

Post by eugenekay »

LuaSurface.find_entities_filtered will accept an Area filter, which will permit you to run this code against a smaller subset of Chunks. You will need to run it multiple times to cover the entire map.

Good Luck!
Post Reply

Return to “Modding help”