_Jacques

Quarry

Jul 18th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cPrint(str)
  2.     term.clear()
  3.     term.setCursorPos(1,1)
  4.     print(str)
  5. end
  6.  
  7. cPrint('starting up quarry!')
  8. os.sleep(1)
  9. cPrint('')
  10.  
  11. os.loadAPI('nav.lua')
  12. nav.calibrate()
  13.  
  14. function goBack(functionCalled)
  15.     initx, inity, initz, initDir = nav.pos.x, nav.pos.y, nav.pos.z, nav.pos.dir
  16.     if nav.pos.z ~= 0 then
  17.         nav.up(math.abs(nav.pos.z))
  18.     end
  19.     nav.goDir(2)
  20.     if nav.pos.y ~= 0 then
  21.         nav.forward(math.abs(nav.pos.y))
  22.     end
  23.     if nav.pos.x ~= 0 then
  24.         if nav.pos.x < 0 then
  25.             nav.goDir(1)
  26.             nav.forward(math.abs(nav.pos.x))
  27.         else
  28.             nav.goDir(3)
  29.             nav.forward(math.abs(nav.pos.x)
  30.         end
  31.     end
  32.     functionCalled()
  33.     nav.turnRight(2)
  34.     nav.forward(inity)
  35.     if initx/math.abs(initx) = -1 do
  36.         nav.turnLeft(1)
  37.     elseif initx/math.abs(initx) = 1 do
  38.         nav.turnRight(1)
  39.     end
  40.     if initx ~= 0 then
  41.         nav.forward(math.abs(initx))
  42.     end
  43.     nav.down(initz)
  44.     nav.goDir(initDir)
  45. end
  46.  
  47. function refuel()
  48.     if turtle.getFuelLevel() < 2*(math.abs(nav.pos.z) + math.abs(nav.pos.y) + math.abs(math.pos.x) + 10) then
  49.         if not turtle.refuel() then
  50.             goBack(grabFuel)
  51.         end
  52.     end
  53. end
  54.  
  55. function checkInv()
  56.     if turtle.getItemCount(16) ~= 0 then
  57.         goBack(dropOff)
  58.     end
  59. end
  60.  
  61. function grabFuel()
  62.     turtle.suckUp(64)
  63. end
  64.  
  65. function dropOff()
  66.     for i=2, 16 do
  67.         turtle.select(i)
  68.         turtle.drop(64)
  69.     end
  70.     turtle.select(1)
  71. end
  72.    
  73. function forward(x)
  74.     for i = 1, x do
  75.         nav.forward(1)
  76.         refuel()
  77.         checkInv()
  78.     end
  79. end
Add Comment
Please, Sign In to add comment