Advertisement
JMANN2400

TreeFarmV3[NoFuel]

Aug 17th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.87 KB | None | 0 0
  1.  
  2.  
  3.  
  4. x = 0
  5.  
  6. y = 0
  7.  
  8. z = 0
  9.  
  10. step = 0
  11.  
  12. function deposit()
  13.     for i = 2,16,1 do
  14.         turtle.select(i)
  15.         count = turtle.getItemCount(i)
  16.         if count > 1 then
  17.             turtle.drop(count - 1)
  18.         end
  19.     end
  20. end
  21.  
  22. function writeFile()
  23.     file = fs.open("Info", "w")
  24.     file.writeLine(x)
  25.     file.writeLine(y)
  26.     file.writeLine(z)
  27.     file.writeLine(step)
  28.     file.close()
  29. end
  30.  
  31. function readFile()
  32.     file = fs.open("Info","r")
  33.     fileData = {}
  34.     local i = 0
  35.     while i < 4 do
  36.         line = file.readLine()
  37.         table.insert(fileData, line)
  38.         i = i + 1
  39.     end
  40.     file.close()
  41.     x = tonumber(fileData[1])
  42.     y = tonumber(fileData[2])
  43.     z = tonumber(fileData[3])
  44.     step = tonumber(fileData[4])
  45. end
  46.  
  47. function algorithm()
  48.     success, data = turtle.inspect()
  49.     if data.name == "minecraft:leaves" then
  50.         turtle.dig()
  51.         turtle.forward()
  52.         algorithm()
  53.         turtle.back()
  54.     end
  55.     turtle.turnLeft()
  56.     success, data = turtle.inspect()
  57.     if data.name == "minecraft:leaves" then
  58.         turtle.dig()
  59.         turtle.forward()
  60.         algorithm()
  61.         turtle.back()
  62.     end
  63.     turtle.turnLeft()
  64.     success, data = turtle.inspect()
  65.     if data.name == "minecraft:leaves" then
  66.         turtle.dig()
  67.         turtle.forward()
  68.         algorithm()
  69.         turtle.back()
  70.     end
  71.     turtle.turnLeft()
  72.     success, data = turtle.inspect()
  73.     if data.name == "minecraft:leaves" then
  74.         turtle.dig()
  75.         turtle.forward()
  76.         algorithm()
  77.         turtle.back()
  78.     end
  79.     turtle.turnLeft()
  80. end
  81.  
  82. function mineTree()
  83.     turtle.digUp()
  84.     turtle.up()
  85.     algorithm()
  86. end
  87.  
  88. function checkForTreeF()
  89.     success, data = turtle.inspectUp()
  90.     if data.name == "minecraft:log" then
  91.         mineTree()
  92.         z = z + 1
  93.         checkForTreeF()
  94.         turtle.down()
  95.         z = z - 1
  96.         if z == 0 then
  97.             turtle.forward()
  98.             y = y + 1
  99.             turtle.turnLeft()
  100.             turtle.turnLeft()
  101.             turtle.select(1)
  102.             turtle.place()
  103.             turtle.turnLeft()
  104.             turtle.turnLeft()
  105.         end
  106.     end
  107. end
  108.  
  109. function checkForTreeB()
  110.     success, data = turtle.inspectUp()
  111.     if data.name == "minecraft:log" then
  112.         mineTree()
  113.         z = z + 1
  114.         checkForTreeB()
  115.         turtle.down()
  116.         z = z - 1
  117.         if z == 0 and y > 0 then
  118.             turtle.forward()
  119.             y = y - 1
  120.             turtle.turnLeft()
  121.             turtle.turnLeft()
  122.             turtle.select(1)
  123.             turtle.place()
  124.             turtle.turnLeft()
  125.             turtle.turnLeft()
  126.         end
  127.         if z == 0 and y == 0 then
  128.             turtle.turnRight()
  129.             turtle.forward()
  130.             x = x - 1
  131.             turtle.turnLeft()
  132.             turtle.turnLeft()
  133.             turtle.select(1)
  134.             turtle.place()
  135.             turtle.turnLeft()
  136.             turtle.turnLeft()
  137.         end
  138.     end
  139. end
  140.  
  141. function checkForTreeX()
  142.     success, data = turtle.inspectUp()
  143.     if data.name == "minecraft:log" then
  144.         mineTree()
  145.         z = z + 1
  146.         checkForTreeX()
  147.         turtle.down()
  148.         z = z - 1
  149.         if z == 0 then
  150.             turtle.forward()
  151.             x = x - 1
  152.             turtle.turnLeft()
  153.             turtle.turnLeft()
  154.             turtle.select(1)
  155.             turtle.place()
  156.             turtle.turnLeft()
  157.             turtle.turnLeft()
  158.         end
  159.     end
  160. end
  161.  
  162. readFile()
  163.  
  164. repeat
  165.     if step == 0 then
  166.     while y < 42 do
  167.         checkForTreeF()
  168.         turtle.dig()
  169.         turtle.forward()
  170.         y = y + 1
  171.         checkForTreeF()
  172.     end
  173.     step = step + 1
  174.     writeFile()
  175.     end
  176.     if step == 1 then
  177.     turtle.turnRight()
  178.     step = step + 1
  179.     writeFile()
  180.     end
  181.     if step == 2 then
  182.     while x < 6 do
  183.         turtle.dig()
  184.         turtle.forward()
  185.         x = x + 1
  186.     end
  187.     step = step + 1
  188.     writeFile()
  189.     end
  190.     if step == 3 then
  191.     turtle.turnRight()
  192.     step = step + 1
  193.     writeFile()
  194.     end
  195.     if step == 4 then
  196.     while y > 6 do
  197.         checkForTreeB()
  198.         turtle.dig()
  199.         turtle.forward()
  200.         y = y - 1
  201.         checkForTreeB()
  202.     end
  203.     step = step + 1
  204.     writeFile()
  205.     end
  206.     if step == 5 then
  207.     turtle.turnLeft()
  208.     step = step + 1
  209.     writeFile()
  210.     end
  211.     if step == 6 then
  212.     while x < 12 do
  213.         turtle.dig()
  214.         turtle.forward()
  215.         x = x + 1
  216.     end
  217.     step = step + 1
  218.     writeFile()
  219.     end
  220.     if step == 7 then
  221.     turtle.turnLeft()
  222.     step = step + 1
  223.     writeFile()
  224.     end
  225.     if step == 8 then
  226.     while y < 42 do
  227.         checkForTreeF()
  228.         turtle.dig()
  229.         turtle.forward()
  230.         y = y + 1
  231.         checkForTreeF()
  232.     end
  233.     step = step + 1
  234.     writeFile()
  235.     end
  236.     if step == 9 then
  237.     turtle.turnRight()
  238.     step = step + 1
  239.     writeFile()
  240.     end
  241.     if step == 10 then
  242.     while x < 18 do
  243.         turtle.dig()
  244.         turtle.forward()
  245.         x = x + 1
  246.     end
  247.     step = step + 1
  248.     writeFile()
  249.     end
  250.     if step == 11 then
  251.     turtle.turnRight()
  252.     step = step + 1
  253.     writeFile()
  254.     end
  255.     if step == 12 then
  256.     while y > 6 do
  257.         checkForTreeB()
  258.         turtle.dig()
  259.         turtle.forward()
  260.         y = y - 1
  261.         checkForTreeB()
  262.     end
  263.     step = step + 1
  264.     writeFile()
  265.     end
  266.     if step == 13 then
  267.     turtle.turnLeft()
  268.     step = step + 1
  269.     writeFile()
  270.     end
  271.     if step == 14 then
  272.     while x < 24 do
  273.         turtle.dig()
  274.         turtle.forward()
  275.         x = x + 1
  276.     end
  277.     step = step + 1
  278.     writeFile()
  279.     end
  280.     if step == 15 then
  281.     turtle.turnLeft()
  282.     step = step + 1
  283.     writeFile()
  284.     end
  285.     if step == 16 then
  286.     while y < 42 do
  287.         checkForTreeF()
  288.         turtle.dig()
  289.         turtle.forward()
  290.         y = y + 1
  291.         checkForTreeF()
  292.     end
  293.     step = step + 1
  294.     writeFile()
  295.     end
  296.     if step == 17 then
  297.     turtle.turnRight()
  298.     step = step + 1
  299.     writeFile()
  300.     end
  301.     if step == 18 then
  302.     while x < 30 do
  303.         turtle.dig()
  304.         turtle.forward()
  305.         x = x + 1
  306.     end
  307.     step = step + 1
  308.     writeFile()
  309.     end
  310.     if step == 19 then
  311.     turtle.turnRight()
  312.     step = step + 1
  313.     writeFile()
  314.     end
  315.     if step == 20 then
  316.     while y > 6 do
  317.         checkForTreeB()
  318.         turtle.dig()
  319.         turtle.forward()
  320.         y = y - 1
  321.         checkForTreeB()
  322.     end
  323.     step = step + 1
  324.     writeFile()
  325.     end
  326.     if step == 21 then
  327.     turtle.turnLeft()
  328.     step = step + 1
  329.     writeFile()
  330.     end
  331.     if step == 22 then
  332.     while x < 36 do
  333.         turtle.dig()
  334.         turtle.forward()
  335.         x = x + 1
  336.     end
  337.     step = step + 1
  338.     writeFile()
  339.     end
  340.     if step == 23 then
  341.     turtle.turnLeft()
  342.     step = step + 1
  343.     writeFile()
  344.     end
  345.     if step == 24 then
  346.     while y < 42 do
  347.         checkForTreeF()
  348.         turtle.dig()
  349.         turtle.forward()
  350.         y = y + 1
  351.         checkForTreeF()
  352.     end
  353.     step = step + 1
  354.     writeFile()
  355.     end
  356.     if step == 25 then
  357.     turtle.turnRight()
  358.     step = step + 1
  359.     writeFile()
  360.     end
  361.     if step == 26 then
  362.     while x < 42 do
  363.         turtle.dig()
  364.         turtle.forward()
  365.         x = x + 1
  366.     end
  367.     step = step + 1
  368.     writeFile()
  369.     end
  370.     if step == 27 then
  371.     turtle.turnRight()
  372.     step = step + 1
  373.     writeFile()
  374.     end
  375.     if step == 28 then
  376.     while y > 0 do
  377.         checkForTreeB()
  378.         turtle.dig()
  379.         turtle.forward()
  380.         y = y - 1
  381.         checkForTreeB()
  382.     end
  383.     step = step + 1
  384.     writeFile()
  385.     end
  386.     if step == 29 then
  387.     while x > 0 do
  388.         checkForTreeX()
  389.         turtle.dig()
  390.         turtle.forward()
  391.         x = x - 1
  392.         checkForTreeX()
  393.     end
  394.     step = step + 1
  395.     writeFile()
  396.     end
  397.     if step == 30 then
  398.     turtle.dig()
  399.     turtle.forward()
  400.     step = step + 1
  401.     writeFile()
  402.     end
  403.     if step == 31 then
  404.     turtle.dig()
  405.     turtle.forward()
  406.     step = step + 1
  407.     writeFile()
  408.     end
  409.     if step == 32 then
  410.     turtle.dig()
  411.     turtle.forward()
  412.     step = step + 1
  413.     writeFile()
  414.     end
  415.     if step == 33 then
  416.     deposit()
  417.     turtle.back()
  418.     step = step + 1
  419.     writeFile()
  420.     end
  421.     if step == 34 then
  422.     turtle.back()
  423.     step = step + 1
  424.     writeFile()
  425.     end
  426.     if step == 35 then
  427.     turtle.back()
  428.     step = step + 1
  429.     writeFile()
  430.     end
  431.     if step == 36 then
  432.     turtle.turnRight()
  433.     step = 0
  434.     writeFile()
  435.     end
  436. until redstone.getInput("bottom") == 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement