computer craft mining turtle -- Turtle inventory should be 4 by 4 -- A chest or an inventory should be present at the left of the starting position -- The block layer at the turtle's level should be clear, fully digged for the defined mining zone -- Fuel should be on the lower right slot -- Any well-sealing block should be on slot 15, left of the fuel -- Blocks not to be mined should be on the first line -- Define the mining zone here MaxForward = 16 MaxRight = 16 -- Number of holes to skip (beginning) computer craft mining turtle PasteShr computer craft mining turtle SkipHoles = 0 local pos = {0, 0, 0} local facing = 0 local curMessage = '' function tWrite(txt) term.clear() term.setCursorPos(1, 1) if txt then term.write(txt) computer craft mining turtle PasteShr computer craft mining turtle else term.write(curMessage) end end function turnRight(n) n = n or 1 while n > 0 do n = n - 1 facing = (facing + 1) % 4 computer craft mining turtle PasteShr computer craft mining turtle turtle.turnRight() end end function turnLeft(n) n = n or 1 while n > 0 do n = n - 1 facing = (facing - 1) % 4 computer craft mining turtle How to use it? computer craft mining turtle turtle.turnLeft() end end function right(n) n = n or 1 checkFuel(n) if facing == 0 then turnRight() computer craft mining turtle How to get it? computer craft mining turtle while n > 0 do if turtle.forward() then n = n - 1 pos[1] = pos[1] + 1 end end elseif facing == 1 then while n > 0 do if turtle.forward() then n = n - 1 computer craft mining turtle How to dowload it? computer craft mining turtle pos[1] = pos[1] + 1 end end elseif facing == 2 then turnLeft() while n > 0 do if turtle.forward() then n = n - 1 pos[1] = pos[1] + 1 end computer craft mining turtle How to dowload it? computer craft mining turtle end else while n > 0 do if turtle.back() then n = n - 1 pos[1] = pos[1] + 1 end end end end computer craft mining turtle How to use it? computer craft mining turtle function left(n) n = n or 1 checkFuel(n) if facing == 0 then turnLeft() while n > 0 do if turtle.forward() then n = n - 1 computer craft mining turtle How to dowload it? computer craft mining turtle pos[1] = pos[1] - 1 end end elseif facing == 1 then while n > 0 do if turtle.back() then n = n - 1 pos[1] = pos[1] - 1 end end computer craft mining turtle How to use it? computer craft mining turtle elseif facing == 2 then turnRight() while n > 0 do if turtle.forward() then n = n - 1 pos[1] = pos[1] - 1 end end else while n > 0 do computer craft mining turtle PasteShr computer craft mining turtle if turtle.forward() then n = n - 1 pos[1] = pos[1] - 1 end end end end function forward(n) n = n or 1 computer craft mining turtle How to get it for free? computer craft mining turtle checkFuel(n) if facing == 0 then while n > 0 do if turtle.forward() then n = n - 1 pos[2] = pos[2] + 1 end end elseif facing == 1 then computer craft mining turtle How to dowload it? computer craft mining turtle turnLeft() while n > 0 do if turtle.forward() then n = n - 1 pos[2] = pos[2] + 1 end end elseif facing == 2 then while n > 0 do if turtle.back() then computer craft mining turtle How to use it? computer craft mining turtle n = n - 1 pos[2] = pos[2] + 1 end end else turnRight() while n > 0 do if turtle.forward() then n = n - 1 pos[2] = pos[2] + 1 computer craft mining turtle PasteShr computer craft mining turtle end end end end function backward(n) n = n or 1 checkFuel(n) if facing == 0 then computer craft mining turtle How to get it for free? computer craft mining turtle while n > 0 do if turtle.back() then n = n - 1 pos[2] = pos[2] - 1 end end elseif facing == 1 then turnRight() while n > 0 do if turtle.forward() then computer craft mining turtle PasteShr computer craft mining turtle n = n - 1 pos[2] = pos[2] - 1 end end elseif facing == 2 then while n > 0 do if turtle.forward() then n = n - 1 pos[2] = pos[2] - 1 end computer craft mining turtle PasteShr computer craft mining turtle end else turnLeft() while n > 0 do if turtle.forward() then n = n - 1 pos[2] = pos[2] - 1 end end end computer craft mining turtle How to use it? computer craft mining turtle end function up(n) n = n or 1 checkFuel(n) while n > 0 do if turtle.up() then n = n - 1 pos[3] = pos[3] + 1 computer craft mining turtle How to dowload it? computer craft mining turtle end end end function down(n) n = n or 1 checkFuel(n) while n > 0 do if turtle.down() then computer craft mining turtle How to use it? computer craft mining turtle n = n - 1 pos[3] = pos[3] - 1 end end end function getTo(nPos) if not nPos[1] then nPos[1] = pos[1] end if not nPos[2] then nPos[2] = pos[2] end if not nPos[3] then nPos[3] = pos[3] end computer craft mining turtle How to get it for free? computer craft mining turtle diff = {nPos[1] - pos[1], nPos[2] - pos[2], nPos[3] - pos[3]} -- Right / left if diff[1] > 0 then right(diff[1]) elseif diff[1] < 0 then left(-diff[1]) end -- Forward / backward if diff[2] > 0 then forward(diff[2]) elseif diff[2] < 0 then backward(-diff[2]) computer craft mining turtle How to dowload it? computer craft mining turtle end -- Up / down if diff[3] > 0 then up(diff[3]) elseif diff[3] < 0 then down(-diff[3]) end end function checkFuel(n) if turtle.getFuelLevel() < n then computer craft mining turtle How to get it? computer craft mining turtle tWrite('Refueling...') turtle.select(16) while turtle.getFuelLevel() < n do turtle.refuel(1) end tWrite() end end computer craft mining turtle How to dowload it? computer craft mining turtle function startingPoint(row) return (2 * (row-1)) % 5 + 1 end function ascend() curMessage = 'Ascending...' tWrite() while pos[3] < 0 do computer craft mining turtle How to dowload it? computer craft mining turtle if turtle.detectUp() then turtle.digUp() end up() end turtle.select(15) turtle.placeDown() tWrite() end computer craft mining turtle How to get it? computer craft mining turtle function drillSides() for i = 0, 3, 1 do local canDig = true for j = 1, 4, 1 do turtle.select(j) if turtle.compare() then canDig = false end end if canDig then turtle.dig() end computer craft mining turtle How to get it? computer craft mining turtle if i ~=3 then turnLeft() end end end function drill() curMessage = 'Drilling...' tWrite() while (not turtle.detectDown()) or (turtle.detectDown() and turtle.digDown()) do down() computer craft mining turtle How to get it for free? computer craft mining turtle drillSides() end ascend() tWrite() end function drillRow(row) getTo({row, startingPoint(row)}) computer craft mining turtle How to dowload it? computer craft mining turtle local willMove = 0 while (pos[2] + willMove) <= (MaxForward - 2) do emptyInventory() if willMove == 0 then willMove = 5 else forward(willMove) end computer craft mining turtle How to get it for free? computer craft mining turtle if SkipHoles == 0 then drill() else SkipHoles = SkipHoles - 1 end end end function emptyInventory() curMessage = 'Emptying inventory...' tWrite() computer craft mining turtle How to use it? computer craft mining turtle local curPos = {pos[1], pos[2]} getTo({0,0}) while facing ~= 3 do turnRight() end for i = 5, 14, 1 do turtle.select(i) turtle.drop() computer craft mining turtle How to use it? computer craft mining turtle end getTo(curPos) tWrite() end tWrite('Initializing...') for i = 1, MaxRight - 2, 1 do computer craft mining turtle How to get it for free? computer craft mining turtle drillRow(i) end tWrite('Ended') computer craft mining turtle