Blazuno

TurtleSwarmDISKDRIVE

Oct 31st, 2021 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. local north
  2. local west
  3. local PCID = os.getComputerID ()
  4. local k
  5. local p
  6. local turnLeft = false
  7. rednet.open ("right")
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. function fuelUp ()
  17. turtle.turnLeft ()
  18. turtle.suck (16)
  19. turtle.refuel ()
  20. turtle.turnRight ()
  21. end
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. -----TURTLE IS SUPPOSED TO FACE POSITIVE X (EAST)
  33. function goToPlr ()
  34. local forwardXAmount
  35. local forwardYAmount
  36. local forwardZAmount
  37. local curPosX, curPosY, curPosZ = gps.locate ()
  38. local curPos = { curPosX, curPosY, curPosZ }
  39. local curZPos = math.abs (curPos[3])
  40. local plrZPos = math.abs (plrPos[3])
  41. print (curPos[1])
  42. print (plrPos[1])
  43. print (curPos[2])
  44. print (plrPos[2])
  45. print (curPos[3])
  46. print (plrPos[3])
  47. for i, v in pairs (curPos) do
  48. print (i .. ":" .. v)
  49. end
  50. if curPos[1] > plrPos[1] then
  51. turtle.turnRight ()
  52. turtle.turnRight ()
  53. end
  54. if curPos[1] > plrPos[1] then
  55. forwardXAmount = math.abs(curPos[1]) - math.abs(plrPos[1])
  56. west = true
  57. else
  58. forwardXAmount = math.abs(plrPos[1]) - math.abs(curPos[1])
  59. west = false
  60. end
  61. forwardXAmount = math.abs(forwardXAmount)
  62. print ("goToPlr Forward Amount Debug: " .. forwardXAmount)
  63. for i=1, forwardXAmount do
  64. forwardAndCheck ()
  65. end
  66. if curPos[3] > plrPos[3] then
  67. if west == true then
  68. turtle.turnRight ()
  69. north = true
  70. else
  71. turtle.turnLeft ()
  72. north = true
  73. end
  74. forwardZAmount = plrZPos - curZPos
  75. else
  76. if west == true then
  77. turtle.turnLeft ()
  78. north = false
  79. else
  80. turtle.turnRight ()
  81. north = false
  82. end
  83. forwardZAmount = curZPos - plrZPos
  84. end
  85. forwardZAmount = math.abs(forwardZAmount)
  86. print("goToPlr ForwardZAmount Debug: "..forwardZAmount)
  87. west = false
  88. for i=1, forwardZAmount do
  89. forwardAndCheck ()
  90. end
  91. forwardYAmount = curPos[2] - plrPos[2]
  92. for i=1, forwardYAmount-1 do
  93. turtle.down ()
  94. end
  95. print(north)
  96. if north == true then
  97. turtle.turnRight ()
  98. else
  99. turtle.turnLeft ()
  100. end
  101. end
  102.  
  103. function forwardAndCheck ()
  104. if turtle.forward () == false then
  105. repeat
  106. turtle.up ()
  107. until turtle.forward () == true
  108. end
  109. end
  110.  
  111. function downAndCheck ()
  112. if turtle.down () == false then
  113. repeat
  114. sleep (1)
  115. until turtle.down () == true
  116. end
  117. end
  118.  
  119. function goToSectors (turtleID, deploymentCoords, plrPos)
  120. local j = 1
  121. newPlrPos = {}
  122. print ("goToSectors turtleID Debug: " .. turtleID)
  123. local deploymentYPos = turtleID*2
  124. local deploymentXPos = deploymentYPos - 1
  125. local xPos = deploymentCoords[deploymentXPos]
  126. local yPos = deploymentCoords[deploymentYPos]
  127. local xPos = math.abs (xPos)
  128. local yPos = math.abs (yPos)
  129. for i,v in pairs(plrPos) do
  130. v = math.abs(v)
  131. table.insert(newPlrPos, v)
  132. end
  133. print("goToSectors xPos Debug: "..xPos)
  134. print ("goToSectors yPos Debug: " .. yPos)
  135. print ("goToSectors plrYPos Debug: " .. newPlrPos[3])
  136. local forwardXAmount = xPos - newPlrPos[1]
  137. local forwardYAmount = newPlrPos[3] - yPos
  138. local forwardXAmount = math.abs(forwardXAmount)
  139. local forwardYAmount = math.abs(forwardYAmount)
  140. print ("goToSectors forwardXAmount Debug: " .. forwardXAmount)
  141. print ("goToSectors forwardYAmount Debug: " .. forwardYAmount)
  142. for i=1, forwardYAmount do
  143. forwardAndCheck()
  144. end
  145. turtle.turnRight()
  146. for i=1,forwardXAmount do
  147. forwardAndCheck()
  148. end
  149. turtle.turnLeft()
  150. turtle.down()
  151. end
  152.  
  153. function mineColumn(miningDimensions, length)
  154. print("nextRow yRemainder Debug: "..yRemainder)
  155. xPos = 1
  156. reverseXPos = false
  157. if yRemainder == 1 then
  158. for i=1, length-1 do
  159. turtle.dig()
  160. turtle.forward()
  161. if reverseXPos == true then
  162. xPos = xPos-1
  163. else
  164. xPos = xPos+1
  165. end
  166. end
  167. elseif yRemainder == 2 then
  168. for i=1, length-1 do
  169. turtle.dig()
  170. turtle.digDown()
  171. turtle.forward()
  172. if reverseXPos == true then
  173. xPos = xPos-1
  174. else
  175. xPos = xPos+1
  176. end
  177. end
  178. else
  179. for i=1, length-1 do
  180. turtle.digDown()
  181. turtle.digUp()
  182. turtle.dig()
  183. turtle.forward()
  184. if reverseXPos == true then
  185. xPos = xPos-1
  186. else
  187. xPos = xPos+1
  188. end
  189. end
  190. end
  191. end
  192.  
  193. function nextRow()
  194. print("nextRow yRemainder Debug: "..yRemainder)
  195. zPos = 1
  196. if turnLeft == false then
  197. turtle.turnRight()
  198. if yRemainder == 1 then
  199. turtle.dig()
  200. turtle.forward()
  201. turtle.turnRight()
  202. zPos = zPos+1
  203. elseif yRemainder == 2 then
  204. turtle.dig()
  205. turtle.digDown()
  206. turtle.forward()
  207. turtle.digDown()
  208. turtle.turnRight()
  209. zPos = zPos + 1
  210. else
  211. turtle.dig()
  212. turtle.digUp()
  213. turtle.digDown()
  214. turtle.forward()
  215. turtle.digUp()
  216. turtle.digDown()
  217. turtle.turnRight()
  218. zPos = zPos + 1
  219. end
  220. turnLeft = true
  221. else
  222. turtle.turnLeft()
  223. if yRemainder == 1 then
  224. turtle.dig()
  225. turtle.forward()
  226. turtle.turnLeft()
  227. zPos = zPos + 1
  228. elseif yRemainder == 2 then
  229. turtle.dig()
  230. turtle.digDown()
  231. turtle.forward()
  232. turtle.digDown()
  233. turtle.turnLeft()
  234. zPos = zPos + 1
  235. else
  236. turtle.dig()
  237. turtle.digUp()
  238. turtle.digDown()
  239. turtle.forward()
  240. turtle.digUp()
  241. turtle.digDown()
  242. turtle.turnLeft()
  243. zPos = zPos + 1
  244. end
  245. turnLeft = false
  246. end
  247. end
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254. function goToY (miningDimensions)
  255. local curXPos, curYPos, curZPos = gps.locate()
  256. local curPos = {curXPos, curYPos, curZPos}
  257. local forwardYAmount = curPos[2] - miningDimensions[4]
  258. if tonumber(miningDimensions[2]) >= 3 then
  259. for i=1, forwardYAmount+1 do
  260. turtle.digDown()
  261. turtle.down()
  262. end
  263. else
  264. for i=1, forwardYAmount do
  265. turtle.digDown ()
  266. turtle.down ()
  267. end
  268. end
  269. end
  270.  
  271.  
  272.  
  273.  
  274. k, packet, p = rednet.receive ()
  275. turtleID = packet[1]
  276. turtleCountNeeded = packet[2]
  277. plrPos = packet[3]
  278. miningDimensions = packet[4]
  279. rowsPerTurtle = packet[5]
  280. deploymentCoords = packet[6]
  281. yRemainder = miningDimensions[2]
  282. length = packet[7]
  283. width = packet[8]
  284. print("yRemainder Debug: "..yRemainder)
  285.  
  286.  
  287. fuelUp ()
  288. turtle.forward ()
  289. turtle.forward ()
  290. turtle.forward ()
  291. turtle.forward ()
  292. turtle.down ()
  293. turtle.down ()
  294. goToPlr ()
  295. goToSectors (turtleID, deploymentCoords, plrPos)
  296. goToY(miningDimensions)
  297. for i=1,width do
  298. mineColumn(miningDimensions, length)
  299. nextRow(yRemainder)
  300. end
  301.  
Add Comment
Please, Sign In to add comment