require "defines" function startOffshoreDumps(event) -- Work around the "onload" event triggering when a save occurs. if global.startedOffshoreDumps == nil then global.offshoreDumps = {} global.startedOffshoreDumps = true end end function stepOffshoreDumps(event) for offshoreDump, magicFurnace in pairs(global.offshoreDumps) do -- Work around the lack of a proper stop event. if not offshoreDump.valid then if magicFurnace.valid then -- Also remove the invisible furnace from the game. magicFurnace.destroy() end global.offshoreDumps[offshoreDump] = nil end -- If all is well then we can just do our thing. if offshoreDump.valid and magicFurnace.valid then -- The game will set the fluidbox property to nil if there is no fluid in it anymore. if offshoreDump.fluidbox[1] ~= nil then -- Decrease the amount of fluid at a rate similar to the offshore pump. We have to -- completely replace the table, adjusting only the amount value has no effect. local fluid = { type = offshoreDump.fluidbox[1].type, amount = offshoreDump.fluidbox[1].amount, temperature = offshoreDump.fluidbox[1].temperature } fluid.amount = fluid.amount - 1 if fluid.amount < 0 then fluid.amount = 0 end offshoreDump.fluidbox[1] = fluid -- Produce pollution if the amount of a fluid other than water is being decreased -- by running an invisible furnace. if fluid.type ~= "water" then -- Make sure there is iron ore in the furnace, otherwise no pollution will be -- produced. local sourceInventory = magicFurnace.get_inventory(2) local ironOreCount = sourceInventory.get_item_count("iron-ore") if ironOreCount < 1 then sourceInventory.insert({ name = "iron-ore", count = 1 }) end end end -- Make sure there is always fuel in the furnace, otherwise an out-of-fuel icon will -- be shown. local fuelInventory = magicFurnace.get_inventory(1) local coalCount = fuelInventory.get_item_count("coal") if coalCount < 1 then fuelInventory.insert({ name = "coal", count = 1 }) end -- Make sure there is never iron in the furnace, otherwise it will become backed up. local resultInventory = magicFurnace.get_inventory(3) local ironCount = resultInventory.get_item_count("iron-plate") if ironCount > 0 then resultInventory.remove({ name = "iron-plate", count = ironCount }) end end end end function startOffshoreDump(event) local entity = event.created_entity if event.created_entity.name == "offshore-dump" then -- Place an invisible furnace on top of the entity. local magicFurnace = game.get_surface("nauvis").create_entity({ name = "magic-furnace", position = event.created_entity.position }) -- Remember the entity and the furnace together. global.offshoreDumps[entity] = magicFurnace end end script.on_init(startOffshoreDumps) script.on_load(startOffshoreDumps) script.on_event(defines.events.on_tick, stepOffshoreDumps) script.on_event(defines.events.on_built_entity, startOffshoreDump) script.on_event(defines.events.on_robot_built_entity, startOffshoreDump)