Advertisement
LuckyToShoot

Untitled

Mar 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.93 KB | None | 0 0
  1. local startpos = vector.new(0, 0, 0)
  2. local toDig = 66
  3. local width = 31
  4. local length = 31
  5. local refuelLevel = 5000
  6. local sleepTime = 0.5
  7. local currentpos = vector.new(0, 0, 0)
  8. local fuelName = "minecraft:coal"
  9. local direction = 0
  10. local success = false
  11. local startDepth = 35
  12. local resume_x = 0
  13. local resume_z = 0
  14. local resume_y = 0
  15. local resume_direction = 0
  16. local turn = 0
  17. local breakTime = false
  18.  
  19. function debugPos()
  20. print("x: "..currentpos.x);
  21. print("y: "..currentpos.y);
  22. print("z: "..currentpos.z);
  23. end
  24.  
  25. function face(fDir)
  26. while(direction ~= fDir) do
  27. turtle.turnRight()
  28. sleep(sleepTime)
  29. direction = direction + 1
  30. if(direction > 3) then
  31. direction = direction - 4
  32. elseif(direction < 0) then
  33. direction = direction + 4
  34. end
  35. end
  36. end
  37.  
  38. function isEmpty()
  39. local i = 1
  40. i = 1
  41. while(i <= 16) do
  42. if(turtle.getItemCount(i) == 0) then
  43. return true
  44. end
  45. end
  46. if(i >= 16) then
  47. return false
  48. end
  49. end
  50.  
  51. function mRefuel(f_x)
  52. local i = 1
  53. while(turtle.getFuelLevel() < f_x) do
  54. face(3)
  55. turtle.suck(64)
  56. while(i < 17) do
  57. turtle.select(i)
  58. turtle.refuel()
  59. i = i + 1
  60. end
  61. turtle.select(1)
  62. i = 1
  63. print("Refuel Loop End")
  64. end
  65. face(0)
  66. print("Refueled")
  67. end
  68.  
  69. function checkCoal()
  70. if(turtle.getItemDetail(1).name == fuelName) then
  71. return turtle.getItemDetail(1).count
  72. else
  73. return 0
  74. end
  75. end
  76.  
  77. function updatePos()
  78. if(direction == 0) then
  79. currentpos.z = currentpos.z + 1
  80. elseif(direction == 1) then
  81. currentpos.x = currentpos.x + 1
  82. elseif(direction == 2) then
  83. currentpos.z = currentpos.z - 1
  84. elseif(direction == 3) then
  85. currentpos.x = currentpos.x - 1
  86. end
  87. end
  88.  
  89. function goHome()
  90. local home = false
  91. resume_x = currentpos.x
  92. resume_z = currentpos.z
  93. resume_direction = direction
  94. while(not home) do
  95. if(currentpos.x == 0 and currentpos.y == 0 and currentpos.z == 0) then
  96. home = true
  97. break
  98. end
  99.  
  100. while(currentpos.x ~= 0) do
  101. if(currentpos.x > 0) then
  102. if(direction ~= 3) then
  103. turtle.turnLeft()
  104. direction = direction - 1
  105. sleep(sleepTime)
  106. if(direction > 3) then
  107. direction = direction - 4
  108. elseif(direction < 0) then
  109. direction = direction + 4
  110. end
  111. end
  112.  
  113. if(direction == 3) then
  114. while(success == false) do
  115. success = turtle.forward()
  116. end
  117. success = false
  118. updatePos()
  119. sleep(sleepTime)
  120. end
  121.  
  122. elseif(currentpos.x < 0) then
  123. if(direction ~= 1) then
  124. turtle.turnLeft()
  125. direction = direction - 1
  126. sleep(sleepTime)
  127. if(direction > 3) then
  128. direction = direction - 4
  129. elseif(direction < 0) then
  130. direction = direction + 4
  131. end
  132. end
  133.  
  134. if(direction == 1) then
  135. while(success == false) do
  136. success = turtle.forward()
  137. end
  138. success = false
  139. updatePos()
  140. sleep(sleepTime)
  141. end
  142. end
  143. end
  144. print("x is 0")
  145. while(currentpos.z ~= 0) do
  146. if(currentpos.z > 0) then
  147. if(direction ~= 2) then
  148. turtle.turnLeft()
  149. direction = direction - 1
  150. sleep(sleepTime)
  151. if(direction > 3) then
  152. direction = direction - 4
  153. elseif(direction < 0) then
  154. direction = direction + 4
  155. end
  156. end
  157.  
  158. if(direction == 2) then
  159. while(success == false) do
  160. success = turtle.forward()
  161. end
  162. success = false
  163. updatePos()
  164. sleep(sleepTime)
  165. end
  166.  
  167. elseif(currentpos.z < 0) then
  168. if(direction ~= 0) then
  169. turtle.turnLeft()
  170. direction = direction - 1
  171. sleep(sleepTime)
  172. if(direction > 3) then
  173. direction = direction - 4
  174. elseif(direction < 0) then
  175. direction = direction + 4
  176. end
  177. end
  178.  
  179. if(direction == 0) then
  180. while(success == false) do
  181. success = turtle.forward()
  182. end
  183. success = false
  184. updatePos()
  185. sleep(sleepTime)
  186. end
  187. end
  188. end
  189. print("z is 0")
  190. home = true
  191. while(direction ~= 0) do
  192. turtle.turnLeft()
  193. sleep(sleepTime)
  194. direction = direction - 1
  195. if(direction > 3) then
  196. direction = direction - 4
  197. elseif(direction < 0) then
  198. direction = direction + 4
  199. end
  200. end
  201. end
  202. face(0)
  203. end
  204.  
  205. function yHome()
  206. resume_y = currentpos.y
  207. while(currentpos.y ~= 0) do
  208. if(currentpos.y > 0) then
  209. while(success == false) do
  210. success = turtle.up()
  211. sleep(sleepTime)
  212. end
  213. success = false
  214. currentpos.y = currentpos.y - 1
  215. end
  216. if(currentpos.y < 0) then
  217. while(success == false) do
  218. success = turtle.down()
  219. sleep(sleepTime)
  220. end
  221. success = false
  222. currentpos.y = currentpos.y + 1
  223. end
  224. end
  225. print("I am home")
  226. end
  227.  
  228. function resume()
  229. while(currentpos.y < resume_y) do
  230. success = turtle.down()
  231. if(success) then
  232. currentpos.y = currentpos.y + 1
  233. end
  234. success = false
  235. sleep(sleepTime)
  236. if(currentpos.y >= resume_y) then
  237. currentpos.y = resume_y
  238. end
  239. end
  240.  
  241. while(currentpos.x < resume_x) do
  242. face(1)
  243. success = turtle.forward()
  244. if(success) then
  245. currentpos.x = currentpos.x + 1
  246. end
  247. success = false
  248. sleep(sleepTime)
  249. if(currentpos.x >= resume_x) then
  250. currentpos.x = resume_x
  251. end
  252. end
  253.  
  254. while(currentpos.z < resume_z) do
  255. face(0)
  256. success = turtle.forward()
  257. if(success) then
  258. currentpos.z = currentpos.z + 1
  259. end
  260. success = false
  261. sleep(sleepTime)
  262. if(currentpos.z >= resume_z) then
  263. currentpos.z = resume_z
  264. end
  265. end
  266. face(resume_direction)
  267. end
  268.  
  269. function Forward()
  270. success = turtle.forward()
  271. sleep(sleepTime)
  272. while(not success) do
  273. turtle.dig()
  274. sleep(sleepTime)
  275. success = turtle.forward()
  276. sleep(sleepTime)
  277. end
  278. success = false
  279. end
  280. function Down()
  281. success = turtle.down()
  282. sleep(sleepTime)
  283. while(not success) do
  284. turtle.digDown()
  285. sleep(sleepTime)
  286. success = turtle.down()
  287. sleep(sleepTime)
  288. end
  289. success = false
  290. end
  291. function TurnRight()
  292. turtle.turnRight()
  293. sleep(sleepTime)
  294. direction = direction + 1
  295. if(direction > 3) then
  296. direction = direction - 4
  297. elseif(direction < 0) then
  298. direction = direction + 4
  299. end
  300. end
  301. function TurnLeft()
  302. turtle.turnLeft()
  303. sleep(sleepTime)
  304. direction = direction - 1
  305. if(direction > 3) then
  306. direction = direction - 4
  307. elseif(direction < 0) then
  308. direction = direction + 4
  309. end
  310. end
  311. function MineCurrentLayer()
  312. breakTime = false
  313. turn = 0
  314. while(currentpos.x < width) do
  315. if(turn == 0) then
  316. while(currentpos.z < length - 1) do
  317. turtle.digDown()
  318. Forward()
  319. updatePos()
  320. end
  321. elseif(turn == 1)then
  322. while(currentpos.z > 0) do
  323. turtle.digDown()
  324. Forward()
  325. updatePos()
  326. end
  327. end
  328. turtle.digDown()
  329. sleep(sleepTime)
  330.  
  331. --Break Time
  332. dropCobble()
  333. breakTime = isEmpty()
  334. if(turtle.getFuelLevel() < (refuelLevel/2) or (not breakTime))then
  335. goHome()
  336. yHome()
  337. face(2)
  338. dropAll()
  339. face(0)
  340. mRefuel(refuelLevel)
  341. resume()
  342. end
  343. --Break Time End
  344.  
  345. --Turn Corner to next strip
  346. if(turn == 0) then
  347. TurnRight()
  348. elseif(turn == 1) then
  349. TurnLeft()
  350. end
  351. if(currentpos.x == width - 1) then
  352. break
  353. end
  354. if(currentpos.x < width - 1) then
  355. Forward()
  356. updatePos()
  357. end
  358. turtle.digDown()
  359. sleep(sleepTime)
  360. if(turn == 0) then
  361. TurnRight()
  362. elseif(turn == 1) then
  363. TurnLeft()
  364. end
  365. if(turn == 0) then
  366. turn = 1
  367. elseif(turn == 1) then
  368. turn = 0
  369. end
  370. --End of turning corner
  371. end
  372. end
  373. function dropCobble()
  374. local i = 1
  375. while(i < 17) do
  376. turtle.select(i)
  377. if(turtle.getItemCount() > 0)then
  378. if(turtle.getItemDetail().name == "minecraft:cobblestone") then
  379. turtle.drop()
  380. end
  381. end
  382. if(turtle.getItemCount() > 0)then
  383. if(turtle.getItemDetail().name == "minecraft:dirt") then
  384. turtle.drop()
  385. end
  386. end
  387. if(turtle.getItemCount() > 0)then
  388. if(turtle.getItemDetail().name == "minecraft:gravel") then
  389. turtle.drop()
  390. end
  391. end
  392. i = i + 1
  393. end
  394. turtle.select(1)
  395. end
  396. function dropAll()
  397. local i = 1
  398. while(i < 17) do
  399. turtle.select(i)
  400. turtle.drop()
  401. i = i + 1
  402. end
  403. end
  404.  
  405. function GoDepth()
  406. while(currentpos.y < startDepth) do
  407. Down()
  408. currentpos.y = currentpos.y + 1
  409. print("Down")
  410. end
  411. print("I am there")
  412. end
  413.  
  414. function startMine()
  415. print("Start mining operation")
  416. while(currentpos.y < toDig) do
  417. MineCurrentLayer()
  418. goHome()
  419. Down()
  420. currentpos.y = currentpos.y + 1
  421. sleep(sleepTime)
  422. end
  423. end
  424.  
  425. mRefuel(refuelLevel)
  426. GoDepth(startDepth)
  427. startMine()
  428. goHome()
  429. yHome()
  430. face(2)
  431. dropAll()
  432. debugPos()
  433. sleep(5)
  434. goHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement