Advertisement
gur111

Untitled

Nov 5th, 2017
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. local size = 4
  2. local posX, posY, posZ
  3. local direction = 0
  4. posX = 0
  5. posY = 0
  6. posZ = 0
  7.  
  8. function up()
  9. while(not turtle.up()) do
  10. turtle.digUp()
  11. turtle.attackUp()
  12. end
  13. posZ = posZ-1
  14. end
  15.  
  16. function forward()
  17. while(not turtle.forward()) do
  18. local succ, data = turtle.inspect()
  19. if(succ and data.name == "minecraft:bedrock") then
  20. goBack()
  21. return
  22. end
  23. turtle.dig()
  24. turtle.attack()
  25. end
  26. updateXY(1)
  27. end
  28. function updateXY(dist)
  29. if(direction == 0) then posX = posX+dist
  30. elseif(direction == 1) then posY = posY+dist
  31. elseif(direction == 2) then posX = posX-dist
  32. elseif(direction == 3) then posY = posY-dist
  33. else print("invalid direction") end
  34. end
  35.  
  36. function turnStart()
  37. if(posX>0) then
  38. while(direction ~= 2) do
  39. turnLeft()
  40. end
  41. elseif(posY>0) then
  42. while(direction ~= 3) do
  43. turnLeft()
  44. end
  45. elseif(posX<0) then
  46. while(direction ~= 0) do
  47. turnLeft()
  48. end
  49. elseif(posY<0) then
  50. while(direction ~= 0) do
  51. turnLeft()
  52. end
  53. else
  54. return false
  55. end
  56. return true
  57. end
  58.  
  59. function goBack()
  60. print("Going back")
  61. while(posZ > 0) do up() end
  62. while(turnStart()) do
  63. go()
  64. end
  65. while(direction ~= 0) do turnRight() end
  66. end
  67.  
  68.  
  69. function down()
  70. while(turtle.attackDown()) do end
  71. if(turtle.detectDown()) then
  72. if(not turtle.digDown()) then
  73. goBack()
  74. return
  75. end
  76. end
  77. turtle.down()
  78. posZ = posZ+1
  79. end
  80.  
  81. function go()
  82. --print(posX..","..posY..","..posZ)
  83. local succ, data = turtle.inspect()
  84. if(succ and data.name == "minecraft:bedrock") then
  85. goBack()
  86. return
  87. end
  88. while(turtle.detect()) do
  89. turtle.dig()
  90. end
  91. while(turtle.detectUp()) do
  92. turtle.digUp()
  93. end
  94. if(turtle.detectDown()) then
  95. turtle.digDown()
  96. end
  97. while(turtle.attack()) do end
  98.  
  99. if(not turtle.forward()) then
  100. print("Can't move. Going home...")
  101. goBack()
  102. else
  103. updateXY(1)
  104. end
  105. end
  106.  
  107. function turnRight()
  108. turtle.turnRight()
  109. direction = (direction+1)%4
  110. end
  111.  
  112. function turnLeft()
  113. turtle.turnLeft()
  114. direction = (direction-1)%4
  115. end
  116.  
  117.  
  118.  
  119. local status, data = turtle.inspectDown()
  120.  
  121. while(not status or data.name ~= "minecraft:bedrock" and posZ < 10) do
  122. print("New Layer")
  123. for i = 0, size-1 do
  124. print("row: "..i)
  125. for j = 0, size-2, 1 do
  126. go()
  127. end
  128. if(i+1 ~= size) then
  129. if( i%2 == 0) then
  130. turnRight()
  131. go()
  132. turnRight()
  133. else
  134. turnLeft()
  135. go()
  136. turnLeft()
  137. end
  138. else
  139. print("End layer")
  140. -- os.sleep(10)
  141. if(size%2==0) then
  142. print("turn right only. Mod is 0")
  143. turnRight()
  144. else
  145. print("U turn mod isn't 1")
  146. turnLeft()
  147. turnLeft()
  148. end
  149. end
  150. end
  151. status, data = turtle.inspectDown()
  152. if (not status or data.name ~= "minecraft:bedrock" and posZ < 10) then
  153. down()
  154. down()
  155. down()
  156. end
  157. end
  158. goBack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement