Advertisement
Neyrods

Turtle Quarry Program for Computercraft

Sep 29th, 2023 (edited)
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Announcement: In an attempt to add a tunnel boring feature to this, I ended up breaking it so auto refueling no longer works. Version 2.0 is in the works (K6HvcJmD) but many features do not function and I'm taking a break from fixing it, but feel free to edit it if you'd like.
  2.  
  3. --Note: Computer craft has an issue where turtles will break if left in unloaded chunks, keep near the turtle or use a worldspike.
  4.  
  5. --This is version 1.2.4, updates will replace the current pastebin with the newer version once they're done!
  6. --Added a boring mode that mines a single layer, good for underground strip mining.
  7.  
  8. --How to use:
  9. --Place a chest to the left of the turtle for fuel and a chest behind it for a place to drop off items.
  10. --"Quarry or bore?" Type "quarry" for a quarry or "bore" to mine a single layer. Make sure you type in all lowercase.
  11. --"Rows" If looking from above, this is how many blocks it will mine in the 'y' axis.
  12. --"Columns" If looking from above, this is how many blocks it will mine in the 'x' axis.
  13. --"Current 'y' level?" The 'y' level of the turtle.
  14. --"Toss garbage blocks?" Type "yes" to toss out stone, gravel, dirt, etc. Make sure you type in all lowercase.
  15.  
  16. term.clear()
  17. term.setCursorPos(1,1)
  18. io.write("Quarry or bore? ")
  19. quarrybore = io.read()
  20. term.clear()
  21. term.setCursorPos(1,1)
  22. io.write("Rows: ")
  23. rows = io.read()
  24. io.write("Columns: ")
  25. columns = io.read()
  26. iniY = 2
  27. if quarrybore == "quarry" then
  28.     term.clear()
  29.     term.setCursorPos(1,1)
  30.     io.write("Current 'y' level: ")
  31.     iniY = io.read()
  32. end
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. io.write("Toss garbage blocks? ")
  36. tossGarbage = io.read()
  37. term.clear()
  38. term.setCursorPos(1,1)
  39.  
  40. posX = 0
  41. posY = 0
  42. posZ = 0
  43.  
  44. rotation = 0
  45.  
  46. fullSlots = 0
  47.  
  48. function info()
  49.     term.clear()
  50.     term.setCursorPos(1,1)
  51.     print("---------------------------------------")
  52.     print("Mining size: " .. rows .. " by " .. columns)
  53. --  print("Total distance: " .. posX + posY + posZ)
  54. --  print("X: " .. posX)
  55. --  print("Y: " .. posY)
  56. --  print("Z: " .. posZ)
  57. --  print("Orientation: " .. rotation)
  58.     if tossGarbage == "yes" then
  59.         print("Toss garbage: Yes")
  60.     else
  61.         print("Toss garbage: No")
  62.     end
  63.     print("")
  64.     print("Fuel level: " .. turtle.getFuelLevel())
  65. end
  66.  
  67. function rotate()
  68.     if rotation == 0 then
  69.         turtle.turnLeft()
  70.     elseif rotation == 1 then
  71.         turtle.turnLeft()
  72.         turtle.turnLeft()
  73.     elseif rotation == 2 then
  74.         turtle.turnRight()
  75.     end
  76. end
  77.  
  78. function recover()
  79.     rotate()
  80.     local step = 0
  81.     for step = posY - 1, 0, -1 do
  82.         turtle.up()
  83.     end
  84.     for step = posX - 1, 0, -1 do
  85.         turtle.forward()
  86.     end
  87.     turtle.turnLeft()
  88.     for step = posZ - 1, 0, -1 do
  89.         turtle.forward()
  90.     end
  91. end
  92.  
  93. function resume()
  94.     turtle.turnLeft()
  95.     turtle.turnLeft()
  96.     local step = 0
  97.     for step = 0, posZ - 1, 1 do
  98.         turtle.forward()
  99.     end
  100.     turtle.turnRight()
  101.     for step = 0, posX - 1, 1 do
  102.         turtle.forward()
  103.     end
  104.     for step = 0, posY - 1, 1 do
  105.         turtle.down()
  106.     end
  107.     if rotation == 0 then
  108.         turtle.turnLeft()
  109.     elseif rotation == 2 then
  110.         turtle.turnRight()
  111.     elseif rotation == 3 then
  112.         turtle.turnRight()
  113.         turtle.turnRight()
  114.     end
  115. end
  116.  
  117. function checkFuel()
  118.     turtle.select(1)
  119.     turtle.refuel()
  120.     if turtle.getFuelLevel() <= posX + posY + posZ + 1 then
  121.         refill = 1
  122.         empty()
  123.         refill = 0
  124.     end
  125. end
  126.  
  127. function empty()
  128.     recover()
  129.     if quarrybore == "bore" then
  130.         turtle.down()
  131.     end
  132.     local search = 0
  133.     for search = 16, 1, -1 do
  134.         turtle.select(search)
  135.         turtle.drop()
  136.     end
  137.     if refill == 1 then
  138.         turtle.turnRight()
  139.         while turtle.getFuelLevel() <= posX + posY + posZ + 1 do
  140.             if turtle.suck() == true then
  141.                 turtle.suck()
  142.                 turtle.select(1)
  143.                 turtle.refuel()
  144.             elseif turtle.suck() == false then
  145.                 turtle.select(1)
  146.                 turtle.refuel()
  147.                 term.clear()
  148.                 term.setCursorPos(1,1)
  149.                 io.write("Please add more fuel to slot '1' or fuel chest.")
  150.             end
  151.         end
  152.         turtle.turnLeft()
  153.         resume()
  154.     end
  155.     if done ~= 1 then
  156.         if quarrybore == "bore" then
  157.             turtle.up()
  158.         end
  159.         resume()
  160.     end
  161. end
  162.  
  163. function checkFull()
  164.     fullSlots = 0
  165.     local search = 0
  166.     for search = 16, 1, -1 do
  167.         turtle.select(search)
  168.         if turtle.getItemCount() > 0 then
  169.             if tossGarbage == "yes" then
  170.                 if turtle.getItemDetail().name == "minecraft:cobblestone" then
  171.                     turtle.drop()
  172.                 elseif turtle.getItemDetail().name == "minecraft:stone" then
  173.                     turtle.drop()
  174.                 elseif turtle.getItemDetail().name == "minecraft:dirt" then
  175.                     turtle.drop()
  176.                 elseif turtle.getItemDetail().name == "minecraft:gravel" then
  177.                     turtle.drop()
  178.                 elseif turtle.getItemDetail().name == "chisel:marble2" then
  179.                     turtle.drop()
  180.                 elseif turtle.getItemDetail().name == "chisel:limestone2" then
  181.                     turtle.drop()
  182.                 elseif turtle.getItemDetail().name == "minecraft:netherrack" then
  183.                     turtle.drop()
  184.                 elseif turtle.getItemDetail().name == "natura:nether_tainted_soil" then
  185.                     turtle.drop()
  186.                 elseif turtle.getItemDetail().name == "minecraft:andesite" then
  187.                     turtle.drop()
  188.                 elseif turtle.getItemDetail().name == "minecraft:granite" then
  189.                     turtle.drop()
  190.                 elseif turtle.getItemDetail().name == "regions_unexplored:argillite" then
  191.                     turtle.drop()
  192.                 elseif turtle.getItemDetail().name == "minecraft:clay_ball" then
  193.                     turtle.drop()
  194.                 elseif turtle.getItemDetail().name == "minecraft:diorite" then
  195.                     turtle.drop()
  196.                 end
  197.             end
  198.         end
  199.         if turtle.getItemCount() > 0 then
  200.             fullSlots = fullSlots + 1
  201.         end
  202.     end
  203.     if fullSlots == 16 then
  204.         empty()
  205.     end
  206. end
  207.  
  208. function nextRow()
  209.     if turn == 0 then
  210.         turtle.turnRight()
  211.         rotation = 1
  212.         digStraight()
  213.         turtle.turnRight()
  214.         rotation = 2
  215.         turn = 1
  216.     elseif turn == 1 then
  217.         turtle.turnLeft()
  218.         rotation = 1
  219.         digStraight()
  220.         turtle.turnLeft()
  221.         rotation = 0
  222.         turn = 0
  223.     elseif turn == 2 then
  224.         turtle.turnRight()
  225.         rotation = 3
  226.         digStraight()
  227.         turtle.turnRight()
  228.         rotation = 0
  229.         turn = 3
  230.     elseif turn == 3 then
  231.         turtle.turnLeft()
  232.         rotation = 3
  233.         digStraight()
  234.         turtle.turnLeft()
  235.         rotation = 2
  236.         turn = 2
  237.     end
  238. end
  239.  
  240. function digDown()
  241.     checkFuel()
  242.     local step = 0
  243.     for step = 2, 0, -1 do
  244.         turtle.digDown()
  245.         if turtle.down() == true then
  246.             posY = posY + 1
  247.         end
  248.         info()
  249.     end
  250. end
  251.  
  252. function digStraight()
  253.     checkFuel()
  254.     turtle.digDown()
  255.     turtle.dig()
  256.     turtle.dig()
  257.     turtle.forward()
  258.     if rotation == 0 then
  259.         posZ = posZ + 1
  260.     elseif rotation == 1 then
  261.         posX = posX + 1
  262.     elseif rotation == 2 then
  263.         posZ = posZ - 1
  264.     elseif rotation == 3 then
  265.         posX = posX - 1
  266.     end
  267.     turtle.digUp()
  268.     info()
  269. end
  270.  
  271. function quarry()
  272.     turn = 0
  273.     done = 0
  274.     iniY = tonumber (iniY)
  275.     checkFuel()
  276.     turtle.digUp()
  277.     turtle.up()
  278.     posY = posY - 1
  279.     while posY < iniY - 2 do
  280.         if quarrybore == "quarry" then
  281.             digDown()
  282.         end
  283.         for c = columns, 1, -1 do
  284.             for r = rows, 2, -1 do
  285.                 digStraight()
  286.             end
  287.             checkFull()
  288.             if c == 1 then
  289.                 turtle.turnRight()
  290.                 turtle.turnRight()
  291.                 if rotation == 0 then
  292.                     rotation = 2
  293.                 elseif rotation == 2 then
  294.                     rotation = 0
  295.                 end
  296.                 if turn == 0 then
  297.                     turn = 2
  298.                 elseif turn == 1 then
  299.                     turn = 3
  300.                 elseif turn == 2 then
  301.                     turn = 0
  302.                 elseif turn == 3 then
  303.                     turn = 1
  304.                 end
  305.             elseif c > 1 then
  306.                 nextRow()
  307.             end
  308.         end
  309.         if quarrybore == "bore" then
  310.             posY = posY + 1
  311.         end
  312.     end
  313.     turtle.digDown()
  314.     done = 1
  315.     empty()
  316.     term.clear()
  317.     term.setCursorPos(1,1)
  318.     print("Thank you for using Gambit's quarry program!")
  319.     print("---------------------------------------")
  320. end
  321.  
  322. quarry()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement