1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-19 21:10:19 +02:00
ComfyFactorio/modules/ores_are_mixed.lua

43 lines
1.2 KiB
Lua
Raw Normal View History

2021-03-24 20:14:55 +01:00
local Event = require 'utils.event'
local simplex_noise = require 'utils.math.simplex_noise'.d2
2024-11-14 21:52:30 +01:00
local Public = {}
2019-05-10 12:57:30 +02:00
local ore_raffle = {
2021-03-24 16:46:00 +01:00
'iron-ore',
'iron-ore',
'iron-ore',
'copper-ore',
'copper-ore',
'coal',
'stone'
2019-05-10 12:57:30 +02:00
}
2024-11-14 21:52:30 +01:00
Public.settings = {
mixed_ores_on_nauvis_only = false
}
2019-05-10 12:57:30 +02:00
local function on_chunk_generated(event)
2021-03-24 16:46:00 +01:00
local surface = event.surface
2024-11-14 21:52:30 +01:00
if Public.settings.mixed_ores_on_nauvis_only and surface.name ~= 'nauvis' then
return
end
local ores = surface.find_entities_filtered({ area = event.area, name = { 'iron-ore', 'copper-ore', 'coal', 'stone' } })
2021-03-24 16:46:00 +01:00
if #ores == 0 then
return
end
local seed = game.surfaces[1].map_gen_settings.seed
for _, ore in pairs(ores) do
local pos = ore.position
local noise =
simplex_noise(pos.x * 0.005, pos.y * 0.005, seed) + simplex_noise(pos.x * 0.01, pos.y * 0.01, seed) * 0.3 + simplex_noise(pos.x * 0.05, pos.y * 0.05, seed) * 0.2
local i = (math.floor(noise * 100) % 7) + 1
2024-11-14 21:52:30 +01:00
surface.create_entity({ name = ore_raffle[i], position = ore.position, amount = ore.amount })
2021-03-24 16:46:00 +01:00
ore.destroy()
end
2019-05-10 12:57:30 +02:00
end
2021-03-24 20:14:55 +01:00
Event.add(defines.events.on_chunk_generated, on_chunk_generated)
2024-11-14 21:52:30 +01:00
return Public