Phemto

Mine_Arc2

Dec 23rd, 2020 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Mining a series of pluses all the way to bedrock, then come back and leave the items in chests.
  2. --To start, Have a chest one in front and one up from the turtle, then a row going back from there. You'll want a lot.
  3. --Make sure the turtle is fueled. Put buckets in slot one and stone in slot 2
  4.  
  5. --declare the global variables
  6. width = 9 --width of the area to mine. (Actually 2 * width +1
  7. theta = 50*6.28 --sweep of the spiral
  8. step = 0.001 --change in theta each step
  9. b = 0.14 --growth factor for spiral
  10. columnList = " " --list of columns visited
  11. maxradius = 200 --don't grow out past this point
  12. buildWall = 0 --set to 1 to build a wall on the outside
  13. lavaSum = 200 --sum of the YY locations for finding lava
  14. lavaCount = 0 --number of lava blocks collected
  15. cobbleCountMax = 600 --give up if you check this many columns and they're all already done
  16.  
  17. curX = 0 --current X position relative to the start
  18. curY = 0 --current Y position relative to the start
  19. curZ = 0 --current Z position relative to the start
  20. facing = 0 --what direction is the turtle facing (0,1,2,3)
  21. --0 is toward positive Z
  22.  
  23.  
  24. function fuel(direction)
  25. --called periodically, and also when lava is detected.
  26. --print("refueling ", direction)
  27. turtle.select(1)
  28. --Now let's pickup the lava
  29. if direction == 1 then
  30. --its in front
  31. turtle.place()
  32. elseif direction == 2 then
  33. turtle.placeDown()
  34. lavaSum = lavaSum + curY
  35. lavaCount = lavaCount + 1
  36. elseif direction == 3 then
  37. turtle.placeUp()
  38. lavaSum = lavaSum + curY
  39. lavaCount = lavaCount + 1
  40. end
  41. if turtle.getFuelLevel() < 19000 then
  42. for slot = 5,16,1 do
  43. turtle.select(slot)
  44. turtle.refuel()
  45. if turtle.compareTo(1) then
  46. turtle.transferTo(1)
  47. end
  48. if turtle.getFuelLevel() > 19000 then
  49. break
  50. end
  51. end
  52. if curY >=0 or turtle.getFuelLevel() < 500 then
  53. repeat
  54. --Time to refuel
  55. for slot = 5,16,1 do
  56. turtle.select(slot)
  57. turtle.refuel()
  58. if turtle.compareTo(1) then
  59. turtle.transferTo(1)
  60. end
  61. end
  62. until (turtle.getFuelLevel() > 1000) --don't stop trying if the level is too low
  63. end
  64. end
  65. turtle.select(1)
  66. print(turtle.getFuelLevel())
  67. end
  68.  
  69. function SlotItems(slot)
  70. turtle.select(slot)
  71. if turtle.getItemCount() == 0 then
  72. return "nothing"
  73. else
  74. local data = turtle.getItemDetail()
  75. return data.name
  76. end
  77. end
  78.  
  79. function TRight()
  80. --Turn the turtle to the right
  81. turtle.turnRight()
  82. facing = facing +1
  83. if facing > 3 then
  84. facing = facing - 4
  85. end
  86. end
  87.  
  88. function TLeft()
  89. --Turn the turtle to the right
  90. turtle.turnLeft()
  91. facing = facing - 1
  92. if facing < 0 then
  93. facing = facing + 4
  94. end
  95. end
  96.  
  97. function Forward()
  98. local success, data = turtle.inspect()
  99. if success then
  100. while string.find(data.name, "urtle") do
  101. print("Turtle detected: No TVT!")
  102. success, data = turtle.inspect()
  103. end
  104. if string.find(data.name, "lava") then
  105. fuel(1)
  106. end
  107. end
  108. while not turtle.forward() do
  109. turtle.dig()
  110. end
  111. if facing == 0 then
  112. curZ = curZ + 1
  113. elseif facing == 1 then
  114. curX = curX +1
  115. elseif facing == 2 then
  116. curZ = curZ - 1
  117. else
  118. curX = curX - 1
  119. end
  120. end
  121.  
  122. function Up()
  123. local success, data = turtle.inspectUp()
  124. if success then
  125. while string.find(data.name, "urtle") do
  126. print("Turtle detected: No TVT!")
  127. success, data = turtle.inspectUp()
  128. sleep(10)
  129. end
  130. if string.find(data.name, "lava") then
  131. fuel(3)
  132. end
  133. end
  134. while not turtle.up() do
  135. turtle.digUp()
  136. end
  137. curY = curY + 1
  138. end
  139.  
  140. function Down()
  141. local success, data = turtle.inspectDown()
  142. if success then
  143. while string.find(data.name, "urtle") do
  144. print("Turtle detected: No TVT!")
  145. success, data = turtle.inspectDown()
  146. sleep(10)
  147. end
  148. if string.find(data.name, "lava") then
  149. fuel(2)
  150. end
  151. end
  152. while not turtle.down() do
  153. turtle.digDown()
  154. end
  155. curY = curY - 1
  156. end
  157.  
  158. function TurnTo(face)
  159. while (facing ~= face) do
  160. TLeft()
  161. end
  162. end
  163.  
  164. function MoveTo (MoveToX, MoveToY, MoveToZ)
  165. --Move the turtle to the desired position
  166. --first X
  167. --print(MoveToX, " " , MoveToY, " " ,MoveToZ)
  168. if MoveToX < curX then
  169. TurnTo(3)
  170. while MoveToX < curX do
  171. Forward()
  172. end
  173. elseif MoveToX > curX then
  174. TurnTo(1)
  175. while MoveToX > curX do
  176. Forward()
  177. end
  178. end
  179. --Now Z
  180. if MoveToZ < curZ then
  181. TurnTo(2)
  182. while MoveToZ < curZ do
  183. Forward()
  184. end
  185. elseif MoveToZ > curZ then
  186. TurnTo(0)
  187. while MoveToZ > curZ do
  188. Forward()
  189. end
  190. end
  191. --Now Y
  192. if MoveToY < curY then
  193. while MoveToY < curY do
  194. Down()
  195. end
  196. end
  197. while MoveToY > curY do
  198. Up()
  199. end
  200. end --MoveTo
  201.  
  202. function cobbleBelow()
  203. local success, data = turtle.inspectDown()
  204. if success then
  205. if string.find(data.name, "cobble") then
  206. return 1
  207. end
  208. end
  209. return nil
  210. end
  211.  
  212. function setCobble(direction)
  213. for slot = 2,3,1 do
  214. turtle.select(slot)
  215. if turtle.getItemCount() > 1 then
  216. if direction < 0 then
  217. turtle.placeDown()
  218. elseif direction > 0 then
  219. turtle.placeUp()
  220. else
  221. turtle.place()
  222. end
  223. for s=4,16,1 do
  224. turtle.select(s)
  225. if turtle.compareTo(slot) then
  226. turtle.transferTo(slot,1)
  227. return(1)
  228. end
  229. end
  230. return(1)
  231. end
  232. end
  233. return 0
  234. end
  235.  
  236.  
  237. --Start the program
  238.  
  239. columnX = 0 --location to dig out a column
  240. columnY = 0
  241. fuel()
  242. oldXX = 1 --previous XX and ZZ positions
  243. oldZZ = 1
  244. XX = 1
  245. ZZ = 1
  246. while math.abs(theta) < maxradius*6.28 do
  247. --find the next (XX,ZZ)
  248. --first change theta until we get to a new column
  249. --print("new column")
  250. while (XX == oldXX) and (ZZ == oldZZ) do
  251. theta = theta + step
  252. XX = math.floor((b*theta) * math.cos(theta))
  253. ZZ = math.floor((b*theta) * math.sin(theta))
  254. end
  255. --now the column has changed, but is it really one we've never done before?
  256. MoveTo(XX,curY,ZZ)
  257. MoveTo(XX,0,ZZ)
  258. --print("Checking for cobble")
  259. cobbleCount = 0
  260. while cobbleBelow() or ((ZZ - XX*2) % 5) ~= 0 do
  261. --print(XX, "," ZZ, "," , (ZZ-XX*2) % 5)
  262. oldXX = XX
  263. oldZZ = ZZ
  264. while (XX == oldXX) and (ZZ == oldZZ) do
  265. theta = theta + step
  266. XX = math.floor((b*theta) * math.cos(theta))
  267. ZZ = math.floor((b*theta) * math.sin(theta))
  268. end
  269. MoveTo(XX,curY,ZZ)
  270. cobbleCount = cobbleCount + 1
  271. if cobbleCount > cobbleCountMax then
  272. --Looks like we've run into an area already processed by another turtle.
  273. print("Couldn't find a new column. Finishing!")
  274. MoveTo(0,0,0)
  275. os.exit()
  276. end
  277. end
  278. oldXX = XX
  279. oldZZ = ZZ
  280. --dig down
  281. turtle.digDown()
  282. while not turtle.detectDown() do
  283. Down()
  284. --Remove the blocks in the four directions
  285. for i=1,4,1 do
  286. local success, data = turtle.inspect()
  287. if success then
  288. if string.find(data.name, "lava") then
  289. fuel(1)
  290. end
  291. end
  292. turtle.dig()
  293. TRight()
  294. end
  295. if curY == -2 then
  296. setCobble(1)
  297. elseif curY == -1 then
  298. turtle.select(2)
  299. for i=1,4,1 do
  300. TRight()
  301. setCobble(0)
  302. end
  303. end
  304. --check for lava
  305. local success, data = turtle.inspectDown()
  306. if success then
  307. if string.find(data.name, "lava") then
  308. fuel(2)
  309. end
  310. end
  311. turtle.digDown()
  312. end
  313. --return up
  314. --print("atan=" , math.floor(2*math.atan2(curX+0.1,curZ+0.1)))
  315. while curY < -1 do
  316. turtle.select(2)
  317. Up()
  318. if (curY + math.floor(2*math.atan2(curX,curZ))) % 12 == 0 then
  319. setCobble(-1)
  320. elseif (curY + math.floor(2*math.atan2(curX,curZ))) % 12 == 11 then
  321. for i=1,4,1 do
  322. TRight()
  323. setCobble(0)
  324. end
  325. elseif buildWall > 0 and theta > maxradius*6.28 - 9 then
  326. --If we're on the last circuit and below the lava level
  327. setCobble(0)
  328. end
  329. end
  330. --place the cobbles at the top (YY=-1)
  331. for i=1,4,1 do
  332. TRight()
  333. setCobble(0)
  334. end
  335. Up()
  336. turtle.placeDown() --place a cobblestone in this location to mark it as done
  337. MoveTo(0,2,0)
  338. TurnTo(0)
  339. fuel()
  340. --Now empty all the slots into chests except leave the stones in the first one.
  341. Forward() --Move to above the chest.
  342. --first chest is just for picking up more empty buckets
  343. turtle.select(1) --the empty bucket slot
  344. turtle.suckDown(turtle.getItemSpace())
  345. --Second chest is to make sure we have cobblestone
  346. Forward()
  347. turtle.select(2) -- The cobblestone slot
  348. turtle.suckDown(turtle.getItemSpace())
  349. turtle.select(3) -- The cobblestone slot
  350. turtle.suckDown(turtle.getItemSpace())
  351. --now empty into the subsequent chests
  352. Forward()
  353. local done = 0
  354. local count = 20
  355. while done == 0 do
  356. done = 1
  357. for slot = 4,16,1 do
  358. turtle.select(slot)
  359. turtle.dropDown()
  360. if turtle.getItemCount(slot) >= 1 then
  361. done = 0
  362. end
  363. end
  364. if done == 0 then
  365. count = count + 1
  366. --print( 2*math.floor(count/10) ," ", curY," ", count % 10 +1 )
  367. MoveTo(2*math.floor(count/10) ,curY, count % 10 + 1)
  368. end
  369. end
  370. MoveTo(0,curY,0)
  371. turtle.select(2)
  372. end
  373.  
Add Comment
Please, Sign In to add comment