Advertisement
steellz

Gambit's Turtle Quarry Program for Computercraft

Aug 12th, 2023 (edited)
3,157
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. end
  65.  
  66. function rotate()
  67.     if rotation == 0 then
  68.         turtle.turnLeft()
  69.     elseif rotation == 1 then
  70.         turtle.turnLeft()
  71.         turtle.turnLeft()
  72.     elseif rotation == 2 then
  73.         turtle.turnRight()
  74.     end
  75. end
  76.  
  77. function recover()
  78.     rotate()
  79.     local step = 0
  80.     for step = posY - 1, 0, -1 do
  81.         turtle.up()
  82.     end
  83.     for step = posX - 1, 0, -1 do
  84.         turtle.forward()
  85.     end
  86.     turtle.turnLeft()
  87.     for step = posZ - 1, 0, -1 do
  88.         turtle.forward()
  89.     end
  90. end
  91.  
  92. function resume()
  93.     turtle.turnLeft()
  94.     turtle.turnLeft()
  95.     local step = 0
  96.     for step = 0, posZ - 1, 1 do
  97.         turtle.forward()
  98.     end
  99.     turtle.turnRight()
  100.     for step = 0, posX - 1, 1 do
  101.         turtle.forward()
  102.     end
  103.     for step = 0, posY - 1, 1 do
  104.         turtle.down()
  105.     end
  106.     if rotation == 0 then
  107.         turtle.turnLeft()
  108.     elseif rotation == 2 then
  109.         turtle.turnRight()
  110.     elseif rotation == 3 then
  111.         turtle.turnRight()
  112.         turtle.turnRight()
  113.     end
  114. end
  115.  
  116. function empty()
  117.     recover()
  118.     if quarrybore == "bore" then
  119.         turtle.down()
  120.     end
  121.     local search = 0
  122.     for search = 16, 1, -1 do
  123.         turtle.select(search)
  124.         turtle.drop()
  125.     end
  126.    
  127.         end
  128.         turtle.turnLeft()
  129.         resume()
  130.    
  131.     if done ~= 1 then
  132.         if quarrybore == "bore" then
  133.             turtle.up()
  134.         end
  135.         resume()
  136.     end
  137.  
  138. function checkFull()
  139.     fullSlots = 0
  140.     local search = 0
  141.     for search = 16, 1, -1 do
  142.         turtle.select(search)
  143.         if turtle.getItemCount() > 0 then
  144.             if tossGarbage == "yes" then
  145.                 if turtle.getItemDetail().name == "minecraft:cobblestone" then
  146.                     turtle.drop()
  147.                 elseif turtle.getItemDetail().name == "minecraft:stone" then
  148.                     turtle.drop()
  149.                 elseif turtle.getItemDetail().name == "minecraft:dirt" then
  150.                     turtle.drop()
  151.                 elseif turtle.getItemDetail().name == "minecraft:gravel" then
  152.                     turtle.drop()
  153.                 elseif turtle.getItemDetail().name == "chisel:marble2" then
  154.                     turtle.drop()
  155.                 elseif turtle.getItemDetail().name == "chisel:limestone2" then
  156.                     turtle.drop()
  157.                 elseif turtle.getItemDetail().name == "minecraft:netherrack" then
  158.                     turtle.drop()
  159.                 elseif turtle.getItemDetail().name == "natura:nether_tainted_soil" then
  160.                     turtle.drop()
  161.                 end
  162.             end
  163.         end
  164.         if turtle.getItemCount() > 0 then
  165.             fullSlots = fullSlots + 1
  166.         end
  167.     end
  168.     if fullSlots == 16 then
  169.         empty()
  170.     end
  171. end
  172.  
  173. function nextRow()
  174.     if turn == 0 then
  175.         turtle.turnRight()
  176.         rotation = 1
  177.         digStraight()
  178.         turtle.turnRight()
  179.         rotation = 2
  180.         turn = 1
  181.     elseif turn == 1 then
  182.         turtle.turnLeft()
  183.         rotation = 1
  184.         digStraight()
  185.         turtle.turnLeft()
  186.         rotation = 0
  187.         turn = 0
  188.     elseif turn == 2 then
  189.         turtle.turnRight()
  190.         rotation = 3
  191.         digStraight()
  192.         turtle.turnRight()
  193.         rotation = 0
  194.         turn = 3
  195.     elseif turn == 3 then
  196.         turtle.turnLeft()
  197.         rotation = 3
  198.         digStraight()
  199.         turtle.turnLeft()
  200.         rotation = 2
  201.         turn = 2
  202.     end
  203. end
  204.  
  205. function digDown()
  206.     local step = 0
  207.     for step = 2, 0, -1 do
  208.         turtle.digDown()
  209.         if turtle.down() == true then
  210.             posY = posY + 1
  211.         end
  212.         info()
  213.     end
  214. end
  215.  
  216. function digStraight()
  217.     turtle.digDown()
  218.     turtle.dig()
  219.     turtle.dig()
  220.     turtle.forward()
  221.     if rotation == 0 then
  222.         posZ = posZ + 1
  223.     elseif rotation == 1 then
  224.         posX = posX + 1
  225.     elseif rotation == 2 then
  226.         posZ = posZ - 1
  227.     elseif rotation == 3 then
  228.         posX = posX - 1
  229.     end
  230.     turtle.digUp()
  231.     info()
  232. end
  233.  
  234. function quarry()
  235.     turn = 0
  236.     done = 0
  237.     iniY = tonumber (iniY)
  238.     turtle.digUp()
  239.     turtle.up()
  240.     posY = posY - 1
  241.     while posY < iniY - 2 do
  242.         if quarrybore == "quarry" then
  243.             digDown()
  244.         end
  245.         for c = columns, 1, -1 do
  246.             for r = rows, 2, -1 do
  247.                 digStraight()
  248.             end
  249.             checkFull()
  250.             if c == 1 then
  251.                 turtle.turnRight()
  252.                 turtle.turnRight()
  253.                 if rotation == 0 then
  254.                     rotation = 2
  255.                 elseif rotation == 2 then
  256.                     rotation = 0
  257.                 end
  258.                 if turn == 0 then
  259.                     turn = 2
  260.                 elseif turn == 1 then
  261.                     turn = 3
  262.                 elseif turn == 2 then
  263.                     turn = 0
  264.                 elseif turn == 3 then
  265.                     turn = 1
  266.                 end
  267.             elseif c > 1 then
  268.                 nextRow()
  269.             end
  270.         end
  271.         if quarrybore == "bore" then
  272.             posY = posY + 1
  273.         end
  274.     end
  275.     turtle.digDown()
  276.     done = 1
  277.     empty()
  278.     term.clear()
  279.     term.setCursorPos(1,1)
  280.     print("Thank you for using Gambit's quarry program!")
  281.     print("---------------------------------------")
  282. end
  283.  
  284. quarry()
Tags: Rowquarry
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement