AlexanderHaffer

Quarry [edited]

Jun 18th, 2021 (edited)
1,360
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Created by: pastebin.com/u/Gamboodle
  2. --Edited by:  pastebin.com/u/AlexanderHaffer
  3. --Version:    1.2.4 e2
  4.  
  5. term.clear()
  6. term.setCursorPos(1,1)
  7. print("Please ensure that the turtle has enough fuel!")
  8. print("Current fuel level: " .. turtle.getFuelLevel())
  9. print("Maximum fuel levels are 20k for a regular and 100k for a mining turtle.")
  10. sleep(5)
  11. term.clear()
  12. term.setCursorPos(1,1)
  13. io.write("Select 'quarry' or 'bore': ")
  14. quarrybore = io.read()
  15. term.clear()
  16. term.setCursorPos(1,1)
  17. io.write("Blocks forward: ")
  18. rows = io.read()
  19. io.write("Blocks sideways: ")
  20. columns = io.read()
  21. iniY = 2
  22. limitY = 5
  23. if quarrybore == "quarry" then
  24.     term.clear()
  25.     term.setCursorPos(1,1)
  26.     io.write("Current 'y' level: ")
  27.     iniY = io.read()
  28.     term.clear()
  29.     term.setCursorPos(1,1)
  30.     io.write("Lowest 'y' level: ")
  31.     limitY = io.read()
  32. end
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. io.write("Toss garbage blocks like Cobblestone?")
  36. io.write("Select 'yes' or 'no': ")
  37. tossGarbage = io.read()
  38. term.clear()
  39. term.setCursorPos(1,1)
  40.  
  41. posX = 0
  42. posY = 0
  43. posZ = 0
  44.  
  45. rotation = 0
  46.  
  47. fullSlots = 0
  48.  
  49. function info()
  50.     term.clear()
  51.     term.setCursorPos(1,1)
  52.     print("---------------------------------------")
  53.     print("Mining size: " .. rows .. " by " .. columns)
  54.     print("Mining down to level " .. limitY)
  55. --  print("Total distance: " .. posX + posY + posZ)
  56. --  print("X: " .. posX)
  57. --  print("Y: " .. posY)
  58. --  print("Z: " .. posZ)
  59. --  print("Orientation: " .. rotation)
  60.     if tossGarbage == "yes" then
  61.         print("Tossing garbage.")
  62.     else
  63.         print("Keeping garbage.")
  64.     end
  65.     print("")
  66.     print("Fuel level: " .. turtle.getFuelLevel())
  67. end
  68.  
  69. function rotate()
  70.     if rotation == 0 then
  71.         turtle.turnLeft()
  72.     elseif rotation == 1 then
  73.         turtle.turnLeft()
  74.         turtle.turnLeft()
  75.     elseif rotation == 2 then
  76.         turtle.turnRight()
  77.     end
  78. end
  79.  
  80. function recover()
  81.     rotate()
  82.     local step = 0
  83.     for step = posY - 1, 0, -1 do
  84.         turtle.up()
  85.     end
  86.     for step = posX - 1, 0, -1 do
  87.         turtle.forward()
  88.     end
  89.     turtle.turnLeft()
  90.     for step = posZ - 1, 0, -1 do
  91.         turtle.forward()
  92.     end
  93. end
  94.  
  95. function resume()
  96.     turtle.turnLeft()
  97.     turtle.turnLeft()
  98.     local step = 0
  99.     for step = 0, posZ - 1, 1 do
  100.         turtle.forward()
  101.     end
  102.     turtle.turnRight()
  103.     for step = 0, posX - 1, 1 do
  104.         turtle.forward()
  105.     end
  106.     for step = 0, posY - 1, 1 do
  107.         turtle.down()
  108.     end
  109.     if rotation == 0 then
  110.         turtle.turnLeft()
  111.     elseif rotation == 2 then
  112.         turtle.turnRight()
  113.     elseif rotation == 3 then
  114.         turtle.turnRight()
  115.         turtle.turnRight()
  116.     end
  117. end
  118.  
  119. function checkFuel()
  120.     turtle.select(1)
  121.     turtle.refuel()
  122.     if turtle.getFuelLevel() <= posX + posY + posZ + 1 then
  123.         refill = 1
  124.         empty()
  125.         refill = 0
  126.     end
  127. end
  128.  
  129. function empty()
  130.     recover()
  131.     if quarrybore == "bore" then
  132.         turtle.down()
  133.     end
  134.     local search = 0
  135.     for search = 16, 1, -1 do
  136.         turtle.select(search)
  137.         turtle.drop()
  138.     end
  139.     if refill == 1 then
  140.         turtle.turnRight()
  141.         while turtle.getFuelLevel() <= posX + posY + posZ + 1 do
  142.             if turtle.suck() == true then
  143.                 turtle.suck()
  144.                 turtle.select(1)
  145.                 turtle.refuel()
  146.             elseif turtle.suck() == false then
  147.                 turtle.select(1)
  148.                 turtle.refuel()
  149.                 term.clear()
  150.                 term.setCursorPos(1,1)
  151.                 io.write("Please add fuel to slot '1' or fuel chest.")
  152.             end
  153.         end
  154.         turtle.turnLeft()
  155.         resume()
  156.     end
  157.     if done ~= 1 then
  158.         if quarrybore == "bore" then
  159.             turtle.up()
  160.         end
  161.         resume()
  162.     end
  163. end
  164.  
  165. function checkFull()
  166.     fullSlots = 0
  167.     local search = 0
  168.     for search = 16, 1, -1 do
  169.         turtle.select(search)
  170.         if turtle.getItemCount() > 0 then
  171.             if tossGarbage == "yes" then
  172.                 if turtle.getItemDetail().name == "minecraft:cobblestone" then
  173.                     turtle.drop()
  174.                 elseif turtle.getItemDetail().name == "minecraft:stone" then
  175.                     turtle.drop()
  176.                 elseif turtle.getItemDetail().name == "minecraft:dirt" then
  177.                     turtle.drop()
  178.                 elseif turtle.getItemDetail().name == "minecraft:gravel" then
  179.                     turtle.drop()
  180.                 elseif turtle.getItemDetail().name == "chisel:marble2" then
  181.                     turtle.drop()
  182.                 elseif turtle.getItemDetail().name == "chisel:limestone2" then
  183.                     turtle.drop()
  184.                 elseif turtle.getItemDetail().name == "minecraft:netherrack" then
  185.                     turtle.drop()
  186.                 elseif turtle.getItemDetail().name == "natura:nether_tainted_soil" then
  187.                     turtle.drop()
  188.                 end
  189.             end
  190.         end
  191.         if turtle.getItemCount() > 0 then
  192.             fullSlots = fullSlots + 1
  193.         end
  194.     end
  195.     if fullSlots == 16 then
  196.         empty()
  197.     end
  198. end
  199.  
  200. function nextRow()
  201.     if turn == 0 then
  202.         turtle.turnRight()
  203.         rotation = 1
  204.         digStraight()
  205.         turtle.turnRight()
  206.         rotation = 2
  207.         turn = 1
  208.     elseif turn == 1 then
  209.         turtle.turnLeft()
  210.         rotation = 1
  211.         digStraight()
  212.         turtle.turnLeft()
  213.         rotation = 0
  214.         turn = 0
  215.     elseif turn == 2 then
  216.         turtle.turnRight()
  217.         rotation = 3
  218.         digStraight()
  219.         turtle.turnRight()
  220.         rotation = 0
  221.         turn = 3
  222.     elseif turn == 3 then
  223.         turtle.turnLeft()
  224.         rotation = 3
  225.         digStraight()
  226.         turtle.turnLeft()
  227.         rotation = 2
  228.         turn = 2
  229.     end
  230. end
  231.  
  232. function digDown()
  233.     checkFuel()
  234.     local step = 0
  235.     for step = 2, 0, -1 do
  236.         turtle.digDown()
  237.         if turtle.down() == true then
  238.             posY = posY + 1
  239.         end
  240.         info()
  241.     end
  242. end
  243.  
  244. function digStraight()
  245.     checkFuel()
  246.     turtle.digDown()
  247.     turtle.dig()
  248.     turtle.dig()
  249.     turtle.forward()
  250.     if rotation == 0 then
  251.         posZ = posZ + 1
  252.     elseif rotation == 1 then
  253.         posX = posX + 1
  254.     elseif rotation == 2 then
  255.         posZ = posZ - 1
  256.     elseif rotation == 3 then
  257.         posX = posX - 1
  258.     end
  259.     turtle.digUp()
  260.     info()
  261. end
  262.  
  263. function quarry()
  264.     turn = 0
  265.     done = 0
  266.     iniY = tonumber (iniY)
  267.     limitY = tonumber (limitY)
  268.     checkFuel()
  269.     turtle.digUp()
  270.     turtle.up()
  271.     posY = posY - 1
  272.     while posY < iniY - 2 do
  273.         if quarrybore == "quarry" then
  274.             digDown()
  275.         end
  276.         for c = columns, 1, -1 do
  277.             for r = rows, 2, -1 do
  278.                 digStraight()
  279.             end
  280.             checkFull()
  281.             if c == 1 then
  282.                 turtle.turnRight()
  283.                 turtle.turnRight()
  284.                 if rotation == 0 then
  285.                     rotation = 2
  286.                 elseif rotation == 2 then
  287.                     rotation = 0
  288.                 end
  289.                 if turn == 0 then
  290.                     turn = 2
  291.                 elseif turn == 1 then
  292.                     turn = 3
  293.                 elseif turn == 2 then
  294.                     turn = 0
  295.                 elseif turn == 3 then
  296.                     turn = 1
  297.                 end
  298.             elseif c > 1 then
  299.                 nextRow()
  300.             end
  301.         end
  302.         if quarrybore == "bore" then
  303.             posY = posY + 1
  304.         end
  305.     end
  306.     turtle.digDown()
  307.     done = 1
  308.     empty()
  309.     term.clear()
  310.     term.setCursorPos(1,1)
  311.     print("Done!")
  312.     print("---------------------------------------")
  313. end
  314.  
  315. quarry()
RAW Paste Data