Hello!
I am loving the dynamic rain mod, it's great. Thank you for writing it. :D
I was hoping you could expose a handler I could register to when a rainstorm cleans up all the pollution in a chunk. I've got a treez mod with a tree planting mechanic that is trying to detect if the rain cleans up the pollution in a chunk so it can figure out if it can/should plant a seed in a purified chunk. Right now I'm checking when a rainstorm is going and what the pollution values are (and if any hit zero) during the rain-storm as an indirect proxy for a handler. My hope is to be considerate of server load so having a direct handler/detection method would be useful. Please let me know what you think,
Sudain
Suggested code:
events.lua:
-- Shared event definitions. Required by both control.lua and pollution.lua
-- so the ID is created exactly once and is consistent across both files.
return {
on_chunk_pollution_cleared = script.generate_event_name(),
}
--==--
pollution.lua
local events = require("events")
-- ...inside M.on_tick, replace the existing pollute block with:
if current > 0 then
local removed = math.min(current, cfg.rain_pollution_cleanup_cap)
if removed > 0 then
surface.pollute(pos, -removed, "dynamic-rain-pollution-cleaner")
-- If removed == current, this call brought the chunk to exactly zero.
if removed == current then
script.raise_event(events.on_chunk_pollution_cleared, {
surface_index = surface.index,
chunk_position = { x = chunk.x, y = chunk.y },
})
end
end
end
--==--
control.lua
local events = require("events")
remote.add_interface("dynamic-rain", {
is_raining = function(surface_index) ... end, -- existing, unchanged
time_left = function(surface_index) ... end, -- existing, unchanged
is_sunshower = function(surface_index) ... end, -- existing, unchanged
-- New: other mods call this to get the event ID, then use script.on_event()
get_events = function()
return { on_chunk_pollution_cleared = events.on_chunk_pollution_cleared }
end,
})