1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-14 10:13:13 +02:00
RedMew/map_gen/misc/danger_ore_banned_entities.lua

68 lines
1.7 KiB
Lua
Raw Normal View History

2018-08-07 01:14:54 +02:00
local Event = require 'utils.event'
2018-09-23 00:25:13 +02:00
local Game = require 'utils.game'
2018-08-07 01:14:54 +02:00
2018-08-07 13:28:57 +02:00
global.allowed_entites = {
2018-08-07 01:14:54 +02:00
['transport-belt'] = true,
['fast-transport-belt'] = true,
['express-transport-belt'] = true,
['underground-belt'] = true,
['fast-underground-belt'] = true,
['express-underground-belt'] = true,
['small-electric-pole'] = true,
['medium-electric-pole'] = true,
['big-electric-pole'] = true,
['substation'] = true,
['electric-mining-drill'] = true,
['burner-mining-drill'] = true,
2018-08-07 13:28:57 +02:00
['pumpjack'] = true
2018-08-07 01:14:54 +02:00
}
Event.add(
defines.events.on_built_entity,
function(event)
local entity = event.created_entity
if not entity or not entity.valid then
return
end
local name = entity.name
2018-08-08 13:04:59 +02:00
if name == 'tile-ghost' then
return
end
2018-08-07 01:14:54 +02:00
local ghost = false
if name == 'entity-ghost' then
name = entity.ghost_name
ghost = true
end
2018-08-07 13:28:57 +02:00
if global.allowed_entites[name] then
2018-08-07 01:14:54 +02:00
return
end
2018-08-08 01:07:27 +02:00
-- Some entities have a bounding_box area of zero, eg robots.
local area = entity.bounding_box
local left_top, right_bottom = area.left_top, area.right_bottom
if left_top.x == right_bottom.x and left_top.y == right_bottom.y then
return
end
local count = entity.surface.count_entities_filtered {area = area, type = 'resource', limit = 1}
2018-08-07 01:14:54 +02:00
if count == 0 then
return
end
local p = Game.get_player_by_index(event.player_index)
2018-08-07 01:14:54 +02:00
if not p or not p.valid then
return
end
entity.destroy()
if not ghost then
2018-08-08 01:07:27 +02:00
p.insert(event.stack)
2018-08-07 01:14:54 +02:00
end
end
)