-
Notifications
You must be signed in to change notification settings - Fork 1
/
undecorator.lua
52 lines (44 loc) · 1.61 KB
/
undecorator.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--Undecorator
--A 3Ra Gaming creation
--removes decorations on the map to reduce stress on players computers
local CHUNK_SIZE = 32
-- Remove decorations in a given area
-- @param surface target surface
-- @param area area to clear decorations within
local function removeDecorationsArea(surface, area)
for _, entity in pairs(surface.find_entities_filtered { area = area, type = "decorative" }) do
entity.destroy()
end
end
--this fires whenever new chunks are generated.
Event.register(defines.events.on_chunk_generated, function(event)
removeDecorationsArea(event.surface, event.area)
end)
--the rest only triggers if they've never been removed before on whichever map is loaded.
-- Clean parameters for removeDecorationsArea function
-- @param surface target surface
-- @param x bottom left x coordinate
-- @param y bottom left y coordinate
-- @param width width of area
-- @param height height of area
local function removeDecorations(surface, x, y, width, height)
removeDecorationsArea(surface, { { x, y }, { x + width, y + height } })
end
-- Clear all decorations on the map.
local function clearDecorations()
local surface = game.surfaces["nauvis"]
for chunk in surface.get_chunks() do
removeDecorations(surface, chunk.x * CHUNK_SIZE, chunk.y * CHUNK_SIZE, CHUNK_SIZE - 1, CHUNK_SIZE - 1)
end
game.print("Decorations removed")
end
-- If the map hasn't been scanned already, clear it
-- @param event on_tick event
function full_clear(event)
if not global.fullClear then
clearDecorations()
global.fullClear = true
end
Event.remove(defines.events.on_tick, full_clear)
end
Event.register(defines.events.on_tick, full_clear)