Advertisement
asweigart

burrower

Aug 1st, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. -- Burrower program
  2. -- By Al Sweigart
  3. -- turtleappstore.com/users/AlSweigart
  4. -- Mines a tunnel-shaped burrow.
  5.  
  6. os.loadAPI('hare')
  7.  
  8. -- handle command line arguments
  9. local cliArgs = {...}
  10. local maxLength = tonumber(cliArgs[1])
  11. local maxHeight = tonumber(cliArgs[2])
  12.  
  13. -- display "usage" info
  14. if maxLength == nil then
  15. print('Usage: stairminer <length> [height]')
  16. return
  17. end
  18.  
  19. -- set default height of 3
  20. if maxHeight == nil then
  21. maxHeight = 3
  22. end
  23.  
  24. -- dig the tunnel
  25. print('Digging burrow...')
  26. local i
  27. local currentLength = 0
  28. while currentLength < maxLength do
  29. print((maxLength - currentLength) .. ' meters left...')
  30.  
  31. -- fuel check
  32. if turtle.getFuelLevel() < (maxHeight * 2 + 1) then
  33. error('Not enough fuel to continue.')
  34. end
  35.  
  36. hare.digUntilClear()
  37. turtle.forward()
  38.  
  39. -- ascend and dig left side
  40. turtle.turnLeft()
  41. for i=1,maxHeight do
  42. hare.digUntilClear()
  43. if i ~= maxHeight then
  44. -- don't dig up at the very top
  45. hare.digUpUntilClear()
  46. turtle.up()
  47. end
  48. end
  49.  
  50. turtle.turnRight()
  51. turtle.turnRight()
  52.  
  53. -- descend and dig right side
  54. for i=1,maxHeight do
  55. hare.digUntilClear()
  56. if i ~= maxHeight then
  57. -- don't dig down at the very bottom
  58. hare.digDownUntilClear()
  59. turtle.down()
  60. end
  61. end
  62.  
  63. turtle.turnLeft() -- face forward
  64. currentLength = currentLength + 1
  65. end
  66.  
  67. print('Done.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement