posicat

MinerFixed

Jul 16th, 2021 (edited)
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[Copyright PrinceTommen - Script developed for CyanideEpic (twitch.tv/cyanideepic)]]--
  2. --[[You are all allowed to use it as long as you don't pretend it's yours]]--
  3. --[[Have fun !]]--
  4. version =" 3.5"
  5. --[[
  6. Release Note:
  7. 3.5.1: Updated to add key checking because keys were being pressed multiple times (Posicat)
  8. 3.5: Added: Multiple item slots system, including the items to throw (suggested by Portsanta and CyanideEpic)
  9. Major interface enhancements to make the configuration faster in spite of the new options
  10. Enhanced item shortage security, supporting the multiple slots
  11. New functions to manage I/O in a more compact way (suggested by Niseg)
  12. 3.41: Fixed: Important glitch when the turtle returned to its starting position with a certain configuration
  13. Displaying issues
  14. 3.4: Added: Favorite configuration system
  15. Ability to choose the direction of the series of parallel tunnels (right or left)
  16. Support of execution without torches or chests (will not try to place them)
  17. Security that stops the turtle when it runs out of chests or torches (suggested by CyanideEpic)
  18. Chests and torches status updated automatically
  19. Security that requires the user to press enter before the turtle starts (suggested by CyanideEpic)
  20. The turtle now returns to its starting position after it finishes
  21. New rotation function as well a a specific torch placing function
  22. Fixed: The turtle will now properly finish the hub after mining an odd number of tunnels
  23. The torch placement has been modified to avoid conflicts with chests
  24. 3.3: Added: Enderchest Support (suggested by Niseg and Daniteh)
  25. Release note
  26. 3.2: Fixed: Very important chest placing issue (only appeared in 3.1)
  27. 3.1: Added: New mining pattern for more efficiency (suggested by Niseg)
  28. Smarter fuel management: Will now consume the "stored" fuel before refueling
  29. Can now consume any type of fuel supported by turtles (check the wiki)
  30. Fuel type can be changed while the turtle is mining
  31. Optimized the mining of 3 blocks high tunnels
  32. Better interface, instructions remain visible and a line is dedicated to the fuel status (updated automatically)
  33. Option to throw cobblestone automatically (suggested by Niseg)
  34. Fixed: Refueling issue in certain circumstances (reported by CyanideEpic)
  35. ]]--
  36. function resetScreen()
  37. term.clear()
  38. term.setCursorPos(14,1)
  39. write("Mining Turtle")
  40. term.setCursorPos(5,2)
  41. write("For CyanideEpic and his friends")
  42. term.setCursorPos(1,13)
  43. write("By PrinceTommen, version "..version)
  44. term.setCursorPos(1,4)
  45. end
  46. function textOutput(output_message, x_screen_pos, z_screen_pos, clear_area)
  47. term.setCursorPos(x_screen_pos,z_screen_pos)
  48. if clear_area == 0 then
  49. clear_area = string.len(output_message)
  50. end
  51. write(output_message..string.rep(" ", (clear_area - string.len(output_message))))
  52. end
  53. function securedInput(x_screen_pos, z_screen_pos, nature, lower_value, upper_value, example1, example2)
  54. example = {example1, example2}
  55. local function shortExample(example_int, example, boolStringPart)
  56. tableShortExample = {}
  57. tableShortExample[example_int] = example[example_int].." ("..string.sub(string.lower(example[example_int]), 1, 1)..") "
  58. if boolStringPart then
  59. return string.sub(string.lower(example[example_int]), 1, 1)
  60. else
  61. return tableShortExample[example_int]
  62. end
  63. end
  64. incipit = shortExample(1, example, false).."/ "..shortExample(2, example, false)..": "
  65. if nature == "text" then
  66. repeat
  67. textOutput(incipit, x_screen_pos, z_screen_pos, 39)
  68. term.setCursorPos(string.len(incipit)+1,z_screen_pos)
  69. user_input = string.sub(string.lower(read()), 1, 1)
  70. until (user_input == shortExample(1, example, true) or user_input == shortExample(2, example, true))
  71. elseif nature == "integer" then
  72. repeat
  73. textOutput(" ", x_screen_pos, z_screen_pos, (39 - x_screen_pos))
  74. term.setCursorPos(x_screen_pos,z_screen_pos)
  75. user_input = tonumber(read())
  76. until (user_input >= lower_value and user_input <= upper_value)
  77. end
  78. return user_input
  79. end
  80. function clearLines(firstLine, lastLine)
  81. a = 1
  82. for a=1, (lastLine-firstLine+1) do
  83. textOutput("", 1, (firstLine+a-1), 40)
  84. end
  85. end
  86. function convertToBool(var, boolTrue)
  87. if var == boolTrue then
  88. var = true
  89. else
  90. var = false
  91. end
  92. return var
  93. end
  94. function turn(FacingAngle, Bool_rotation, Rotation_integer)
  95. if Bool_rotation then
  96. for u=1, Rotation_integer do
  97. turtle.turnRight()
  98. end
  99. FacingAngle = FacingAngle + Rotation_integer
  100. else
  101. for u=1, Rotation_integer do
  102. turtle.turnLeft()
  103. end
  104. FacingAngle = FacingAngle - Rotation_integer
  105. end
  106. FacingAngle = math.abs((FacingAngle - 1)%4+1)
  107. return FacingAngle
  108. end
  109. local function refuel()
  110. turtle.select(torches_slots+current_slot[2])
  111. while not(turtle.refuel(1)) do
  112. for f=1, fuel_slots do
  113. current_slot[2], shortage[2] = rotateSlot(2, torches_slots+1, fuel_slots)
  114. turtle.select(torches_slots+current_slot[2])
  115. if turtle.refuel(1) then
  116. boolRefuel = true
  117. break
  118. else
  119. boolRefuel = false
  120. end
  121. end
  122. if not(boolRefuel) then
  123. textOutput("No Fuel -", 1, 11, 0)
  124. current_slot[2], shortage[2] = manageShortage(2, torches_slots+1, torches_slots+fuel_slots)
  125. end
  126. end
  127. refuel_count = 80 - turtle.getFuelLevel()
  128. textOutput("Fuel OK -", 1, 11, 0)
  129. return refuel_count
  130. end
  131. function moveForward(FacingAngle, Boolfb, moving_integer, digUpBool, digDownBool, refuel_count)
  132. local moving_count = 1
  133. for moving_count=1,moving_integer do
  134. if (refuel_count == 80) then
  135. refuel_count = refuel()
  136. end
  137. Bool1 = false
  138. while not(Bool1) do
  139. if (Boolfb) then
  140. turtle.dig()
  141. Bool1 = turtle.forward()
  142. if (digUpBool) then
  143. turtle.digUp()
  144. end
  145. if (digDownBool) then
  146. turtle.digDown()
  147. end
  148. else
  149. Bool1 = turtle.back()
  150. if not(Bool1) then
  151. turn(FacingAngle, true, 2)
  152. turtle.dig()
  153. turn(FacingAngle, false, 2)
  154. end
  155. end
  156. end
  157. moving_count = moving_count + 1
  158. refuel_count = refuel_count + 1
  159. end
  160. return refuel_count
  161. end
  162. function moveUp(Boolud, moving_integer, refuel_count, Bool_DigFront)
  163. local moving_count = 1
  164. for moving_count=1, moving_integer do
  165. if (refuel_count == 80) then
  166. refuel_count = refuel()
  167. end
  168. Bool2 = false
  169. if Bool_DigFront then
  170. turtle.dig()
  171. end
  172. while not(Bool2) do
  173. if (Boolud) then
  174. turtle.digUp()
  175. Bool2 = turtle.up()
  176. else
  177. turtle.digDown()
  178. Bool2 = turtle.down()
  179. end
  180. end
  181. moving_count = moving_count + 1
  182. refuel_count = refuel_count + 1
  183. end
  184. return refuel_count
  185. end
  186. function manageShortage(managedItem, initial_item_slot, final_item_slot)
  187. textOutput("The turtle has used all the "..(itemNames[managedItem+3]).." intitially given. Have you refilled all the "..(itemNames[managedItem+3]).." slots ?", 1, 4, 0)
  188. textOutput("Press enter if all the "..(itemNames[managedItem+3]).." slots are refilled (slots "..(initial_item_slot).." to "..(final_item_slot)..").", 1, 7, 0)
  189. repeat
  190. turn(FacingAngle, true, 4)
  191. os.startTimer(1)
  192. press, key = os.pullEvent()
  193. until (key == 257)
  194. clearLines(4,10)
  195. current_slot[managedItem] = 1
  196. shortage[managedItem] = false
  197. return current_slot[managedItem], shortage[managedItem]
  198. end
  199. function rotateSlot(managedItem, control_slot, rotation_controler)
  200. if (turtle.getItemCount(control_slot) == 0) or (managedItem == 2) then
  201. if current_slot[managedItem]==rotation_controler and (managedItem ~= 2) then
  202. shortage[managedItem] = true
  203. else
  204. current_slot[managedItem]=((current_slot[managedItem])%rotation_controler)+1
  205. end
  206. end
  207. return current_slot[managedItem], shortage[managedItem]
  208. end
  209. function inventoryManagement(refuel_count,Right_or_Left,throw_cobble)
  210. function fullInventory(n)
  211. n = m + 1
  212. repeat
  213. item_count = turtle.getItemCount(n)
  214. if (item_count ~= 0) then
  215. boolSlotOccupied = true
  216. n = n + 1
  217. else
  218. boolSlotOccupied = false
  219. end
  220. until (boolSlotOccupied == false) or (n == 17)
  221. return n
  222. end
  223. if Chest_approval then
  224. m = torches_slots + chests_slots + fuel_slots + garbage_slots
  225. thrown_slots = 0
  226. if (turtle.getItemCount(16) ~= 0) and (m~=16) then
  227. if fullInventory(m)==17 then
  228. if throw_stuff then
  229. for k=1, garbage_slots do
  230. for j=1, (16-m) do
  231. turtle.select(m - garbage_slots + k)
  232. Bool_match_stuff = turtle.compareTo(m+j)
  233. if Bool_match_stuff then
  234. thrown_slots = thrown_slots + 1
  235. turtle.select(m+j)
  236. turtle.drop()
  237. end
  238. end
  239. turtle.select(m - garbage_slots + k)
  240. turtle.drop(turtle.getItemCount(m - garbage_slots + k)-1)
  241. end
  242. for z = (m+1), 16 do
  243. for u = (z+1), 16 do
  244. if turtle.getItemCount(u)~=0 then
  245. turtle.select(u)
  246. turtle.transferTo(z)
  247. end
  248. end
  249. end
  250. end
  251. if not(throw_stuff) or ((thrown_slots <= 2) and (fullInventory(n)>15)) then
  252. if shortage[3] then
  253. textOutput("No Chests", 24, 11, 0)
  254. current_slot[3], shortage[3] = manageShortage(3, torches_slots+fuel_slots+1, torches_slots+fuel_slots+chests_slots)
  255. end
  256. textOutput("Chests OK", 24, 11, 0)
  257. if (Right_or_Left == "left") then
  258. FacingAngle = turn(FacingAngle, true, 1)
  259. else
  260. FacingAngle = turn(FacingAngle, false, 1)
  261. end
  262. refuel_count = moveForward(FacingAngle, true, 1, false, true, refuel_count)
  263. turtle.select(torches_slots+fuel_slots+current_slot[3])
  264. turtle.digDown()
  265. turtle.placeDown()
  266. for u=(m+1),16 do
  267. if turtle.getItemCount(u)~=0 then
  268. turtle.select(u)
  269. turtle.dropDown()
  270. end
  271. end
  272. if enderchest then
  273. turtle.select(torches_slots+fuel_slots+1)
  274. turtle.drop()
  275. turtle.digDown()
  276. end
  277. current_slot[3], shortage[3] = rotateSlot(3, torches_slots+fuel_slots+current_slot[3], chests_slots)
  278. refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
  279. if (Right_or_Left == "left") then
  280. FacingAngle = turn(FacingAngle, false, 1)
  281. else
  282. FacingAngle = turn(FacingAngle, true, 1)
  283. end
  284. end
  285. end
  286. end
  287. end
  288. turtle.select(1)
  289. return refuel_count
  290. end
  291. function placeTorch(Position)
  292. if Torch_approval then
  293. if shortage[1] then
  294. textOutput("No Torches -", 11, 11, 0)
  295. current_slot[1], shortage[1] = manageShortage(1, 1, torches_slots)
  296. end
  297. textOutput("Torches OK -", 11, 11, 0)
  298. turtle.select(current_slot[1])
  299. if Position == "front" then
  300. turtle.dig()
  301. turtle.place()
  302. elseif Position == "below" then
  303. turtle.digDown()
  304. turtle.placeDown()
  305. elseif Position == "up" then
  306. turtle.digUp()
  307. turtle.placeUp()
  308. end
  309. current_slot[1], shortage[1] = rotateSlot(1, current_slot[1], torches_slots)
  310. end
  311. end
  312. function digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, Bool_Torches, Right_or_Left)
  313. if Right_or_Left then
  314. Right_or_Left = "left"
  315. else
  316. Right_or_Left = "right"
  317. end
  318. done_columns = 0
  319. if (Height_Position == "up") then
  320. for columns=1, math.floor(Width/4) do
  321. turtle.digUp()
  322. if (Height > 3) then
  323. refuel_count = moveUp(true, 1, refuel_count, false)
  324. turtle.dig()
  325. refuel_count = moveUp(false, (Height-2), refuel_count, true)
  326. turtle.digDown()
  327. end
  328. refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
  329. refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
  330. if (Height > 3) then
  331. refuel_count = moveUp(false, 1, refuel_count, false)
  332. turtle.dig()
  333. refuel_count = moveUp(true, (Height-2), refuel_count, true)
  334. turtle.digUp()
  335. end
  336. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  337. done_columns = done_columns + 1
  338. if (Width - 4*done_columns ~= 0) then
  339. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  340. end
  341. end
  342. if ((Width - 4*math.floor(Width/4)) == 0) then
  343. Height_Position = "up"
  344. elseif ((Width - 4*math.floor(Width/4)) == 1) then
  345. turtle.digUp()
  346. refuel_count = moveUp(false, (Height-3), refuel_count, false)
  347. turtle.digDown()
  348. refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
  349. Height_Position = "down"
  350. elseif ((Width - 4*math.floor(Width/4)) >= 2) then
  351. if (Height > 3) then
  352. refuel_count = moveUp(true, 1, refuel_count, false)
  353. turtle.dig()
  354. refuel_count = moveUp(false, (Height-2), refuel_count, true)
  355. turtle.digDown()
  356. end
  357. turtle.digUp()
  358. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  359. refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
  360. Height_Position = "down"
  361. if ((Width - 4*math.floor(Width/4)) == 3) then
  362. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  363. refuel_count = moveUp(true, (Height - 3), refuel_count, false)
  364. turtle.digUp()
  365. Height_Position = "up"
  366. end
  367. end
  368. elseif (Height_Position == "down") then
  369. for columns=1, math.floor(Width/4) do
  370. turtle.digDown()
  371. if (Height > 3) then
  372. refuel_count = moveUp(false, 1, refuel_count, false)
  373. turtle.dig()
  374. refuel_count = moveUp(true, (Height - 2), refuel_count, true)
  375. turtle.digUp()
  376. end
  377. refuel_count = moveForward(FacingAngle, true, 2, true, true, refuel_count)
  378. if (Height > 3) then
  379. refuel_count = moveUp(true, 1, refuel_count, false)
  380. turtle.dig()
  381. refuel_count = moveUp(false, (Height - 2), refuel_count, true)
  382. turtle.digDown()
  383. end
  384. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  385. done_columns = done_columns + 1
  386. if (Width - 4*done_columns ~= 0) then
  387. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  388. end
  389. refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
  390. if (done_columns%2 == 0) and Bool_Torches then
  391. FacingAngle = turn(FacingAngle,true , 1)
  392. placeTorch("front")
  393. FacingAngle = turn(FacingAngle, false, 1)
  394. end
  395. end
  396. if ((Width - 4*math.floor(Width/4)) == 0) then
  397. Height_Position = "down"
  398. elseif ((Width - 4*math.floor(Width/4)) == 1) then
  399. turtle.digDown()
  400. refuel_count = moveUp(true, (Height - 3), refuel_count, false)
  401. turtle.digUp()
  402. Height_Position = "up"
  403. elseif ((Width - 4*math.floor(Width/4)) >= 2) then
  404. if (Height > 3) then
  405. refuel_count = moveUp(false, 1, refuel_count, false)
  406. turtle.dig()
  407. refuel_count = moveUp(true, (Height - 2), refuel_count, true)
  408. turtle.digUp()
  409. end
  410. turtle.digDown()
  411. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  412. Height_Position = "up"
  413. if ((Width - 4*math.floor(Width/4)) == 3) then
  414. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  415. refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  416. turtle.digDown()
  417. refuel_count = inventoryManagement(refuel_count, Right_or_Left, throw_cobble)
  418. Height_Position = "down"
  419. end
  420. end
  421. end
  422. return refuel_count, Height_Position
  423. end
  424.  
  425. enderchest, throw_stuff, Chest_approval, Torch_approval, Chest_mismatch, Torch_mismatch = false, false, false, false, false, false
  426. shortage, itemNames = {false, false, false}, {"torch", "fuel", "chest", "torches", "fuel", "chests"}
  427.  
  428. resetScreen()
  429. if (io.open("favorite", "r") ~= nil) then
  430. resetScreen()
  431. textOutput("Do you wish to use your favorite configuration ?", 1, 4, 0)
  432. Favorite_approval = securedInput(1, 6, "text", 0, 0, "Yes", "No")
  433. if (Favorite_approval == "y") then
  434. handle = fs.open("favorite", "r")
  435. input = handle.readAll()
  436. handle.close()
  437. favorite = textutils.unserialize(input)
  438. tunnels_integer = favorite.tunnels_integer
  439. Width = favorite.Width
  440. Height = favorite.Height
  441. Length = favorite.Length
  442. tunnels_separation = favorite.tunnels_separation
  443. throw_stuff = favorite.throw_stuff
  444. enderchest = favorite.enderchest
  445. Torch_approval = favorite.Torch_approval
  446. Chest_approval = favorite.Chest_approval
  447. end
  448. end
  449. if (io.open("favorite", "r") == nil) or ((io.open("favorite", "r") ~= nil) and (Favorite_approval == "n")) then
  450. resetScreen()
  451. textOutput("Number of parallel tunnels ? ", 1, 4, 0)
  452. tunnels_integer = securedInput(37, 4, "integer", 1, 1000, " ", " ")
  453. textOutput("Width of the tunnels ? ", 1, 5, 0)
  454. Width = securedInput(37, 5, "integer", 1, 1000, " ", " ")
  455. term.setCursorPos(1,6)
  456. textOutput("Height of the tunnels ? ", 1, 6, 0)
  457. Height = securedInput(37, 6, "integer", 1, 200, " ", " ")
  458. if (Height < 3) then
  459. Height = 3
  460. end
  461. term.setCursorPos(1,7)
  462. textOutput("Length of the tunnels ? ", 1, 7, 0)
  463. Length = securedInput(37, 7, "integer", 1, 100000, " ", " ")
  464. if (tunnels_integer > 1) then
  465. term.setCursorPos(1,8)
  466. textOutput("Separating blocks between tunnels ? ", 1, 8, 0)
  467. tunnels_separation = securedInput(37, 8, "integer", 1, 1000, " ", " ")
  468. else
  469. tunnels_separation = 0
  470. end
  471.  
  472. resetScreen()
  473. textOutput("To use regular chests, press c", 1, 4, 0)
  474. textOutput("To use an enderchest, press e", 1, 5, 0)
  475. textOutput("To use torches, press t", 1, 6, 0)
  476. textOutput("To throw away specific items, press p", 1, 7, 0)
  477. textOutput("Press enter once you have chosen all the options you wanted to activate.", 1, 11, 0)
  478. while true do
  479. press, key = os.pullEvent()
  480. if press == "key" and key == 257 then
  481. break
  482. elseif press == "key" and key == 67 then
  483. if Chest_approval then
  484. Chest_approval = false
  485. textOutput("", 10, 9, 11)
  486. else
  487. Chest_approval = true
  488. textOutput("Chests,", 10, 9, 11)
  489. end
  490. elseif press == "key" and key == 69 then
  491. if enderchest then
  492. enderchest = not(enderchest)
  493. textOutput("", 10, 9, 11)
  494. else
  495. Chest_approval = true
  496. enderchest = true
  497. textOutput("Enderchest,", 10, 9, 11)
  498. end
  499. elseif press == "key" and key == 84 then
  500. if Torch_approval then
  501. Torch_approval = false
  502. textOutput("", 1, 9, 8)
  503. else
  504. Torch_approval = true
  505. textOutput("Torches,", 1, 9, 8)
  506. end
  507. elseif press == "key" and key == 80 then
  508. if throw_stuff then
  509. throw_stuff = not(throw_stuff)
  510. textOutput("", 22, 9, 12)
  511. else
  512. throw_stuff = true
  513. textOutput("Throw items.", 22, 9, 12)
  514. end
  515. end
  516. end
  517. resetScreen()
  518.  
  519. textOutput("Do you want to save this configuration as your favorite ?", 1, 4, 0)
  520. New_favorite = securedInput(1, 6, "text", 0, 0, "Yes", "No")
  521.  
  522. if (New_favorite == "y") then
  523. favorite = {}
  524. favorite.tunnels_integer = tunnels_integer
  525. favorite.Width = Width
  526. favorite.Height = Height
  527. favorite.Length = Length
  528. favorite.tunnels_separation = tunnels_separation
  529. favorite.Torch_approval = Torch_approval
  530. favorite.Chest_approval = Chest_approval
  531. favorite.throw_stuff = throw_stuff
  532. favorite.enderchest = enderchest
  533. output = textutils.serialize(favorite)
  534. handle = fs.open("favorite", "w")
  535. handle.write(output)
  536. handle.close()
  537. end
  538. end
  539. resetScreen()
  540. textOutput("To manage extra slots, press s", 1, 4, 0)
  541. textOutput("This option allows you to have several torches/fuel/chests slots, as well as different items to throw", 1, 6, 0)
  542. textOutput("Else, press enter to skip this step.", 1, 10, 0)
  543. torches_slots, chests_slots, garbage_slots = 0, 0, 0
  544. while true do
  545. press, key = os.pullEvent()
  546. if press == "key" and key == 257 then
  547. fuel_slots = 1
  548. break
  549. elseif key == 83 then
  550. repeat
  551. turtle.select(1)
  552. resetScreen()
  553. textOutput("Number of fuel slots ? ", 1, 4, 0)
  554. fuel_slots = securedInput(29, 4, "integer", 1, 16, " ", " ")
  555. slot_total = fuel_slots
  556. if Torch_approval then
  557. textOutput("Number of torches slots ? ", 1, 5, 0)
  558. torches_slots = securedInput(29, 5, "integer", 1, 16, " ", " ")
  559. slot_total = slot_total + torches_slots
  560. end
  561. if Chest_approval and not(enderchest) then
  562. textOutput("Number of chests slots ? ", 1, 6, 0)
  563. chests_slots = securedInput(29, 6, "integer", 1, 16, " ", " ")
  564. slot_total = slot_total + chests_slots
  565. end
  566. if throw_stuff then
  567. textOutput("Number of undesired items ? ", 1, 7, 0)
  568. garbage_slots = securedInput(29, 7, "integer", 1, 16, " ", " ")
  569. slot_total = slot_total + garbage_slots
  570. end
  571. until (slot_total < 16)
  572. break
  573. end
  574. end
  575. resetScreen()
  576. if (tunnels_integer > 1) then
  577. textOutput("The first tunnel will be in front of the turtle. Do you want the tunnels to be dug on the right or on the left of the first tunnel (They will be parallel to the first one) ?", 1, 4, 0)
  578. Bool_direction = securedInput(1, 9, "text", 0, 0, "Right", "Left")
  579. end
  580. if (tunnels_integer == 1) and (Width > 1) then
  581. textOutput("In front of the turtle will be one side of the tunnel. Do you want it to mine the rest on the left or on the right ?", 1, 4, 0)
  582. Bool_direction = securedInput(1, 9, "text", 0, 0, "Right", "Left")
  583. end
  584. resetScreen()
  585. if Torch_approval then
  586. if torches_slots > 1 then
  587. textOutput("Torches in the slots 1 to "..torches_slots, 1, 4, 0)
  588. else
  589. torches_slots = 1
  590. textOutput("Torches in the slot 1", 1, 4, 0)
  591. end
  592. end
  593. if fuel_slots > 1 then
  594. textOutput("Fuel in the slots "..(torches_slots+1).." to "..(torches_slots+fuel_slots), 1, 5, 0)
  595. else
  596. fuel_slots = 1
  597. textOutput("Fuel in the slot "..(torches_slots+1), 1, 5, 0)
  598. end
  599. if Chest_approval and not(enderchest) then
  600. if chests_slots > 1 then
  601. textOutput("Chests in the slots "..(torches_slots+fuel_slots+1).." to "..(torches_slots+fuel_slots+chests_slots), 1, 6, 0)
  602. else
  603. chests_slots = 1
  604. textOutput("Chests in the slot "..(torches_slots+fuel_slots+1), 1, 6, 0)
  605. end
  606. end
  607. if enderchest then
  608. textOutput("The enderchest in the slot "..(torches_slots+fuel_slots+1), 1, 6, 0)
  609. chests_slots = 1
  610. end
  611. if throw_stuff then
  612. if garbage_slots > 1 then
  613. textOutput("Please make sure there are samples of the items to throw in the slots "..(torches_slots+fuel_slots+chests_slots+1).." to "..(torches_slots+fuel_slots+chests_slots+garbage_slots), 1, 8, 0)
  614. else
  615. garbage_slots = 1
  616. textOutput("Please make sure there is a sample of the item to throw in the slot "..(torches_slots+fuel_slots+chests_slots+1), 1, 8, 0)
  617. end
  618. end
  619. if (Bool_direction == "r") then
  620. Bool_direction = true
  621. else
  622. Bool_direction = false
  623. end
  624. textOutput("Press enter to start", 1, 11, 0)
  625. while true do
  626. press, key = os.pullEvent()
  627. if press == "key" and key == 257 then
  628. break
  629. end
  630. end
  631. resetScreen()
  632. textOutput("", 1, 11, 20)
  633. if Torch_approval and (turtle.getItemCount(1) == 0) then
  634. textOutput("The torches slot is empty. Are you sure you want to use torches ?", 1, 4, 0)
  635. Torch_approval = convertToBool(securedInput(1, 6, "text", 0, 0, "Yes", "No"), "y")
  636. elseif Torch_approval and (turtle.getItemCount(1) ~= 0) then
  637. for u = 1, torches_slots-1 do
  638. turtle.select(u+1)
  639. if not(turtle.compareTo(1)) then
  640. Torch_mismatch = true
  641. end
  642. end
  643. if Torch_mismatch then
  644. resetScreen()
  645. textOutput("All the slots dedicated to the torches have not been set up correctly. Are you sure you want to use torches ?", 1, 4, 0)
  646. Torch_approval = convertToBool(securedInput(1, 7, "text", 0, 0, "Yes", "No"), "y")
  647. end
  648. end
  649.  
  650. if Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) == 0) then
  651. resetScreen()
  652. textOutput("The chests slot is empty. Are you sure you want to use chests ?", 1, 4, 0)
  653. Chest_approval = convertToBool(securedInput(1, 6, "text", 0, 0, "Yes", "No"), "y")
  654. elseif Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) ~= 0) then
  655. for u = 1, chests_slots-1 do
  656. turtle.select(torches_slots + fuel_slots + u + 1)
  657. if not(turtle.compareTo(torches_slots + fuel_slots + 1)) then
  658. Chest_mismatch = true
  659. end
  660. end
  661. if Chest_mismatch then
  662. resetScreen()
  663. textOutput("All the slots dedicated to the chests have not been set up correctly. Are you sure you want to use chests ?", 1, 4, 0)
  664. Chest_approval = convertToBool(securedInput(1, 7, "text", 0, 0, "Yes", "No"), "y")
  665. end
  666. end
  667. if Torch_approval then
  668. empty_torches_slots = 0
  669. for u = 1, torches_slots do
  670. if turtle.getItemCount(u) == 0 then
  671. empty_torches_slots = empty_torches_slots + 1
  672. end
  673. end
  674. if empty_torches_slots == torches_slots then
  675. shortage[1] = true
  676. end
  677. textOutput("No Torches -", 11, 11, 0)
  678. end
  679. if Torch_approval and (turtle.getItemCount(1) ~= 0) then
  680. shortage[1] = false
  681. textOutput("Torches OK -", 11, 11, 0)
  682. end
  683. if Chest_approval then
  684. empty_chests_slots = 0
  685. for u = 1, chests_slots do
  686. if turtle.getItemCount(torches_slots + fuel_slots + u) == 0 then
  687. empty_chests_slots = empty_chests_slots + 1
  688. end
  689. end
  690. if empty_chests_slots == chests_slots then
  691. shortage[3] = true
  692. end
  693. textOutput("No Chests -", 24, 11, 0)
  694. end
  695. if Chest_approval and (turtle.getItemCount(torches_slots + fuel_slots + 1) ~= 0) then
  696. shortage[3] = false
  697. textOutput("Chests OK -", 24, 11, 0)
  698. end
  699. textOutput("Fuel OK -", 1, 11, 0)
  700. refuel_count = 80 - turtle.getFuelLevel()
  701. FacingAngle, tunnel_forth, current_slot= 0, true, {1, 1, 1}
  702. refuel_count = moveUp(true, 1, refuel_count, false)
  703. if (Width == 1) then
  704. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  705. end
  706. for done_tunnels=1, tunnels_integer do
  707. if (Width >= 2) then
  708. for done_layers=1, math.ceil(Length/2) do
  709. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  710. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  711. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, "down", false, Bool_direction)
  712. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  713. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  714. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  715. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, Width, Height, Height_Position, false, not(Bool_direction))
  716. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  717. if (done_layers%4 == 0) then
  718. refuel_count = moveUp(false, 1, refuel_count, false)
  719. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  720. placeTorch("front")
  721. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  722. refuel_count = moveUp(true, 1, refuel_count, false)
  723. end
  724. end
  725. elseif (Width == 1) then
  726. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, 2*math.ceil(Length/2), Height, "down", true, Bool_direction)
  727. end
  728. if (Height_Position == "up") then
  729. refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  730. Height_Position = "down"
  731. end
  732. if tunnel_forth and (tunnels_integer - done_tunnels >= 1) then
  733. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  734. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  735. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)+tunnels_separation), Height, "down", false, not(Bool_direction))
  736. if (Height_Position == "up") then
  737. refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  738. Height_Position = "down"
  739. end
  740. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  741. placeTorch("below")
  742. elseif not(tunnel_forth) then
  743. refuel_count = moveForward(FacingAngle, true, 1, true, false, refuel_count)
  744. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  745. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, "down", false, Bool_direction)
  746. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  747. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  748. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  749. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, ((2*Width)-1+tunnels_separation), Height, Height_Position, false, not(Bool_direction))
  750. if (Height_Position == "up") then
  751. refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  752. Height_Position = "down"
  753. end
  754. FacingAngle = turn(FacingAngle, Bool_direction, 2)
  755. refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
  756. placeTorch("front")
  757. FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
  758. refuel_count = moveForward(FacingAngle, true, (Width-2), true, true, refuel_count)
  759. if (tunnels_integer - done_tunnels ~= 0) then
  760. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  761. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, Bool_direction)
  762. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  763. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  764. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  765. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (tunnels_separation+1), Height, Height_Position, false, not(Bool_direction))
  766. refuel_count = moveForward(FacingAngle, false, tunnels_separation, true, true, refuel_count)
  767. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  768. placeTorch("front")
  769. FacingAngle = turn(FacingAngle, not(Bool_direction), 2)
  770. end
  771. end
  772. if tunnel_forth and (tunnels_integer - done_tunnels == 0) and (Width > 1) then
  773. refuel_count = moveForward(FacingAngle, false, 2*math.ceil(Length/2), false, false, refuel_count)
  774. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  775. refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
  776. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, Bool_direction)
  777. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  778. refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
  779. FacingAngle = turn(FacingAngle, Bool_direction, 1)
  780. refuel_count, Height_Position = digVerticalLayer(refuel_count, FacingAngle, (Width - 1), Height, Height_Position, false, not(Bool_direction))
  781. if (Height_Position == "up") then
  782. refuel_count = moveUp(false, (Height - 3), refuel_count, false)
  783. Height_Position = "down"
  784. end
  785. refuel_count = moveForward(FacingAngle, false, (Width - 2), false, false, refuel_count)
  786. FacingAngle = turn(FacingAngle, Bool_direction, 2)
  787. end
  788. if (Width == 1) and (tunnels_integer - done_tunnels ~= 0) then
  789. refuel_count = moveForward(FacingAngle, true, 1, true, true, refuel_count)
  790. elseif (Width == 1) and (tunnels_integer - done_tunnels == 0) and tunnel_forth then
  791. refuel_count = moveForward(FacingAngle, false, (2*math.ceil(Length/2)), false, false, refuel_count)
  792. end
  793. tunnel_forth = not(tunnel_forth)
  794. end
  795. refuel_count = moveUp(false, 1, refuel_count, false)
  796. if (Width == 1) and not(tunnel_forth) then
  797. refuel_count = moveForward(FacingAngle, false, 1, false, false, refuel_count)
  798. turn(FacingAngle, Bool_direction, 1)
  799. end
  800. refuel_count = moveForward(FacingAngle, false, ((tunnels_integer*Width) - 1 + (tunnels_separation*(tunnels_integer - 1))), false, false, refuel_count)
  801. FacingAngle = turn(FacingAngle, not(Bool_direction), 1)
  802. refuel_count = moveForward(FacingAngle, true, 1, false, false, refuel_count)
  803. resetScreen()
  804. write("Done. I hope I worked well !")
  805. term.setCursorPos(1,8)
Add Comment
Please, Sign In to add comment