From ab4339a87dcd7eee336afc9b457d49abb46716a1 Mon Sep 17 00:00:00 2001 From: Wyrrrd Date: Sat, 22 Feb 2020 04:11:21 +0100 Subject: [PATCH] Added missing entity check --- changelog.txt | 6 ++++++ control.lua | 25 ++++++++++++++----------- info.json | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/changelog.txt b/changelog.txt index 7ac0ab6..0f127c1 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,10 @@ --------------------------------------------------------------------------------------------------- +Version: 0.18.1 +Date: 22. 2. 2020 + Bug: + - Added missing entity check + (caused game crash on inserter placement without adjacent entity) +--------------------------------------------------------------------------------------------------- Version: 0.18.0 Date: 22. 2. 2020 Changes: diff --git a/control.lua b/control.lua index 3fff0c9..6e9d844 100644 --- a/control.lua +++ b/control.lua @@ -13,7 +13,7 @@ end local function get_items_by_filter(inserter,inventory) local items = {} - for slot = 1,#inventory,1 do + for slot = 1,#inventory do if #items < inserter.filter_slot_count and inventory.get_filter(slot) then items[#items+1] = inventory.get_filter(slot) end @@ -24,16 +24,19 @@ end local function on_built_entity(event) local inserter = event.created_entity if inserter.filter_slot_count then - local inventory = inserter.surface.find_entities_filtered({position = inserter.pickup_position, limit = 1})[1].get_output_inventory() - if inventory then - local mode = game.players[event.player_index].mod_settings["Autofilter_Mode"].value - if mode == "content" and not inventory.is_empty() then - for slot,item in pairs(get_items_by_content(inserter,inventory)) do - inserter.set_filter(slot,item) - end - elseif mode == "filter" and inventory.is_filtered() then - for slot,item in pairs(get_items_by_filter(inserter,inventory)) do - inserter.set_filter(slot,item) + local pickup = inserter.surface.find_entities_filtered({position = inserter.pickup_position, limit = 1}) + if #pickup > 0 then + local inventory = pickup[1].get_output_inventory() + if inventory then + local mode = game.players[event.player_index].mod_settings["Autofilter_Mode"].value + if mode == "content" and not inventory.is_empty() then + for slot,item in pairs(get_items_by_content(inserter,inventory)) do + inserter.set_filter(slot,item) + end + elseif mode == "filter" and inventory.is_filtered() then + for slot,item in pairs(get_items_by_filter(inserter,inventory)) do + inserter.set_filter(slot,item) + end end end end diff --git a/info.json b/info.json index ab38230..5eb9b4d 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "Autofilter", - "version": "0.18.0", + "version": "0.18.1", "title": "Autofilter", "author": "Wyrrrd", "dependencies": ["base >= 0.18.0"],