Code: Select all
local earthResource = table.deepcopy(data.raw["resource"]["stone"]);
earthResource.name = "earth";
earthResource.minable.result = nil;
earthResource.infinite = true;
earthResource.minimum = 1;
earthResource.minable.results = {{
    name = "earth",
    probability = 0.9,
    amount = 1
}, {
    name = "stone",
    probability = 0.09,
    amount = 1
}, {
    name = "silver",
    probability = 0.009,
    amount = 1
}, {
    name = "gold",
    probability = 0.001,
    amount = 1
}};
earthResource.autoplace = nil;Code: Select all
-- Iterate over every tile in the new chunk and spam with random resources, if empty and possible.
script.on_event(defines.events.on_chunk_generated, function(event)
    for x = event.area.left_top.x + 0, event.area.right_bottom.x - 1 do
        for y = event.area.left_top.y + 0, event.area.right_bottom.y - 1 do
            local resources = event.surface.count_entities_filtered({
                position = {x, y},
                radius = 1,
                type = "resource",
                limit = 1
            })
            log(serpent.block(resources))
            if resources == 0 then
                event.surface.create_entity({
                    name = "earth",
                    amount = 1,
                    position = {x, y}
                })
            end
        end
    end
end)
