Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Build Tools
  2. -- dig v1
  3.  
  4. local args = { ... }
  5.  
  6. if args[1] == nil or args[2] == nil or args[3] == nil or turtle.getItemCount(1) < 1 or args[1] == "help" then
  7. print ("Usage: dig [forward length] [right length] [depth]")
  8. print ("Put an ender chest in the first slot")
  9. return
  10. end
  11.  
  12. local tilt = 0
  13. local flength = tonumber(args[1])
  14. local rlength = tonumber(args[2])
  15. local depth = tonumber(args[3])
  16. local blocks = rlength * flength * depth
  17.  
  18. function step()
  19. while not turtle.forward() do
  20. turtle.dig()
  21. end
  22. end
  23.  
  24. function stepUp()
  25. while not turtle.up() do
  26. turtle.digUp()
  27. end
  28. end
  29.  
  30. function stepDown()
  31. while not turtle.down() do
  32. turtle.digDown()
  33. end
  34. end
  35.  
  36. function placeUp()
  37. while not turtle.placeUp() do
  38. turtle.digUp()
  39. end
  40. end
  41.  
  42. function rotateRight()
  43. turtle.turnRight()
  44. if vertical then
  45. stepUp()
  46. else
  47. step()
  48. end
  49. turtle.turnRight()
  50. end
  51.  
  52. function rotateLeft()
  53. turtle.turnLeft()
  54. if vertical then
  55. stepUp()
  56. else
  57. step()
  58. end
  59. turtle.turnLeft()
  60. end
  61.  
  62. -- Dump inventory into ender chest.
  63. function dump()
  64. turtle.select(1)
  65. placeUp()
  66. for m = 16, 2, -1 do
  67. turtle.select(m)
  68. turtle.dropUp()
  69. end
  70. turtle.select(1)
  71. turtle.digUp()
  72. end
  73.  
  74. -- Dig 'em up.
  75. for i = 1, depth, 1 do
  76. for j = 1, rlength, 1 do
  77. for k = 1, flength, 1 do
  78. if turtle.getItemCount(16) > 0 then
  79. dump()
  80. end
  81. turtle.digDown()
  82. if k < flength then
  83. step()
  84. end
  85. end
  86. if j < rlength then
  87. if (j + tilt) % 2 == 0 then
  88. rotateRight()
  89. else
  90. rotateLeft()
  91. end
  92. end
  93. end
  94. if rlength % 2 == 0 and i % 2 ~= 0 then
  95. tilt = 1
  96. else
  97. tilt = 0
  98. end
  99. turtle.turnLeft()
  100. turtle.turnLeft()
  101. stepDown()
  102. end
  103.  
  104. -- Raise to initial height.
  105. for i = 1, depth, 1 do
  106. stepUp()
  107. end
  108.  
  109. -- Return to origin.
  110. if depth % 2 ~= 0 then
  111. if rlength % 2 == 0 then
  112. turtle.turnRight()
  113. for i = 1, rlength - 1, 1 do
  114. step()
  115. end
  116. else
  117. turtle.turnLeft()
  118. for i = 1, rlength - 1, 1 do
  119. step()
  120. end
  121. turtle.turnRight()
  122. for i = 1, flength - 1, 1 do
  123. step()
  124. end
  125. end
  126. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement