Orcinuss

quarry

Feb 17th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.79 KB | None | 0 0
  1. posX = 0
  2. curX = 0
  3. posY = 0
  4. curY = 0
  5. posZ = 0
  6. curZ = 0
  7. yaw = 0
  8. curYaw = 0
  9.  
  10. local tArgs = {...}
  11. if #tArgs ~= 4 then
  12.     print( "Usage: quarry <length> <width> <starting Y level> <toBedrock (true|false)>" )
  13.     return
  14. end
  15.  
  16. local len = tonumber( tArgs[1] )
  17. if len < 1 then
  18.     print(  "Quarry dimension must be positive" )
  19.     return
  20. end
  21. local wid = tonumber( tArgs[2] )
  22. if wid < 1 then
  23.     print(  "Quarry dimension must be positive" )
  24.     return
  25. end
  26. local levY = tonumber( tArgs[3] )
  27. if levY <= 6 then
  28.     print(  "Quarry must start above y level 6" )
  29.     return
  30. end
  31. local bedrock = tonumber( tArgs[4] )
  32. if not bedrock == "true" or not bedrock == "false" then
  33.     print(  "You must specify if the quarry goes to bedrock (true|false)" )
  34.     return
  35. end
  36.  
  37. local function refuel()
  38.     local fuelLevel = turtle.getFuelLevel()
  39.     if fuelLevel == "unlimited" or fuelLevel > 0 then
  40.         return
  41.     end
  42.  
  43.     local function tryRefuel()
  44.         for n=1,16 do
  45.             count = turtle.getItemCount(n)
  46.             if count > 0 then
  47.                 turtle.select(n)
  48.                 if turtle.refuel(1) then
  49.                     if count < 4 then
  50.                         goChest()
  51.                         empty()
  52.                         goPos()
  53.                     end
  54.                     turtle.select(1)
  55.                     return true
  56.                 end
  57.             end
  58.         end
  59.         turtle.select(1)
  60.         return false
  61.     end
  62.  
  63.     if not tryRefuel() then
  64.         print( "Add more fuel to continue." )
  65.         while not tryRefuel() do
  66.             sleep(1)
  67.         end
  68.         print( "Resuming Mining" )
  69.     end
  70. end
  71.  
  72. local function moveUp()
  73.     refuel()
  74.     turtle.up()
  75.     posY = posY + 1
  76. end
  77.  
  78. local function moveDown()
  79.     refuel()
  80.     turtle.down()
  81.     posY = posY + 1
  82. end
  83.  
  84. local function moveForward()
  85.     refuel()
  86.     turtle.forward()
  87.     if yaw == 0 then
  88.         posX = posX + 1
  89.     end
  90.     if yaw == 1 then
  91.         posZ = posZ + 1
  92.     end
  93.     if yaw == 2 then
  94.         posX = posX - 1
  95.     end
  96.     if yaw == 3 then
  97.         posZ = posZ - 1
  98.     end
  99. end
  100.  
  101. local function moveBack()
  102.     refuel()
  103.     turtle.back()
  104.     if yaw == 0 then
  105.         posX = posX - 1
  106.     end
  107.     if yaw == 1 then
  108.         posZ = posZ - 1
  109.     end
  110.     if yaw == 2 then
  111.         posX = posX + 1
  112.     end
  113.     if yaw == 3 then
  114.         posZ = posZ + 1
  115.     end
  116. end
  117.  
  118. local function turnRight()
  119.     refuel()
  120.     turtle.turnRight()
  121.     yaw = yaw + 1
  122.     if yaw == 4 then
  123.         yaw = 0
  124.     end
  125. end
  126.  
  127. local function turnLeft()
  128.     refuel()
  129.     turtle.turnLeft()
  130.     yaw = yaw - 1
  131.     if yaw == -1 then
  132.         yaw = 3
  133.     end
  134. end
  135.  
  136. local function goChest()
  137.     curX = posX
  138.     curY = posY
  139.     curZ = posZ
  140.     curYaw = yaw
  141.    
  142.     for x = curYaw,0,-1 do
  143.         turnLeft()
  144.     end
  145.    
  146.     if curY < 0 then
  147.         for x = curY,0,1 do
  148.             moveUp()
  149.         end
  150.     else
  151.         for x = curY,0,-1 do
  152.             moveDown()
  153.         end
  154.     end
  155.    
  156.     for x = curX,0,-1 do
  157.         moveBack()
  158.     end
  159.     turnRight()
  160.     for x = curZ,0,-1 do
  161.         moveBack()
  162.     end
  163.     turnLeft()
  164. end
  165.  
  166. local function goPos()
  167.     for x = 0,curX,1 do
  168.         moveForward()
  169.     end
  170.     turnRight()
  171.     for x = 0,curZ,1 do
  172.         moveForward()
  173.     end
  174.     turnLeft()
  175.     for x = 0,curY,-1 do
  176.         moveDown()
  177.     end
  178.     for x = 0,curYaw,1 do
  179.         turnRight()
  180.     end
  181. end
  182.  
  183. local function invCheck()
  184.     slotFull = turtle.getItemSpace(15)
  185.     if slotFull == 0 then
  186.         goChest()
  187.         fill = turtle.getItemSpace(16)
  188.         empty()
  189.         goPos()
  190.     end
  191. end
  192.  
  193. local function empty()
  194.     turtle.turnRight()
  195.     turtle.turnRight()
  196.     for s = 1,15,1 do
  197.         turtle.drop()
  198.     end
  199.     turtle.select(16)
  200.     turtle.suck(turtle.getItemSpace(16))
  201.     turtle.select(1)
  202.     turtle.turnLeft()
  203.     turtle.turnLeft()
  204. end
  205.  
  206.  
  207. if bedrock == "false" then
  208.     print( "How deep should the quarry go?" )
  209.     hgt = read()
  210. else
  211.     hgt = 6
  212. end
  213.  
  214. refuel()
  215. for actY = 0,levY - hgt,1 do
  216.     for actZ = 0,wid,1 do
  217.         for actX = 0,len - 1,1 do
  218.             turtle.dig()
  219.             moveForward()
  220.             invCheck()
  221.         end
  222.         if actZ % 2 == 0 then
  223.             turnRight()
  224.             turtle.dig()
  225.             moveForward()
  226.             turnRight()
  227.         end
  228.         if actZ % 2 == 1 then
  229.             turnLeft()
  230.             turtle.dig()
  231.             moveForward()
  232.             turnLeft()
  233.         end
  234.     end
  235.     goChest()
  236.     empty()
  237.     for y = 0,actY,1 do
  238.         moveDown()
  239.     end
  240.     if actY == 0 then
  241.         moveDown()
  242.     end
  243. end
Advertisement
Add Comment
Please, Sign In to add comment