Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.19 KB | None | 0 0
  1. --This program will excavate in a 10x10 area
  2. --Starts from the bottom left
  3.  
  4. --Init
  5. local wide = 0
  6. local wideCount = 0
  7. local long = 0
  8. local longCount = 0
  9. local deep = 0
  10. local deepCount = 0
  11. local totalBlocks = 0
  12. local coalNeeded = 0
  13. local correct = n
  14. local xPos = 0
  15. local yPos = 0
  16. local zPos = 0
  17. local facing = 0 --right +, left -
  18. local initFace = 0
  19. -- Inventory: This Will Check At Start Code
  20. local chest = 0
  21. local fuelCount = 0
  22. local fuelCount1 = 0
  23. local noFuelNeed = 0 -- if Config is set to not use fuel, set = 1
  24. local error = 0 -- Error Code
  25. local reCheck = 0 -- Recheck Code
  26. -- Others
  27. local totalBlocks = 0
  28. local totalBlockDone = 0 -- How many Block Mined
  29. local LSorWS = 0 -- Go Left or Go Right This is for Wide Code
  30. local ALorAR = 0 -- align left Or align Right
  31. local processRaw = 0
  32. local process = 0
  33. local enderChest = 0 -- TODO
  34. local blockUp = 0 -- Fixing to Chest Probleem and moving probleem
  35. local processRaw = 0
  36. local process = 0
  37.  
  38. -- Checking
  39. local function check()
  40. if noFuelNeed == 0 then
  41. if fuelCount == 0 then
  42. print("Turtle has no fuel")
  43. print("Put fuel in Second and Thrid slot")
  44. error = 1
  45. else
  46. print("Turtle has Fuel")
  47. end
  48. if fuelCount1 == 0 then
  49. print("Turtle has no extra fuel but will run until empty")
  50. end
  51. end
  52. if chest == 0 then
  53. print("No chest in Turtle")
  54. print("Put chest in 1 slot")
  55. error = 1
  56. else
  57. print("Turtle has chest")
  58. end
  59. if error == 1 then
  60. print("Items are missing please try again")
  61. print("Turtle will recheck in 8 sec")
  62. end
  63. end
  64.  
  65. -- Recheck if user forget something turtle will check after 6 sec
  66. local function reCheck()
  67. chest = turtle.getItemCount(1)
  68. fuelCount = turtle.getItemCount(2)
  69. fuelCount1 = turtle.getItemCount(3)
  70. error = 0
  71. end
  72.  
  73. -- Chest Dump
  74. local function chestDump()
  75. if turtle.getItemCount(16)> 0 then -- If slot 16 in turtle has item slot 4 to 16 will go to chest
  76. initFace = facing % 4
  77.  
  78. repeat
  79. turtle.turnLeft()
  80. facing = facing - 1
  81. until facing % 4 == 3
  82.  
  83. while xPos < 0 do
  84. turtle.back()
  85. xPos = xPos + 1
  86. end
  87.  
  88. while xPos > 0 do
  89. turtle.forward()
  90. xPos = xPos - 1
  91. end
  92.  
  93.  
  94. repeat
  95. turtle.turnLeft()
  96. facing = facing - 1
  97. until facing % 4 == 2
  98.  
  99. while yPos < 0 do
  100. turtle.back()
  101. yPos = yPos + 1
  102. end
  103.  
  104. while yPos > 0 do
  105. turtle.forward()
  106. yPos = yPos - 1
  107. end
  108.  
  109.  
  110. while zPos < 0 do
  111. turtle.up()
  112. zPos = zPos + 1
  113. end
  114.  
  115.  
  116. for slot = 4, 16 do
  117. turtle.select(slot)
  118. sleep(0.6)
  119. turtle.dropUp()
  120. end
  121.  
  122. turtle.select(4)
  123.  
  124. repeat
  125. turtle.turnLeft()
  126. facing = facing - 1
  127. until facing % 4 == 1
  128.  
  129. while xPos < wideCount do
  130. turtle.forward()
  131. xPos = xPos + 1
  132. end
  133.  
  134. repeat
  135. turtle.turnLeft()
  136. facing = facing - 1
  137. until facing % 4 == 0
  138.  
  139. while yPos < longCount do
  140. turtle.forward()
  141. yPos = yPos + 1
  142. end
  143.  
  144. while zPos < deepCount do
  145. turtle.down()
  146. zPos = zPos - 1
  147. end
  148.  
  149. repeat
  150. turtle.turnLeft()
  151. facing = facing - 1
  152. until facing % 4 == initFace
  153. end
  154. end
  155.  
  156. -- Refuel
  157. local function refuel()
  158. if noFuelNeed == 0 then
  159. repeat
  160. if turtle.getFuelLevel() < 160 then
  161. if fuelCount > 0 then
  162. turtle.select(2)
  163. turtle.refuel(1)
  164. fuelCount = fuelCount - 1
  165. elseif fuelCount1 > 0 then
  166. turtle.select(3)
  167. turtle.refuel(1)
  168. fuelCount1 = fuelCount1 - 1
  169. else
  170. print("out of fuel")
  171. os.shutdown()
  172. end
  173. end
  174. until turtle.getFuelLevel() >= 160
  175. end
  176. end
  177.  
  178. local function mineLong()
  179. if turtle.detect() then
  180. turtle.dig()
  181. end
  182. if turtle.forward() then
  183. if facing % 4 == 0 then
  184. yPos = yPos + 1
  185. elseif facing % 4 == 1 then
  186. xPos = xPos + 1
  187. elseif facing % 4 == 2 then
  188. yPos = yPos - 1
  189. elseif facing % 4 == 3 then
  190. xPos = xPos - 1
  191. end
  192.  
  193. longCount = longCount + 1
  194. else
  195. repeat
  196. turtle.dig()
  197. sleep(0.6)
  198. if turtle.forward() then
  199. if facing % 4 == 0 then
  200. yPos = yPos + 1
  201. elseif facing % 4 == 1 then
  202. xPos = xPos + 1
  203. elseif facing % 4 == 2 then
  204. yPos = yPos - 1
  205. elseif facing % 4 == 3 then
  206. xPos = xPos - 1
  207. end
  208. blockUp = 0
  209. else
  210. blockUp = 1
  211. end
  212. until blockUp == 0
  213. longCount = longCount + 1
  214. print(totalBlocks - totalBlockDone)
  215. end
  216. if turtle.detectUp() then
  217. turtle.digUp()
  218. end
  219. if turtle.detectDown() then
  220. turtle.digDown()
  221. end
  222. totalBlockDone = totalBlockDone + 3
  223. end
  224.  
  225. local function wideMineLeft() -- TODO
  226. turtle.turnLeft()
  227. facing = facing - 1
  228. if turtle.detect() then
  229. turtle.dig()
  230. sleep(0.6) -- Minor bug fix if there is gravel
  231. end
  232. if turtle.forward() then
  233. if facing % 4 == 0 then
  234. yPos = yPos + 1
  235. elseif facing % 4 == 1 then
  236. xPos = xPos + 1
  237. elseif facing % 4 == 2 then
  238. yPos = yPos - 1
  239. elseif facing % 4 == 3 then
  240. xPos = xPos - 1
  241. end
  242. else
  243. repeat
  244. turtle.dig()
  245. sleep(0.6)
  246. if turtle.forward() then
  247. if facing % 4 == 0 then
  248. yPos = yPos + 1
  249. elseif facing % 4 == 1 then
  250. xPos = xPos + 1
  251. elseif facing % 4 == 2 then
  252. yPos = yPos - 1
  253. elseif facing % 4 == 3 then
  254. xPos = xPos - 1
  255. end
  256. blockUp = 0
  257. else
  258. blockUp = 1
  259. end
  260. until blockUp == 0
  261. end
  262. if turtle.detectUp() then
  263. turtle.digUp()
  264. end
  265. if turtle.detectDown() then
  266. turtle.digDown()
  267. end
  268. turtle.turnLeft()
  269. facing = facing - 1
  270. LSorWS = 0
  271. longCount = 0
  272. wideCount = wideCount + 1
  273. totalBlockDone = totalBlockDone + 3
  274. end
  275.  
  276. local function wideMineRight() -- TODO
  277. turtle.turnRight()
  278. facing = facing + 1
  279. if turtle.detect() then
  280. turtle.dig()
  281. sleep(0.6)
  282. end
  283. if turtle.forward() then
  284. if facing % 4 == 0 then
  285. yPos = yPos + 1
  286. elseif facing % 4 == 1 then
  287. xPos = xPos + 1
  288. elseif facing % 4 == 2 then
  289. yPos = yPos - 1
  290. elseif facing % 4 == 3 then
  291. xPos = xPos - 1
  292. end
  293. else
  294. repeat
  295. turtle.dig()
  296. sleep(0.6)
  297. if turtle.forward() then
  298. if facing % 4 == 0 then
  299. yPos = yPos + 1
  300. elseif facing % 4 == 1 then
  301. xPos = xPos + 1
  302. elseif facing % 4 == 2 then
  303. yPos = yPos - 1
  304. elseif facing % 4 == 3 then
  305. xPos = xPos - 1
  306. end
  307. blockUp = 0
  308. else
  309. blockUp = 1
  310. end
  311. until blockUp == 0
  312. end
  313. if turtle.detectUp() then
  314. turtle.digUp()
  315. end
  316. if turtle.detectDown() then
  317. turtle.digDown()
  318. end
  319. turtle.turnRight()
  320. facing = facing + 1
  321. LSorWS = 1
  322. longCount = 0
  323. wideCount = wideCount + 1
  324. totalBlockDone = totalBlockDone + 3
  325. end
  326.  
  327. local function deepMine()
  328. turtle.digDown()
  329. turtle.down()
  330. zPos = zPos - 1
  331. turtle.digDown()
  332. turtle.down()
  333. zPos = zPos - 1
  334. turtle.digDown()
  335. turtle.down()
  336. zPos = zPos - 1
  337. turtle.digDown()
  338. turtle.turnRight()
  339. facing = facing + 1
  340. turtle.turnRight()
  341. facing = facing + 1
  342. wideCount = 0
  343. longCount = 0
  344. deepCount = deepCount + 3
  345. totalBlockDone = totalBlockDone + 3
  346. end
  347.  
  348. local function main()
  349. repeat --Repeat for each level
  350. mineLong()
  351. refuel()
  352. chestDump()
  353. if longCount == long then
  354. if wideCount ~= wide then
  355. process = totalBlockDone / totalBlocks * 100
  356. processRaw = totalBlocks - totalBlockDone
  357. print("How Much Is Done: " .. math.floor(process+0.5) .. " %")
  358. print("TotalBlocks Still Need To Dig Is " .. processRaw)
  359. if LSorWS == 0 then
  360. wideMineRight()
  361. else
  362. wideMineLeft()
  363. end
  364. elseif wideCount >= wide then
  365. deepMine()
  366. end
  367. end
  368. until deepCount >= deep
  369. print("turtle is Done")
  370. end
  371.  
  372. local function firstDig()
  373. turtle.digDown()
  374. turtle.down()
  375. zPos = zPos - 1
  376. turtle.digDown()
  377. turtle.down()
  378. zPos = zPos - 1
  379. turtle.digDown()
  380. wideCount = 0
  381. longCount = 0
  382. totalBlockDone = totalBlockDone + 3
  383. end
  384.  
  385. local function start()
  386. print("Welcome To The Dig Turtle Program")
  387. print("Slot 1: Chest, Slot 2: Fuel, Slot 3: Fuel")
  388. print("How long(Length) do you want")
  389. input = io.read()
  390. long = tonumber(input)
  391. long = long - 1
  392. print("How wide(Width) do you want")
  393. input2 = io.read()
  394. wide = tonumber(input2)
  395. wide = wide - 1
  396. print("How Deep(Depth) do you Want")
  397. input3 = io.read()
  398. deep = tonumber(input3)
  399. print("Is This Correct?: Length = " .. (long + 1) .. " Width = " .. (wide + 1) .. " Depth = " .. (deep))
  400. print("Type Y if correct or N if incorrect")
  401. correct = io.read()
  402. if correct == n or N then
  403. os.reboot()
  404. end
  405. print("Okay Program Will Do Calculations")
  406. totalBlocks = (wide + 1) * (long + 1) * deep -- 1 is add because above it removed for wide and long code
  407. print("Total amount for block to mine is " .. totalBlocks)
  408. coalNeeded = totalBlocks / 3 / 80
  409. print("Total amount for Coal needed is " .. math.floor(coalNeeded+0.5))
  410. if turtle.getFuelLevel() == "unlimited" then
  411. print("Your turtle config does need fuel")
  412. noFuelNeed = 1
  413. elseif turtle.getFuelLevel() < 160 then
  414. turtle.select(2)
  415. turtle.refuel(2)
  416. end
  417. reCheck()
  418. check()
  419. if error == 1 then
  420. repeat
  421. sleep(6)
  422. reCheck()
  423. check()
  424. until error == 0
  425. end
  426. end
  427.  
  428. start()
  429. print("Turtle will now start!")
  430. turtle.select(1)
  431. turtle.placeUp()
  432. firstDig()
  433. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement