mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-02-15 13:53:13 +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)
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -68,8 +73,10 @@ local function player_build_tile(event)
|
|||||||
|
|
||||||
local tiles = event.tiles
|
local tiles = event.tiles
|
||||||
local count = 0
|
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
|
tile_data.name = replace_tile
|
||||||
|
|
||||||
if tile_data.old_tile.name == replace_tile then
|
if tile_data.old_tile.name == replace_tile then
|
||||||
count = count + 1
|
count = count + 1
|
||||||
end
|
end
|
||||||
|
@ -8,15 +8,16 @@ Event.add(
|
|||||||
defines.events.on_player_built_tile,
|
defines.events.on_player_built_tile,
|
||||||
function(event)
|
function(event)
|
||||||
local item = event.item
|
local item = event.item
|
||||||
if not item or not item.valid then
|
if not item then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if event.item.name == 'landfill' then
|
if item.name == 'landfill' then
|
||||||
local tiles = event.tiles
|
local tiles = event.tiles
|
||||||
for i = 1, #tiles do
|
for i = 1, #tiles do
|
||||||
tiles[i].name = replacement_tiles[random(1, tile_count)]
|
tiles[i].name = replacement_tiles[random(1, tile_count)]
|
||||||
end
|
end
|
||||||
|
|
||||||
local surface = game.surfaces[event.surface_index]
|
local surface = game.surfaces[event.surface_index]
|
||||||
surface.set_tiles(tiles)
|
surface.set_tiles(tiles)
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,12 @@ global.allowed_landfill_tiles = {}
|
|||||||
Event.add(
|
Event.add(
|
||||||
defines.events.on_player_built_tile,
|
defines.events.on_player_built_tile,
|
||||||
function(event)
|
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
|
if item_name ~= 'landfill' then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user