mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-02-09 13:37:05 +02:00
Fix for possible nil item in on_player_built_tile
This commit is contained in:
parent
76871eefbf
commit
6fab882c2f
@ -52,7 +52,12 @@ Global.register(
|
||||
)
|
||||
|
||||
local function player_build_tile(event)
|
||||
if event.item.name ~= brush_tool then
|
||||
local item = event.item
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
if item.name ~= brush_tool then
|
||||
return
|
||||
end
|
||||
|
||||
@ -68,8 +73,10 @@ local function player_build_tile(event)
|
||||
|
||||
local tiles = event.tiles
|
||||
local count = 0
|
||||
for _, tile_data in ipairs(tiles) do
|
||||
for i = 1, #tiles do
|
||||
local tile_data = tiles[i]
|
||||
tile_data.name = replace_tile
|
||||
|
||||
if tile_data.old_tile.name == replace_tile then
|
||||
count = count + 1
|
||||
end
|
||||
|
@ -8,15 +8,16 @@ Event.add(
|
||||
defines.events.on_player_built_tile,
|
||||
function(event)
|
||||
local item = event.item
|
||||
if not item or not item.valid then
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
if event.item.name == 'landfill' then
|
||||
if item.name == 'landfill' then
|
||||
local tiles = event.tiles
|
||||
for i = 1, #tiles do
|
||||
tiles[i].name = replacement_tiles[random(1, tile_count)]
|
||||
end
|
||||
|
||||
local surface = game.surfaces[event.surface_index]
|
||||
surface.set_tiles(tiles)
|
||||
end
|
||||
|
@ -6,7 +6,12 @@ global.allowed_landfill_tiles = {}
|
||||
Event.add(
|
||||
defines.events.on_player_built_tile,
|
||||
function(event)
|
||||
local item_name = event.item.name
|
||||
local item = event.item
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
local item_name = item.name
|
||||
if item_name ~= 'landfill' then
|
||||
return
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user