1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-24 03:49:35 +02:00
RedMew/map_gen/shared/restrict_landfill_tile.lua
RedRafe 26e1c28dc0
Factorio 2.0 update (#1436)
* Init Factorio 2.0 update

* add credits

* fix test module

* I know luackeck, I know

* Fixes

* Fix bad event.player_index handling

* Hotfixes

* Remove all filter inserters

* Migrate removed items

* Deprecating spidertron control and landfill features
2024-10-22 20:22:35 +01:00

45 lines
1.0 KiB
Lua

local Event = require 'utils.event'
storage.allowed_landfill_tiles = {}
Event.add(
defines.events.on_player_built_tile,
function(event)
local item = event.item
if not item then
return
end
local item_name = item.name
if item_name ~= 'landfill' then
return
end
local allowed = storage.allowed_landfill_tiles
local new_tiles = {}
for _, tile in ipairs(event.tiles) do
local name = tile.old_tile.name
if not allowed[name] then
tile.name = name
table.insert(new_tiles, tile)
end
end
local count = #new_tiles
if count == 0 then
return
end
local surface = game.surfaces[event.surface_index]
surface.set_tiles(new_tiles)
local player = game.get_player(event.player_index)
player.insert {name = item_name, count = count}
end
)
return function(allowed_set)
storage.allowed_landfill_tiles = allowed_set
end