FlaserDog

Untitled

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