sCCripts/jlib/mine.lua

33 lines
628 B
Lua
Raw Normal View History

2020-12-28 14:45:50 +01:00
-- Created by Jef Roosens
local module = {}
module.logger = require("jlib.log").Logger:new{level = -1}
-- Safely dig in given direction (aka account for falling blocks)
--
-- @param dir direction to dig (f, u, d)
-- @return amount of blocks it broke
function module.dig(dir)
local funcs = {
f = { turtle.detect, turtle.dig },
u = { turtle.detectUp, turtle.digUp },
d = { turtle.detectDown, turtle.digDown }
}
local i = 0
while funcs[dir][1]() do
funcs[dir][2]()
i = i + 1
end
module.logger:info("Mined " .. i .. " blocks")
return i
end
return module