From 5ed50dcfb376012c42e425f0317f7d8d6c3d3a56 Mon Sep 17 00:00:00 2001 From: Wyrrrd Date: Sun, 23 Feb 2020 15:17:15 +0100 Subject: [PATCH] Added entity type check Apparently event filters are not applied to mod-raised events --- changelog.txt | 8 ++++++++ control.lua | 28 +++++++++++++++------------- info.json | 7 ++----- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/changelog.txt b/changelog.txt index 48cc0c4..a31c1ab 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,12 @@ --------------------------------------------------------------------------------------------------- +Version: 0.18.4 +Date: 23. 2. 2020 + Changes: + - Removed incompatibility with Upgrade Builder and Planner (see Bugfixes) + + Bugfixes: + - Added additional check for entity type, since event filters are not applied to mod-raised events +--------------------------------------------------------------------------------------------------- Version: 0.18.3 Date: 23. 2. 2020 Changes: diff --git a/control.lua b/control.lua index 6955058..aff2c44 100644 --- a/control.lua +++ b/control.lua @@ -23,19 +23,21 @@ end local function on_built_entity(event) local inserter = event.created_entity - if inserter.filter_slot_count then - 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) + if inserter.type == "inserter" then + if inserter.filter_slot_count then + 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 1cd7ff2..2276252 100644 --- a/info.json +++ b/info.json @@ -1,12 +1,9 @@ { "name": "Autofilter", - "version": "0.18.3", + "version": "0.18.4", "title": "Autofilter", "author": "Wyrrrd", - "dependencies": [ - "base >= 0.18.0", - "!upgrade-planner-next" - ], + "dependencies": ["base >= 0.18.0"], "description": "Automatically set inserter filters based on adjacent inventory.", "factorio_version": "0.18" } \ No newline at end of file