os.loadAPI("apis/storage") local db = storage local t = turtle blacklist = {} local function blacklisted (what) for _, b in ipairs(blacklist) do if string.match(what, b) then return true end end return false end -- FIXME leaves block below obstruction local dugUp = db.get("dugup") or 0 local function digAround () dugUp = dugUp + 1 t.up() db.set("dugup", dugUp) return t.dig() end function hook () if t.digsafe then return false end t.digsafe = { ["digUp"] = t.digUp, ["dig"] = t.dig, ["digDown"] = t.digDown } t.digUp = function () local x, y = t.inspectUp() if not x then return false end if blacklisted(y["name"]) then return false end return t.digsafe.digUp() end t.digDown = function () local x, y = t.inspectDown() if not x then return false end if blacklisted(y["name"]) then return false end if 0 ~= dugUp and t.digsafe.digDown() then print("previously dug up " .. dugUp .. " times, digging back down.") t.down() dugUp = dugUp - 1 db.set("dugup", dugUp) return t.digDown() end return t.digsafe.digDown() end t.dig = function () local x, y = t.inspect() if not x then return false end if blacklisted(y["name"]) then print("digging around blacklisted block " .. y["name"]) return digAround() end return t.digsafe.dig() end return true end