Advertisement
Nesltay

Mining Turtle - New Quarry

Mar 15th, 2023 (edited)
914
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.53 KB | None | 0 0
  1. -- Turtle Position
  2. posX, posY, posZ = 0, 0, 0
  3. depth = 1
  4. startDepth = 0
  5.  
  6. -- Y-Level to stop At
  7. stopY = 0
  8.  
  9. -- Chest info
  10. cardinalChest = ""
  11.  
  12. -- Direction to mine
  13. turtleTurn = ""
  14.  
  15. -- Distance to mine
  16. length = 0
  17.  
  18. -- Amount of strips to mine
  19. width = 0
  20.  
  21. -- Torch & Line Count
  22. count = 0
  23. lineCount = 0
  24.  
  25. term.clear()
  26. print("Existing parameters include:")
  27. print("1) You must have the turtle and chest on one of the same axes.")
  28. print("2) The turtle must be moving in the same direction that the chest opens.")
  29. print("3) Place at least 1 coal in the 1st slot.")
  30. print("4) You must enter an even number for width.")
  31. print("---------------------------------------")
  32. local x = term.write("Press [Enter] to Continue")
  33. x = read()
  34. term.clear()
  35.  
  36.  
  37. -- term.write("What is the turtle's X? ")
  38. -- posX = read()
  39. -- term.write("What is the turtle's Z? ")
  40. -- posZ = read()
  41.  
  42. -- term.write("What is the chest's X? ")
  43. -- chestX = read()
  44. -- term.write("What is the chest's Z? ")
  45. -- chestZ = read()
  46.  
  47. term.write("Starting Y-Level: ")
  48. posY = tonumber(read())
  49.  
  50. term.write("Stopping Y-Level: ")
  51. stopY = tonumber(read())
  52.  
  53. term.write("Blocks beneath the chest? ")
  54. startDepth = read()
  55. if startDepth == nil or startDepth == '' then
  56.     startDepth = 0
  57. end
  58. depth = depth + startDepth
  59.  
  60. term.write("Which way do you want to mine? ")
  61. print("Enter 'r' or 'l'")
  62. turtleTurn = read()
  63. if turtleTurn == "r" then
  64.     cardinalChest = "l"
  65. else
  66.     cardinalChest = "r"
  67. end
  68.  
  69. term.write("Width: ")
  70. width = tonumber(read())
  71.  
  72. term.write("Length: ")
  73. length = tonumber(read()) - 1
  74.  
  75. function turnBack()
  76.     if turtleTurn == "r" then
  77.         turtle.turnRight()
  78.         turtle.dig()
  79.         turtle.forward()
  80.         turtle.digUp()
  81.         turtle.digDown()
  82.         turtle.turnRight()
  83.     else
  84.         turtle.turnLeft()
  85.         turtle.dig()
  86.         turtle.forward()
  87.         turtle.digUp()
  88.         turtle.digDown()
  89.         turtle.turnLeft()
  90.     end
  91. end
  92.  
  93. function turnForward()
  94.     if turtleTurn == "r" then
  95.         turtle.turnLeft()
  96.         turtle.dig()
  97.         turtle.forward()
  98.         turtle.digUp()
  99.         turtle.digDown()
  100.         turtle.turnLeft()
  101.     else
  102.         turtle.turnRight()
  103.         turtle.dig()
  104.         turtle.forward()
  105.         turtle.digUp()
  106.         turtle.digDown()
  107.         turtle.turnRight()
  108.     end
  109. end
  110.  
  111. function isAllthemodiumUp()
  112.     for i = 1, 5, 1 do
  113.         turtle.digUp()
  114.         turtle.up()
  115.     end
  116.     for i = 1, 5, 1 do
  117.         turtle.dig()
  118.         turtle.forward()
  119.     end
  120.     for i = 1, 5, 1 do
  121.         turtle.digDown()
  122.         turtle.down()
  123.     end
  124. end
  125.  
  126. function isAllthemodiumDown()
  127.     for i = 1, 5, 1 do
  128.         turtle.digDown()
  129.         turtle.down()
  130.     end
  131.     for i = 1, 5, 1 do
  132.         turtle.dig()
  133.         turtle.forward()
  134.     end
  135.     for i = 1, 5, 1 do
  136.         turtle.digUp()
  137.         turtle.up()
  138.     end
  139. end
  140.  
  141. function tunnel(extraDistance)
  142.     i = 0
  143.     print("extraDistance: ", extraDistance)
  144.     totalDistance = length + extraDistance
  145.     while i < totalDistance do
  146.         local isBlock, data = turtle.inspect()
  147.         if string.find(textutils.serialise(data.name), "allthemodium_ore") then
  148.             local isBlock, data = turtle.inspectUp()
  149.             if string.find(textutils.serialise(data.name), "allthemodium_ore") then
  150.                 isAllthemodiumDown()
  151.             else
  152.                 isAllthemodiumUp()
  153.             end
  154.             i = i + 5
  155.         else
  156.             turtle.dig()
  157.             turtle.forward()
  158.             i = i + 1
  159.         end
  160.         turtle.digUp()
  161.         turtle.digDown()
  162.     end
  163.     if i > length then
  164.         print("length - i", i - length)
  165.         return (i - length)
  166.     else
  167.         return 0
  168.     end
  169. end
  170.  
  171. function drop()
  172.     coal = turtle.getItemCount(1)
  173.     if coal > 1 then
  174.         halfCoal = math.floor(coal / 2)
  175.         turtle.drop(halfCoal)
  176.     end
  177.     for i=2, 16, 1 do
  178.         turtle.select(i)
  179.         turtle.drop()
  180.     end
  181. end
  182.  
  183. function moveForward()
  184.     while turtle.detect() == false do
  185.         turtle.forward()
  186.         turtleSteps = turtleSteps + 1
  187.     end
  188.     local isBlock, data = turtle.inspect()
  189.     if string.find(textutils.serialise(data.name), "chest") then
  190.         drop()
  191.     else
  192.         turtle.dig()
  193.         turtle.forward()
  194.         turtle.digUp()
  195.         turtleSteps = turtleSteps + 1
  196.         moveForward()
  197.     end
  198. end
  199.  
  200. function chest(width, depth)
  201.     turtleSteps = 0
  202.     if cardinalChest == "r" then
  203.         turtle.turnRight()
  204.     else
  205.         turtle.turnLeft()
  206.     end
  207.     for i=1, depth, 1 do
  208.         turtle.up()
  209.     end
  210.     moveForward()
  211.     if turtleSteps >= width - 1 then
  212.         if cardinalChest == "r" then
  213.             turtle.turnLeft()
  214.         else
  215.             turtle.turnRight()
  216.         end
  217.         for i=1, depth + 2, 1 do
  218.             turtle.digDown()
  219.             turtle.down()
  220.         end
  221.     else
  222.         for i=1, depth, 1 do
  223.             turtle.down()
  224.         end
  225.         turtle.turnRight()
  226.         turtle.turnRight()
  227.         for i=1, turtleSteps, 1 do
  228.             turtle.forward()
  229.         end
  230.         if cardinalChest == "r" then
  231.             turtle.turnRight()
  232.         else
  233.             turtle.turnLeft()
  234.         end
  235.     end
  236. end
  237.  
  238. function refuel()
  239.     turtle.select(1)
  240.     fuel = turtle.getItemCount(1)
  241.     if fuel > 1 then
  242.         turtle.refuel(fuel - 1)
  243.     end
  244.     local fuel = 0
  245.     local fuel = turtle.getFuelLevel()
  246.     print("Fuel remaining:")
  247.     print(fuel)
  248. end
  249.  
  250. timeStart = os.time("utc") * 3600
  251.  
  252. while true do
  253.     linesCompleted = 0
  254.     extraDistance = 0
  255.     turtle.digDown()
  256.     turtle.down()
  257.     turtle.digDown()
  258.     for i=1, (width / 2), 1 do
  259.         extraDistance = tunnel(extraDistance)
  260.         turnBack()
  261.         extraDistance = tunnel(extraDistance)
  262.         if linesCompleted ~= width - 2 then
  263.             turnForward()
  264.         else
  265.             turtle.turnLeft()
  266.             turtle.turnLeft()
  267.         end
  268.         linesCompleted = linesCompleted + 2
  269.     end
  270.     chest(width, depth)
  271.     refuel()
  272.     print("Currently on level: "..posY - 1)
  273.     depth = depth + 3
  274.     if posY <= stopY then
  275.         if cardinalChest == "r" then
  276.             turtle.turnRight()
  277.         else
  278.             turtle.turnLeft()
  279.         end
  280.         for i=1, depth, 1 do
  281.             turtle.up()
  282.         end
  283.         break
  284.     end
  285.     posY = posY - 3
  286. end
  287. timeEnd = os.time("utc") * 3600
  288. totalTime = math.ceil((timeEnd - timeStart) / 60)
  289. print("The turtle took: " .. totalTime .. " minutes to complete")
  290. print("Turtle has reached level -57 and completed the quarry")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement