SHARE
TWEET

mining turtle quarry

dcx_ Mar 26th, 2020 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local w = 64
  2. local l = 64
  3. local h = 64
  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.     end
  27. end
  28.  
  29. function RotateRight()
  30.     --print("Rotating right")
  31.     turtle.turnRight()
  32.     while(turtle.detect()) do
  33.         turtle.dig()
  34.         sleep(0.5)
  35.     end
  36.     turtle.forward()
  37.     turtle.turnRight()
  38. end
  39.  
  40. function RotateLeft()
  41.     --print("Rotating left")
  42.     turtle.turnLeft()
  43.     while(turtle.detect()) do
  44.         turtle.dig()
  45.         sleep(0.5)
  46.     end
  47.     turtle.forward()
  48.     turtle.turnLeft()
  49. end
  50.  
  51. function TryDumping()
  52.     if(turtle.getItemCount(15) > 0) then
  53.         Dump()
  54.         return true
  55.     else
  56.         return false
  57.     end
  58. end
  59.  
  60. function Dump()
  61.     print("Going home to dump items into storage")
  62.     local aux = 0
  63.     turtle.turnLeft()
  64.     while(not turtle.detect()) do
  65.         turtle.forward()
  66.         aux = aux + 1
  67.     end
  68.     for i = cur_z,2,-1 do
  69.         turtle.up()
  70.     end
  71.     print("Dumping items into storage")
  72.     for i = 16,2,-1 do
  73.         turtle.select(i)
  74.         turtle.drop()
  75.     end
  76.     for i = 1,cur_z-1,1 do
  77.         turtle.down()
  78.     end
  79.     turtle.turnRight()
  80.     if(cur_x == w) then
  81.         return
  82.     end
  83.     turtle.turnRight()
  84.     while(aux > 0) do
  85.         turtle.forward()
  86.         aux = aux - 1
  87.     end
  88.     turtle.turnLeft()
  89. end
  90.  
  91. function checkLevelFinished()
  92.     if(cur_x == w) then
  93.         print("Finished level, heading home")
  94.         if(cur_x % 2 == 0) then
  95.             turtle.turnRight()
  96.             turtle.turnRight()
  97.             Dump()
  98.         else
  99.             turtle.turnRight()
  100.             turtle.turnRight()
  101.             for i = 1,l-1,1 do
  102.                 turtle.forward()
  103.             end
  104.             turtle.turnLeft()
  105.             turtle.turnLeft()
  106.             Dump()
  107.         end
  108.         return true
  109.     else
  110.         return false
  111.     end
  112. end
  113.  
  114. function Run()
  115.     print("Started mining a " .. w .. "x" .. l .. "x" .. h .. " area")
  116.     while(cur_z <= h) do
  117.         print("Starting to mine level " .. cur_z .. "/" .. h)
  118.         while(cur_x <= w) do
  119.             Refuel()
  120.             Mine(l - 1)
  121.             if(checkLevelFinished()) then break end
  122.             RotateRight()
  123.             cur_x = cur_x + 1
  124.             Refuel()
  125.             Mine(l - 1)
  126.             if(checkLevelFinished()) then break end
  127.             RotateLeft()
  128.             TryDumping()
  129.             cur_x = cur_x + 1
  130.         end
  131.        
  132.         if(cur_z == h) then
  133.             print("Finished work, heading home")
  134.             for i = cur_z,2,-1 do
  135.                 turtle.up()
  136.             end
  137.             break
  138.         end
  139.        
  140.         turtle.digDown()
  141.         turtle.down()
  142.         cur_z = cur_z + 1
  143.         cur_x = 1
  144.     end
  145.     print("Finished mining a " .. w .. "x" .. l .. "x" .. h .. " area")
  146. end
  147.  
  148. 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