Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x, y, z, f = 0, 0, 0, 0
- local breaks = 0
- local returning = false
- local template = {"log", "leaves"}
- function checkFuel(flag)
- if not flag then
- local fuel = turtle.getFuelLevel()
- local distance = math.abs(x) + math.abs(y) + math.abs(z)
- if fuel-1 <= distance then
- home()
- error("Alert: Fuel level critical. Returning to home point...")
- end
- end
- end
- function forward(num)
- num = num or 1
- for i = 1, num do
- if turtle.forward() then
- if f == 0 then
- x = x + 1
- elseif f == 1 then
- z = z + 1
- elseif f == 2 then
- x = x - 1
- elseif f == 3 then
- z = z - 1
- end
- checkFuel(returning)
- else
- return false
- end
- end
- return true
- end
- function back(num)
- num = num or 1
- for i = 1, num do
- if turtle.back() then
- if f == 0 then
- x = x - 1
- elseif f == 1 then
- z = z - 1
- elseif f == 2 then
- x = x + 1
- elseif f == 3 then
- z = z + 1
- end
- checkFuel(returning)
- else
- return false
- end
- end
- return true
- end
- function up(num)
- num = num or 1
- for i = 1, num do
- if turtle.up() then
- y = y + 1
- checkFuel(returning)
- else
- return false
- end
- end
- return true
- end
- function down(num)
- num = num or 1
- for i = 1, num do
- if turtle.down() then
- y = y - 1
- checkFuel(returning)
- else
- return false
- end
- end
- return true
- end
- function left(num)
- num = num or 1
- for i = 1, num do
- turtle.turnLeft()
- f = (f+3)%4
- end
- end
- function right(num)
- num = num or 1
- for i = 1, num do
- turtle.turnRight()
- f = (f+1)%4
- end
- end
- function home()
- returning = true
- while y ~= 0 do
- if y < 0 then
- turtle.digUp()
- up()
- elseif y > 0 then
- turtle.digDown()
- down()
- end
- end
- if z > 0 then
- while f ~= 3 do
- left()
- end
- elseif z < 0 then
- while f ~= 1 do
- left()
- end
- end
- while z ~= 0 do
- forward()
- end
- if x > 0 then
- while f ~= 2 do
- left()
- end
- elseif x < 0 then
- while f ~= 0 do
- left()
- end
- end
- while x ~= 0 do
- forward()
- end
- end
- function log(data)
- local h = fs.open("log", "w")
- if type(data) == "string" then
- h.writeLine(data)
- elseif type(data) == "table" then
- for i = 1, #data do
- h.writeLine(data[i])
- end
- end
- h.close()
- end
- function surface()
- while down() do
- end
- end
- function bottom()
- turtle.digDown()
- while down() do
- turtle.digDown()
- end
- end
- function scan(tStr)
- local s,d = turtle.inspect()
- if s then
- for i = 1, #tStr do
- if string.find(d.name, tStr[i]) then
- return true
- end
- end
- return false
- end
- return false
- end
- function scanUp(tStr)
- local s,d = turtle.inspectUp()
- if s then
- for i = 1, #tStr do
- if string.find(d.name, tStr[i]) then
- return true
- end
- end
- return false
- end
- return false
- end
- function scanDown(tStr)
- local s,d = turtle.inspectDown()
- if s then
- for i = 1, #tStr do
- if string.find(d.name, tStr[i]) then
- return true
- end
- end
- return false
- end
- return false
- end
- function mineVein(tStr)
- breaks = breaks + 1
- if breaks == 200 then
- home()
- error("reached block limit")
- end
- if scan(tStr) then
- turtle.dig()
- forward()
- mineVein(tStr)
- back()
- end
- left()
- if scan(tStr) then
- turtle.dig()
- forward()
- mineVein(tStr)
- back()
- end
- right(2)
- if scan(tStr) then
- turtle.dig()
- forward()
- mineVein(tStr)
- back()
- end
- left()
- if scanUp(tStr) then
- turtle.digUp()
- up()
- mineVein(tStr)
- down()
- end
- if scanDown(tStr) then
- turtle.digDown()
- down()
- mineVein(tStr)
- up()
- end
- end
- function drillDown(num)
- for i = 1, num do
- turtle.digDown()
- if not down() then
- break
- end
- end
- end
- function stripMine(length, strips)
- for i = 1, strips do
- for i = 1, length do
- turtle.dig()
- forward()
- mineVein(template)
- end
- left((i%2)*2+1)
- for i = 1, 3 do
- turtle.dig()
- forward()
- mineVein(template)
- end
- left((i%2)*2+1)
- end
- end
- function coast(num)
- for i = 1, num do
- while not forward() do
- turtle.digUp()
- up()
- end
- surface()
- mineVein(template)
- end
- end
- ------------------------Actual Program------------------------
- mineVein(template)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement