zahar0401

Randomized Quarry

Aug 14th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. local args = {...}
  2.  
  3. if #args < 1 then
  4.  print("quarry <size> [height]")
  5. end
  6.  
  7. function safeRefuel()
  8.  if turtle.getFuelLevel() < 10 then
  9.   print("Attempting to refuel.")
  10.   turtle.refuel()
  11.  end
  12. end
  13.  
  14. function safeForward()
  15.  if not turtle.dig() then
  16.   turtle.forward()
  17.  end
  18. end
  19.  
  20. function safeDown()
  21.  if turtle.detectDown() then
  22.   turtle.digDown()
  23.  end
  24.  print("Going down a row.")
  25.  turtle.down()
  26. end
  27.  
  28. function excavate(radius)
  29.  if radius < 2 then
  30.   error("wrong radius, expected 2 or higher")
  31.  end
  32.  print("Excavating a row.")
  33.  for h = 1,4 do
  34.   for i = 1,radius do
  35.    safeForward()
  36.   end
  37.   safeRefuel()
  38.   turtle.turnRight()
  39.  end
  40. end
  41.  
  42. function digQuarry(size, height)
  43.  if height < 2 then
  44.   error("wrong height, expected 2 or higher")
  45.  end
  46.  for g = 1,height do
  47.   excavate(size)
  48.   safeDown()
  49.  end
  50.  print("Finished.")
  51. end
  52.  
  53. if #args == 1 then
  54.  excavate(tonumber(args[1]))
  55. elseif #args == 2 then
  56.  digQuarry(tonumber(args[1]), tonumber(args[2]))
  57. end
Advertisement
Add Comment
Please, Sign In to add comment