Advertisement
Guest User

Untitled

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