Advertisement
maximumrider999

Quarry 3

Apr 6th, 2023 (edited)
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Quarry a function by Maximumrider999
  2.  
  3. file = io.open("variables.txt", "rb")
  4.  
  5. local lines = {}
  6.  
  7. for line in io.lines("variables.txt") do
  8.     local words = {}
  9.     for word in line:gmatch("%w+") do
  10.         table.insert(words, word)
  11.     end    
  12.   table.insert(lines, words)
  13. end
  14.  
  15.  
  16. local loops = 15
  17. local j = tonumber(lines[2][1])
  18. local position1 = tonumber(lines[3][1])
  19. local position2 = tonumber(lines[4][1])
  20. local position3 = tonumber(lines[5][1])
  21. local currentK = tonumber(lines[6][1])
  22. local currentLoop = tonumber(lines[7][1])
  23. local heading = tonumber(lines[8][1])
  24. local torch = 2
  25. local fuel = 1
  26. local chest = 3
  27.  
  28. --Vars
  29. local tArgs = {...}
  30. if tArgs[1] ~= nul then
  31.     print("test")
  32.     local loops = tonumber(tArgs[1])
  33.     local torch = 2
  34.     local fuel = 1
  35.     local chest = 3
  36.     local j = 0
  37.     local position1 = 1
  38.     local position2 = 1
  39.     local position3 = 1
  40.     local currentk = 0
  41.     local currentLoop = 0
  42.     local heading = 0
  43. end
  44. --Functions
  45.  
  46. function Edit(changeNumber, change)
  47.  
  48.     file = io.open("variables.txt", "r")
  49.     local fileContent = {}
  50.     for line in file:lines() do
  51.         table.insert (fileContent, line)
  52.     end
  53.     io.close(file)
  54.  
  55.     fileContent[changeNumber] = change
  56.  
  57.     file = io.open("variables.txt", 'w')
  58.     for index, value in ipairs(fileContent) do
  59.         file:write(value..'\n')
  60.     end
  61.     io.close(file)
  62. end
  63.  
  64. --Edit(1, loops)
  65.  
  66. function tfuel(amount)
  67.     if turtle.getFuelLevel() < amount then do
  68.         turtle.select(fuel)
  69.         turtle.refuel()
  70.     end
  71. end
  72. end
  73.  
  74. function digForward(amount, p, i2)
  75.     if  amount < 1 then
  76.         amount = 1
  77.     end
  78.     for i = 1, amount do
  79.         while turtle.detect() == true do
  80.             turtle.dig()
  81.         end
  82.         turtle.forward()
  83.         if heading == 1 or heading == 2 then       
  84.             Edit(p,i2)
  85.         end
  86.         turtle.select(16)
  87.         if turtle.getItemCount() > 0 then
  88.             if heading == 1 then
  89.                 turtle.turnLeft()
  90.                 heading = 3
  91.                 Edit(8, heading)
  92.                 turtle.select(chest)
  93.                 turtle.place()
  94.                 for i = 4, 16 do
  95.                     turtle.select(i)
  96.                     turtle.drop()
  97.                 end
  98.                 turtle.turnRight()
  99.                 heading = 1
  100.                 Edit(8, heading)
  101.             end
  102.             if heading == 2 then
  103.                 turtle.turnRight()
  104.                 heading = 3
  105.                 Edit(8, heading)
  106.                 turtle.select(chest)
  107.                 turtle.place()
  108.                 for i = 4, 16 do
  109.                     turtle.select(i)
  110.                     turtle.drop()
  111.                 end
  112.                 turtle.turnLeft()
  113.                 heading = 2
  114.                 Edit(8, heading)
  115.             end
  116.         end
  117.         turtle.select(1)
  118.         turtle.digUp()
  119.         turtle.digDown()
  120.     end
  121. end
  122.    
  123. function placeTorch()
  124.     turtle.select(torch)
  125.     turtle.placeDown()
  126. end
  127.  
  128. function turnAround()
  129.     turtle.turnLeft()
  130.     turtle.turnLeft()
  131. end
  132.  
  133. --Main
  134.  for i = currentLoop, loops do
  135.     Edit(7, i)
  136.     if heading == 0 and position1 == 1 then
  137.         if j == 3 then
  138.             j = 0
  139.         else
  140.             j = j + 1
  141.             Edit(2, j)
  142.         end
  143.     end
  144.     for k = currentK,2 do
  145.         Edit(6, k)
  146.         tfuel(1000)
  147.         if position1 == 1 then
  148.             --[[turtle.select(16)
  149.             if turtle.getItemCount() > 0 then
  150.                 if heading == 0 then
  151.                     turnAround()
  152.                 end
  153.                 turtle.select(chest)
  154.                 turtle.place()
  155.                 for i = 4, 16 do
  156.                     turtle.select(i)
  157.                     turtle.drop()
  158.                 end
  159.                 turnAround()
  160.                 heading = 0
  161.                 Edit(8, heading)
  162.             end]]
  163.             turtle.select(1)   
  164.             digForward(1)
  165.             turtle.turnLeft()
  166.             heading = 1
  167.             Edit(8, heading)
  168.         end
  169.         if heading == 3 then
  170.             if position2 == 7 then
  171.                 turtle.turnLeft()
  172.                 heading = 2
  173.                 Edit(8, heading)
  174.             else
  175.                 turtle.turnRight()
  176.                 heading = 1
  177.                 Edit(8, heading)
  178.             end
  179.         end
  180.         if heading == 1 then
  181.             print("test")
  182.             for i = position1,5 do
  183.                 Edit(3, i)
  184.                 digForward(1,3,i+1)
  185.                 --Edit(3, i+1)
  186.             end
  187.             print("test2")
  188.             Edit(3,6)
  189.             if j == 3 and k == 0 then
  190.                 placeTorch()
  191.             end
  192.             for i = position2,6 do
  193.                 Edit(4, i)
  194.                 digForward(1,4,i+1)
  195.                 --Edit(4, i+1)
  196.             end
  197.             print("test3")
  198.             Edit(4,7)
  199.             if j == 3 and k == 0 then
  200.                 placeTorch()
  201.             end
  202.             turtle.turnRight()
  203.             heading = 0
  204.             Edit(8, heading)
  205.         end
  206.         if heading == 0 then
  207.             digForward(1)
  208.             turtle.turnRight()
  209.             heading = 2
  210.             Edit(8, heading)
  211.         end
  212.         if heading == 2 then
  213.             for i = position3,11 do
  214.                 Edit(5, i)
  215.                 digForward(1,5,i+1)
  216.                 --Edit(5, i+1)
  217.             end
  218.             Edit(5,12)
  219.             turtle.turnLeft()
  220.             heading = 0
  221.             Edit(8, heading)
  222.         end
  223.         if j == 3 and k == 0 then
  224.             placeTorch()
  225.         end
  226.         turtle.digUp()
  227.         turtle.digDown()
  228.         if k ~= 2 then
  229.             turtle.back()
  230.             turtle.back()
  231.             turtle.digUp()
  232.             turtle.up()
  233.             turtle.digUp()
  234.             turtle.up()
  235.             turtle.digUp()
  236.             turtle.up()
  237.         end
  238.         position1 = 1
  239.         position2 = 1
  240.         position3 = 1
  241.         Edit(3,1)
  242.         Edit(4,1)
  243.         Edit(5,1)
  244.     end
  245.     for i = 1,6 do
  246.         turtle.down()
  247.     end
  248.     Edit(6,0)
  249.     currentK = 0
  250.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement