From 3cfd54b11e3a4c72b75d0176cf1c451685bc56eb Mon Sep 17 00:00:00 2001 From: Valansch Date: Wed, 4 Oct 2017 01:51:42 +0200 Subject: [PATCH] Fixed pumpjack deconstruction and miners not deconstructing next to wells --- autodeconstruct.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/autodeconstruct.lua b/autodeconstruct.lua index 4e3e3e0d..ac3cbfb7 100644 --- a/autodeconstruct.lua +++ b/autodeconstruct.lua @@ -5,9 +5,15 @@ local function is_depleted(drill) if drill.name == "electric-mining-drill" then area = {{position.x - 2, position.y - 2},{position.x + 2, position.y + 2}} else - area = {{position.x - 1, position.y - 1},{position.x + 1, position.y + 1}} + area = {{position.x - 1, position.y - 1},{position.x + 1, position.y + 1}} end - return #drill.surface.find_entities_filtered{type="resource", area = area} == 1 + local count = -1 + for _,resource in pairs(drill.surface.find_entities_filtered{type="resource", area = area}) do + if resource.name ~= "crude-oil" then + count = count + 1 + end + end + return count == 0 end local function mark_if_depleted(drill) @@ -20,7 +26,9 @@ local function on_resource_depleted(event) local area = {{event.entity.position.x-1, event.entity.position.y-1}, {event.entity.position.x+1, event.entity.position.y + 1}} local drills = event.entity.surface.find_entities_filtered{area = area, type="mining-drill"} for _,drill in pairs(drills) do - mark_if_depleted(drill) + if drill.name ~= "pumpjack" then + mark_if_depleted(drill) + end end end