Luubstar

CC Turtle Mine Square

Jun 19th, 2023 (edited)
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. currentx = 1
  2. currenty = 1
  3. currentz = 1
  4. lasty = 1
  5. local arg = {...}
  6.  
  7. maxX = tonumber(arg[1])
  8. maxY = tonumber(arg[2])
  9. maxZ = tonumber(arg[3])
  10.  
  11. print("Creando un cuadrado de (x: " .. maxX .." y: " .. maxY .." z: " ..maxZ .. ")")
  12.  
  13. turtle.select(1)
  14. turtle.refuel()
  15. turtle.select(2)
  16. siding = 1
  17. currentSlot = 2
  18. auxSlot = 2
  19. function returndown()
  20. while(currenty ~= lasty)
  21. do
  22. turtle.down()
  23. currenty = currenty + 1
  24. end
  25. end
  26.  
  27. function returnstart()
  28. print("Returning to startpoint...")
  29. if(siding == 1) then
  30. turtle.turnLeft()
  31. while (currentz > 1)
  32. do
  33. turtle.forward()
  34. currentz = currentz - 1
  35. end
  36. turtle.turnLeft()
  37. while (currentx > 1)
  38. do
  39. turtle.forward()
  40. currentx = currentx - 1
  41. end
  42. turtle.turnLeft()
  43. turtle.turnLeft()
  44. currentx = 1
  45. currentz = 1
  46. else
  47. turtle.turnRight()
  48. while (currentz > 1)
  49. do
  50. turtle.forward()
  51. currentz = currentz - 1
  52. end
  53. turtle.turnLeft()
  54. while (currentx > 1)
  55. do
  56. turtle.forward()
  57. currentx = currentx - 1
  58. end
  59. currentx = 1
  60. currentz = 1
  61. turtle.turnRight()
  62. turtle.turnRight()
  63. end
  64. end
  65.  
  66.  
  67. while (currentx ~= maxX or currenty ~= maxY or currentz ~= maxZ)
  68. do
  69. print("Posición acutal (x: " .. currentx .. " y: " .. currenty .." z: " ..currentz..")")
  70. compareblocker = true
  71. while((not turtle.compare()) and compareblocker and turtle.detect())
  72. do
  73. print("checking slot: " .. auxSlot)
  74. turtle.select(auxSlot)
  75. if(turtle.getItemCount(auxSlot) == 0) then
  76. compareblocker = false
  77. else
  78. if (auxSlot < 16) then
  79. auxSlot = auxSlot + 1
  80. turtle.select(auxSlot)
  81. else
  82. returnstart()
  83. while(currenty > 1)
  84. do
  85. turtle.up()
  86. currenty = currenty - 1
  87. end
  88. turtle.turnLeft()
  89. turtle.turnLeft()
  90. auxSlot = 16
  91. while(auxSlot ~= 1)
  92. do
  93. turtle.select(auxSlot)
  94. turtle.drop()
  95. auxSlot = auxSlot -1
  96. end
  97. auxSlot = 2
  98. turtle.select(2)
  99. turtle.turnLeft()
  100. turtle.turnLeft()
  101. compareblocker = false
  102. returndown()
  103. end
  104. end
  105. end
  106.  
  107. if (turtle.getItemCount(currentSlot) == 64) then
  108. if (currentSlot < 16) then
  109. currentSlot = currentSlot +1
  110. turtle.select(currentSlot)
  111. else
  112. returnstart()
  113.  
  114. while(currenty > 1)
  115. do
  116. turtle.up()
  117. currenty = currenty -1
  118. end
  119. turtle.turnLeft()
  120. turtle.turnLeft()
  121. turtle.select(16)
  122. while(currentSlot ~= 1)
  123. do
  124. turtle.drop()
  125. currentSlot = currentSlot -1
  126. turtle.select(currentSlot)
  127. end
  128. currentSlot = 2
  129. turtle.turnLeft()
  130. turtle.turnLeft()
  131. returndown()
  132. end
  133. elseif (turtle.getItemCount(1) < 5) then
  134. returnstart()
  135.  
  136. while(currenty > 1)
  137. do
  138. turtle.up()
  139. currenty = currenty -1
  140. end
  141. turtle.turnLeft()
  142. turtle.select(1)
  143. turtle.refuel()
  144. turtle.suck(64 - turtle.getItemCount(1))
  145. turtle.turnRight()
  146. returndown()
  147. elseif (turtle.getFuelLevel() < 10) then
  148. turtle.select(1)
  149. turtle.refuel()
  150.  
  151. elseif (currentx < maxX) then
  152. turtle.dig()
  153. turtle.forward()
  154. currentx = currentx + 1
  155. elseif (currentz < maxZ and currentx >= maxX) then
  156. currentx = 1
  157. currentz = currentz + 1
  158. if (siding == 1) then
  159. turtle.turnRight()
  160. turtle.dig()
  161. turtle.forward()
  162. turtle.turnRight()
  163. siding = 2
  164. else
  165. turtle.turnLeft()
  166. turtle.dig()
  167. turtle.forward()
  168. turtle.turnLeft()
  169. siding = 1
  170. end
  171. else
  172. if (currenty < maxY) then
  173. returnstart()
  174. currentx = 1
  175. currentz = 1
  176. currenty = currenty + 1
  177. lasty = currenty
  178. turtle.digDown()
  179. turtle.down()
  180. siding = 1
  181. end
  182. end
  183. auxSlot = 2
  184. end
  185.  
  186. returnstart()
  187. while(currenty > 1)
  188. do
  189. turtle.up()
  190. currenty = currenty -1
  191. end
  192. turtle.turnLeft()
  193. turtle.turnLeft()
  194. turtle.select(16)
  195. currentSlot = 16
  196. while(currentSlot ~= 1)
  197. do
  198. turtle.drop()
  199. currentSlot = currentSlot -1
  200. turtle.select(currentSlot)
  201. end
  202. turtle.turnLeft()
  203. turtle.turnLeft()
Advertisement
Add Comment
Please, Sign In to add comment