Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. print("Length: ")
  2. local length = io.read()
  3. print("Width: ")
  4. local width = io.read()
  5. print("Height: ")
  6. local height = io.read()
  7.  
  8.  
  9.  
  10.  
  11.  
  12. function turn(diretion, steps)
  13. if not direction then
  14. direction = "right"
  15. end
  16.  
  17. if not steps then
  18. steps = 1
  19. end
  20.  
  21. if direction == "left" then
  22. for i=1,steps do
  23. turtle.turnLeft()
  24. end
  25. elseif direction == "right" then
  26. for i=1,steps do
  27. turtle.turnRight()
  28. end
  29. else return false end
  30.  
  31. return true
  32. end
  33.  
  34.  
  35.  
  36.  
  37.  
  38. function move()
  39. if turtle.detect() then
  40. turtle.dig()
  41. return turtle.forward()
  42. else
  43. return turtle.forward()
  44. end
  45. end
  46.  
  47.  
  48.  
  49.  
  50. function newRow(rowCount, direction)
  51.  
  52. if not (direction == "left" or direction == "right") then
  53. return false
  54. end
  55.  
  56. local secondDir = function()
  57. if direction == "left" then
  58. return "right"
  59. end
  60. return "left"
  61. end
  62.  
  63. if rowCount%2 ~= 0 then
  64. turn(direction)
  65. if not move() then return false end
  66. turn(direction)
  67. else
  68. turn(secondDir)
  69. if not move() then return false end
  70. turn(secondDir)
  71. end
  72.  
  73. return true
  74. end
  75.  
  76.  
  77.  
  78.  
  79. function newCol()
  80.  
  81. turtle.digDown()
  82. turtle.down()
  83.  
  84. turn("right",2)
  85. end
  86.  
  87.  
  88.  
  89.  
  90. function mineAll(l,w,h)
  91.  
  92. function leftOrRight(rowCount)
  93. if rowCount%2 == 0 then return "left" end
  94. return "right"
  95. end
  96.  
  97. for hi = 1,h do
  98. print("Mining layer: ", hi, "/", h)
  99. for wi=1,w do
  100. print("Mining row: ", wi, "/", w)
  101. for li=1,l do
  102. if not move() then
  103. return false
  104. end
  105. end
  106. if not wi >= w then newRow(wi, leftOrRight(wi)) end
  107. end
  108. if not hi >= h then newCol() end
  109. end
  110. return true
  111. end
  112.  
  113.  
  114.  
  115.  
  116.  
  117. function main()
  118. print("Total blocks to mine: ", length*width*height)
  119. mineAll(length, width, height)
  120. end
  121.  
  122. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement