Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.17 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.  
  123. repeat
  124. turtle.turnLeft()
  125. facing = facing - 1
  126. until facing % 4 == 1
  127.  
  128. while xPos < wideCount do
  129. turtle.forward()
  130. xPos = xPos + 1
  131. end
  132.  
  133. repeat
  134. turtle.turnLeft()
  135. facing = facing - 1
  136. until facing % 4 == 0
  137.  
  138. while yPos < longCount do
  139. turtle.forward()
  140. yPos = yPos + 1
  141. end
  142.  
  143. while zPos < deepCount do
  144. turtle.down()
  145. zPos = zPos - 1
  146. end
  147.  
  148. repeat
  149. turtle.turnLeft()
  150. facing = facing - 1
  151. until facing % 4 == initFace
  152. end
  153. end
  154.  
  155. -- Refuel
  156. local function refuel()
  157. if noFuelNeed == 0 then
  158. repeat
  159. if turtle.getFuelLevel() < 160 then
  160. if fuelCount > 0 then
  161. turtle.select(2)
  162. turtle.refuel(1)
  163. fuelCount = fuelCount - 1
  164. elseif fuelCount1 > 0 then
  165. turtle.select(3)
  166. turtle.refuel(1)
  167. fuelCount1 = fuelCount1 - 1
  168. else
  169. print("out of fuel")
  170. os.shutdown()
  171. end
  172. end
  173. until turtle.getFuelLevel() >= 160
  174. end
  175. end
  176.  
  177. local function mineLong()
  178. if turtle.detect() then
  179. turtle.dig()
  180. end
  181. if turtle.forward() then
  182. if facing % 4 == 0 then
  183. yPos = yPos + 1
  184. elseif facing % 4 == 1 then
  185. xPos = xPos + 1
  186. elseif facing % 4 == 2 then
  187. yPos = yPos - 1
  188. elseif facing % 4 == 3 then
  189. xPos = xPos - 1
  190. end
  191.  
  192. longCount = longCount + 1
  193. else
  194. repeat
  195. turtle.dig()
  196. sleep(0.6)
  197. if turtle.forward() then
  198. if facing % 4 == 0 then
  199. yPos = yPos + 1
  200. elseif facing % 4 == 1 then
  201. xPos = xPos + 1
  202. elseif facing % 4 == 2 then
  203. yPos = yPos - 1
  204. elseif facing % 4 == 3 then
  205. xPos = xPos - 1
  206. end
  207. blockUp = 0
  208. else
  209. blockUp = 1
  210. end
  211. until blockUp == 0
  212. longCount = longCount + 1
  213. print(totalBlocks - totalBlockDone)
  214. end
  215. if turtle.detectUp() then
  216. turtle.digUp()
  217. end
  218. if turtle.detectDown() then
  219. turtle.digDown()
  220. end
  221. totalBlockDone = totalBlockDone + 3
  222. end
  223.  
  224. local function wideMineLeft() -- TODO
  225. turtle.turnLeft()
  226. facing = facing - 1
  227. if turtle.detect() then
  228. turtle.dig()
  229. sleep(0.6) -- Minor bug fix if there is gravel
  230. end
  231. if turtle.forward() then
  232. if facing % 4 == 0 then
  233. yPos = yPos + 1
  234. elseif facing % 4 == 1 then
  235. xPos = xPos + 1
  236. elseif facing % 4 == 2 then
  237. yPos = yPos - 1
  238. elseif facing % 4 == 3 then
  239. xPos = xPos - 1
  240. end
  241. else
  242. repeat
  243. turtle.dig()
  244. sleep(0.6)
  245. if turtle.forward() then
  246. if facing % 4 == 0 then
  247. yPos = yPos + 1
  248. elseif facing % 4 == 1 then
  249. xPos = xPos + 1
  250. elseif facing % 4 == 2 then
  251. yPos = yPos - 1
  252. elseif facing % 4 == 3 then
  253. xPos = xPos - 1
  254. end
  255. blockUp = 0
  256. else
  257. blockUp = 1
  258. end
  259. until blockUp == 0
  260. end
  261. if turtle.detectUp() then
  262. turtle.digUp()
  263. end
  264. if turtle.detectDown() then
  265. turtle.digDown()
  266. end
  267. turtle.turnLeft()
  268. facing = facing - 1
  269. LSorWS = 0
  270. longCount = 0
  271. wideCount = wideCount + 1
  272. totalBlockDone = totalBlockDone + 3
  273. end
  274.  
  275. local function wideMineRight() -- TODO
  276. turtle.turnRight()
  277. facing = facing + 1
  278. if turtle.detect() then
  279. turtle.dig()
  280. sleep(0.6)
  281. end
  282. if turtle.forward() then
  283. if facing % 4 == 0 then
  284. yPos = yPos + 1
  285. elseif facing % 4 == 1 then
  286. xPos = xPos + 1
  287. elseif facing % 4 == 2 then
  288. yPos = yPos - 1
  289. elseif facing % 4 == 3 then
  290. xPos = xPos - 1
  291. end
  292. else
  293. repeat
  294. turtle.dig()
  295. sleep(0.6)
  296. if turtle.forward() then
  297. if facing % 4 == 0 then
  298. yPos = yPos + 1
  299. elseif facing % 4 == 1 then
  300. xPos = xPos + 1
  301. elseif facing % 4 == 2 then
  302. yPos = yPos - 1
  303. elseif facing % 4 == 3 then
  304. xPos = xPos - 1
  305. end
  306. blockUp = 0
  307. else
  308. blockUp = 1
  309. end
  310. until blockUp == 0
  311. end
  312. if turtle.detectUp() then
  313. turtle.digUp()
  314. end
  315. if turtle.detectDown() then
  316. turtle.digDown()
  317. end
  318. turtle.turnRight()
  319. facing = facing + 1
  320. LSorWS = 1
  321. longCount = 0
  322. wideCount = wideCount + 1
  323. totalBlockDone = totalBlockDone + 3
  324. end
  325.  
  326. local function deepMine()
  327. turtle.digDown()
  328. turtle.down()
  329. zPos = zPos - 1
  330. turtle.digDown()
  331. turtle.down()
  332. zPos = zPos - 1
  333. turtle.digDown()
  334. turtle.down()
  335. zPos = zPos - 1
  336. turtle.digDown()
  337. turtle.turnRight()
  338. facing = facing + 1
  339. turtle.turnRight()
  340. facing = facing + 1
  341. wideCount = 0
  342. longCount = 0
  343. deepCount = deepCount + 3
  344. totalBlockDone = totalBlockDone + 3
  345. end
  346.  
  347. local function main()
  348. repeat --Repeat for each level
  349. mineLong()
  350. refuel()
  351. chestDump()
  352. if longCount == long then
  353. if wideCount ~= wide then
  354. process = totalBlockDone / totalBlocks * 100
  355. processRaw = totalBlocks - totalBlockDone
  356. print("How Much Is Done: " .. math.floor(process+0.5) .. " %")
  357. print("TotalBlocks Still Need To Dig Is " .. processRaw)
  358. if LSorWS == 0 then
  359. wideMineRight()
  360. else
  361. wideMineLeft()
  362. end
  363. elseif wideCount >= wide then
  364. deepMine()
  365. end
  366. end
  367. until deepCount >= deep
  368. print("turtle is Done")
  369. end
  370.  
  371. local function firstDig()
  372. turtle.digDown()
  373. turtle.down()
  374. zPos = zPos - 1
  375. turtle.digDown()
  376. turtle.down()
  377. zPos = zPos - 1
  378. turtle.digDown()
  379. wideCount = 0
  380. longCount = 0
  381. totalBlockDone = totalBlockDone + 3
  382. end
  383.  
  384. local function start()
  385. print("Welcome To The Dig Turtle Program")
  386. print("Slot 1: Chest, Slot 2: Fuel, Slot 3: Fuel")
  387. print("How long(Length) do you want")
  388. input = io.read()
  389. long = tonumber(input)
  390. long = long - 1
  391. print("How wide(Width) do you want")
  392. input2 = io.read()
  393. wide = tonumber(input2)
  394. wide = wide - 1
  395. print("How Deep(Depth) do you Want")
  396. input3 = io.read()
  397. deep = tonumber(input3)
  398. print("Is This Correct?: Length = " .. (long + 1) .. " Width = " .. (wide + 1) .. " Depth = " .. (deep))
  399. print("Type Y if correct or N if incorrect")
  400. correct = io.read()
  401. if correct == n or N then
  402. os.reboot()
  403. end
  404. print("Okay Program Will Do Calculations")
  405. totalBlocks = (wide + 1) * (long + 1) * deep -- 1 is add because above it removed for wide and long code
  406. print("Total amount for block to mine is " .. totalBlocks)
  407. coalNeeded = totalBlocks / 3 / 80
  408. print("Total amount for Coal needed is " .. math.floor(coalNeeded+0.5))
  409. if turtle.getFuelLevel() == "unlimited" then
  410. print("Your turtle config does need fuel")
  411. noFuelNeed = 1
  412. elseif turtle.getFuelLevel() < 160 then
  413. turtle.select(2)
  414. turtle.refuel(2)
  415. end
  416. reCheck()
  417. check()
  418. if error == 1 then
  419. repeat
  420. sleep(6)
  421. reCheck()
  422. check()
  423. until error == 0
  424. end
  425. end
  426.  
  427. start()
  428. print("Turtle will now start!")
  429. turtle.select(1)
  430. turtle.placeUp()
  431. firstDig()
  432. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement