SHARE
TWEET

mining turtle quarry

dcx_ Mar 26th, 2020 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local w = 3
  2. local l = 3
  3. local h = 6
  4. local cur_x = 1
  5. local cur_y = 1
  6. local cur_z = 1
  7.  
  8.  
  9. function Refuel()
  10.     if(turtle.getFuelLevel() <= 400) then
  11.         turtle.select(1)
  12.         local fuel = turtle.getItemCount(1) - 1
  13.         print("Refueling " .. fuel .. " units")
  14.         turtle.refuel(fuel)
  15.     end
  16. end
  17.  
  18. function Mine(blocks)
  19.     --print("Mining " .. blocks .. " blocks")
  20.     for y = 1,blocks,1 do
  21.         while(turtle.detect()) do
  22.             turtle.dig()
  23.             sleep(0.5)
  24.         end
  25.         turtle.forward()
  26.         while(turtle.detectUp()) do
  27.             turtle.dig()
  28.             sleep(0.5)
  29.         end
  30.         turtle.digDown()
  31.     end
  32. end
  33.  
  34. function RotateRight()
  35.     --print("Rotating right")
  36.     turtle.turnRight()
  37.     Mine(1)
  38.     turtle.turnRight()
  39. end
  40.  
  41. function RotateLeft()
  42.     --print("Rotating left")
  43.     turtle.turnLeft()
  44.     Mine(1)
  45.     turtle.turnLeft()
  46. end
  47.  
  48. function TryDumping()
  49.     if(turtle.getItemCount(15) > 0) then
  50.         Dump()
  51.         return true
  52.     else
  53.         return false
  54.     end
  55. end
  56.  
  57. function Dump()
  58.     print("Going home to dump items into storage")
  59.     local aux = 0
  60.     turtle.turnLeft()
  61.     while(not turtle.detect()) do
  62.         turtle.forward()
  63.         aux = aux + 1
  64.     end
  65.     for i = cur_z,2,-1 do
  66.         turtle.up()
  67.     end
  68.     print("Dumping items into storage")
  69.     for i = 16,2,-1 do
  70.         turtle.select(i)
  71.         turtle.drop()
  72.     end
  73.     for i = 1,cur_z-1,1 do
  74.         turtle.down()
  75.     end
  76.     turtle.turnRight()
  77.     if(cur_x == w) then
  78.         return
  79.     end
  80.     turtle.turnRight()
  81.     while(aux > 0) do
  82.         turtle.forward()
  83.         aux = aux - 1
  84.     end
  85.     turtle.turnLeft()
  86. end
  87.  
  88. function checkLevelFinished()
  89.     if(cur_x == w) then
  90.         print("Finished level, heading home")
  91.         if(cur_x % 2 == 0) then
  92.             turtle.turnRight()
  93.             turtle.turnRight()
  94.             Dump()
  95.         else
  96.             turtle.turnRight()
  97.             turtle.turnRight()
  98.             for i = 1,l-1,1 do
  99.                 turtle.forward()
  100.             end
  101.             turtle.turnLeft()
  102.             turtle.turnLeft()
  103.             Dump()
  104.         end
  105.         return true
  106.     else
  107.         return false
  108.     end
  109. end
  110.  
  111. function Run()
  112.     print("Started mining a " .. w .. "x" .. l .. "x" .. h .. " area")
  113.    
  114.     if(turtle.detectDown()) then
  115.         turtle.digDown()
  116.     end
  117.     turtle.down()
  118.     cur_z = cur_z + 1
  119.    
  120.     while(cur_z <= h - 1) do
  121.         print("Starting to mine levels " .. cur_z .. ", " .. cur_z + 1 .. ", " .. cur_z + 2 .. " of " .. h)
  122.         while(cur_x <= w) do
  123.             Refuel()
  124.             Mine(l - 1)
  125.             if(checkLevelFinished()) then break end
  126.             RotateRight()
  127.             cur_x = cur_x + 1
  128.             Refuel()
  129.             Mine(l - 1)
  130.             if(checkLevelFinished()) then break end
  131.             RotateLeft()
  132.             TryDumping()
  133.             cur_x = cur_x + 1
  134.         end
  135.        
  136.         if(cur_z == h - 1) then
  137.             print("Finished work, heading home")
  138.             for i = cur_z,2,-1 do
  139.                 turtle.up()
  140.             end
  141.             break
  142.         end
  143.        
  144.         turtle.digDown()
  145.         turtle.down()
  146.         cur_z = cur_z + 1
  147.         turtle.digDown()
  148.         turtle.down()
  149.         cur_z = cur_z + 1
  150.         cur_x = 1
  151.     end
  152.     print("Finished mining a " .. w .. "x" .. l .. "x" .. h .. " area")
  153. end
  154.  
  155. Run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top