Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. -- get arguments
  2.  
  3. local tArgs = { ... }
  4. if #tArgs ~= 1 then
  5. print( "Usage: basicTunne; <Tunnel Length>" )
  6. return
  7. end
  8.  
  9. local tunnelLength = tonumber( tArgs[1] )
  10. if tunnelLength < 1 then
  11. print( "Tunnel Length must be positive!" )
  12. return
  13. end
  14.  
  15. -- stolen collect function
  16.  
  17. local function collect()
  18. local bFull = true
  19. local nTotalItems = 0
  20. for n=1,16 do
  21. local nCount = turtle.getItemCount(n)
  22. if nCount == 0 then
  23. bFull = false
  24. end
  25. nTotalItems = nTotalItems + nCount
  26. end
  27.  
  28. if nTotalItems > collected then
  29. collected = nTotalItems
  30. if math.fmod(collected + unloaded, 50) == 0 then
  31. print( "Mined "..(collected + unloaded).." items." )
  32. end
  33. end
  34.  
  35. if bFull then
  36. print( "No empty slots left." )
  37. return false
  38. end
  39. return true
  40. end
  41.  
  42. -- function to tunnel 1x3 directly in front
  43.  
  44. local function digInFront ()
  45. if turtle.detectUp() then
  46. if turtle.digUp() then
  47. if not collect() then
  48. error()
  49. end
  50. end
  51. end
  52.  
  53. if turtle.detect() then
  54. if turtle.dig() then
  55. if not collect() then
  56. error()
  57. end
  58. end
  59. end
  60.  
  61. if turtle.detectDown() then
  62. if turtle.digDown() then
  63. if not collect() then
  64. error()
  65. end
  66. end
  67. end
  68. end
  69.  
  70. -- function to move x blocks in given direction (left / right) maintaining orientation
  71. local function move(numToMove, orientation)
  72. local cleanNumToMove = tonumber( numToMove )
  73.  
  74. if orientation == "left" then
  75. if turtle.turnLeft() then
  76. for i = 1, cleanNumToMove, 1 do
  77. turtle.forward()
  78. end
  79. turtle.turnRight()
  80. end
  81. end
  82.  
  83. if orientation == "right" then
  84. if turtle.turnRight() then
  85. for i = 1, cleanNumToMove, 1 do
  86. turtle.forward()
  87. end
  88. turtle.turnLeft()
  89. end
  90. end
  91.  
  92. end
  93.  
  94. -- program start
  95.  
  96. local done = false
  97.  
  98. while not done do
  99. for n = 1, tunnelLength/2 do
  100.  
  101. digInFront()
  102. move(1, "right")
  103. digInFront()
  104. move(1, "right")
  105. digInFront()
  106.  
  107. turtle.forward()
  108.  
  109. digInFront()
  110. move(1, "left")
  111. digInFront()
  112. move(1, "left")
  113. digInFront()
  114. end
  115. done = true
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement