M0n5t3r

Big Tree Farm

Jun 15th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.25 KB | None | 0 0
  1. local goUp = 0
  2. local right_movement = 0
  3. local last = "left"
  4. local level = 2
  5.  
  6. function getTree()
  7.     local success, t = turtle.inspect()
  8.     if  (string.find(t.name, "leaves") == nil) then
  9.         turtle.dig()
  10.         if turtle.forward() == false then
  11.             turtle.dig()
  12.             turtle.forward()
  13.         else
  14.             if turtle.detectUp() == true then
  15.                 while (turtle.detectUp()) do
  16.                     local success, t = turtle.inspectUp()
  17.                     if  (string.find(t.name, "dirt") == nil) then
  18.                         turtle.digUp()
  19.                         turtle.up()
  20.                         goUp = goUp + 1
  21.                     else
  22.                         break
  23.                     end
  24.                 end
  25.                 repeat
  26.                     turtle.down()
  27.                     goUp = goUp  - 1
  28.                 until goUp == 0
  29.             else
  30.                 repeat
  31.                     turtle.down()
  32.                     goUp = goUp  - 1
  33.                 until goUp == 0
  34.             end
  35.             turtle.digDown()
  36.             turtle.select(1)
  37.             if turtle.getItemCount(1) > 1 then
  38.                 if  string.find(turtle.getItemDetail(1).name, "sapling") then
  39.                     turtle.placeDown()
  40.                 end
  41.             end
  42.         end
  43.     else
  44.         turtle.dig()
  45.         if turtle.forward() == false then
  46.             turtle.dig()
  47.             turtle.forward()
  48.         end
  49.     end
  50. end
  51. function back(amount)
  52.     local _back = 0
  53.     repeat
  54.         if turtle.back() then
  55.             _back = _back + 1
  56.         else
  57.             turtle.turnleft()
  58.             turtle.turnleft()
  59.             turtle.dig()
  60.             turtle.turnLeft()
  61.             turtle.turnleft()
  62.         end
  63.     until _back == amount
  64. end
  65. function forward(amount)
  66.     local _forward = 0
  67.     repeat
  68.         if turtle.forward() then
  69.             _forward = _forward + 1
  70.         else
  71.             turtle.dig()
  72.         end
  73.     until _forward == amount
  74.  
  75. end
  76. function up(amount)
  77.     local _up = 0
  78.     repeat
  79.         if turtle.up() then
  80.             _up = _up + 1
  81.         else
  82.             turtle.digUp()
  83.         end
  84.     until _up == amount
  85. end
  86. function down(amount)
  87.     local _down = 0
  88.     repeat
  89.         if turtle.down() then
  90.             _down = _down + 1
  91.         else
  92.             turtle.digDown()
  93.         end
  94.     until _down == amount
  95. end
  96. function empty()
  97.     --from base
  98.     turtle.turnLeft()
  99.     turtle.forward()
  100.     if turtle.getItemCount(1) > 1 then
  101.         if  string.find(turtle.getItemDetail(1).name, "sapling") then
  102.             for q=2,16 do
  103.                 turtle.select(q)
  104.                 turtle.dropDown()
  105.             end
  106.         else
  107.             for q=1,16 do
  108.                 turtle.select(q)
  109.                 turtle.dropDown()
  110.             end
  111.         end
  112.     end
  113.    
  114.  
  115.     turtle.select(1)
  116.     turtle.back()
  117.     turtle.turnRight()
  118. end
  119. function emptyAll()
  120.     --from base
  121.     turtle.turnLeft()
  122.     turtle.forward()
  123.     for q=1,16 do
  124.         turtle.select(q)
  125.         turtle.dropDown()
  126.     end
  127.     turtle.select(1)
  128.     turtle.back()
  129.     turtle.turnRight()
  130. end
  131. function start()
  132.     emptyAll()
  133.     goUp = 0
  134.     right_movement = 0
  135.     last = "left"
  136.  
  137.     local counter = 0
  138.  
  139.     --
  140.     if level == 0 then
  141.         turtle.turnRight()
  142.         forward(10)
  143.         turtle.suckDown(35)
  144.         -- if turtle.getItemCount(1) >= 1 then
  145.         --     if  string.find(turtle.getItemDetail(1).name, "sapling") then
  146.         --         print("Didn't have any sapplings, give some in slot 1")
  147.         --         while (string.find(turtle.getItemDetail(1).name, "sapling")) == false or (string.find(turtle.getItemDetail(1).name, "sapling")) == nil do
  148.         --             sleep(10)
  149.         --         end
  150.         --     end
  151.         -- elseif turtle.getItemCount(1) == 0 then
  152.         --     print("Didn't have any sapplings, give some in slot 1")
  153.         --     while turtle.getItemCount(1) == 0 do
  154.         --         sleep(10)
  155.         --     end
  156.         -- end
  157.         back(10)
  158.         turtle.turnLeft()
  159.         turtle.forward()
  160.         up(30)
  161.        
  162.  
  163.  
  164.     elseif level == 1 then
  165.         turtle.turnRight()
  166.         forward(7)
  167.         turtle.suckDown(35)
  168.         -- if turtle.getItemCount(1) >= 1 then
  169.         --     if  string.find(turtle.getItemDetail(1).name, "sapling") then
  170.         --         print("Didn't have any sapplings, give some in slot 1")
  171.         --         while (string.find(turtle.getItemDetail(1).name, "sapling")) == false or (string.find(turtle.getItemDetail(1).name, "sapling")) == nil do
  172.         --             sleep(10)
  173.         --             counter = counter + 1
  174.         --             if counter == 10 then
  175.         --                 break
  176.         --             end
  177.         --         end
  178.         --     end
  179.         -- elseif turtle.getItemCount(1) == 0 then
  180.         --     print("Didn't have any sapplings, give some in slot 1")
  181.         --     while turtle.getItemCount(1) == 0 do
  182.         --         sleep(10)
  183.         --         counter = counter + 1
  184.         --         if counter == 10 then
  185.         --             break
  186.         --         end
  187.         --     end
  188.         -- end
  189.         back(7)
  190.         turtle.turnLeft()
  191.         turtle.forward()
  192.         up(20)
  193.  
  194.     elseif level == 2 then
  195.         turtle.turnRight()
  196.         forward(4)
  197.         turtle.suckDown(35)
  198.         -- if turtle.getItemCount(1) >= 1 then
  199.         --     if  string.find(turtle.getItemDetail(1).name, "sapling") then
  200.         --         print("Didn't have any sapplings, give some in slot 1")
  201.         --         while (string.find(turtle.getItemDetail(1).name, "sapling")) == false or (string.find(turtle.getItemDetail(1).name, "sapling")) == nil do
  202.         --             sleep(10)
  203.         --             counter = counter + 1
  204.         --             if counter == 10 then
  205.         --                 break
  206.         --             end
  207.         --         end
  208.         --     end
  209.         -- elseif turtle.getItemCount(1) == 0 then
  210.         --     print("Didn't have any sapplings, give some in slot 1")
  211.         --     while turtle.getItemCount(1) == 0 do
  212.         --         sleep(10)
  213.         --         counter = counter + 1
  214.         --         if counter == 10 then
  215.         --             break
  216.         --         end
  217.         --     end
  218.         -- end
  219.         back(4)
  220.         turtle.turnLeft()
  221.         turtle.forward()
  222.         up(10)
  223.        
  224.     elseif level == 3 then
  225.         turtle.turnRight()
  226.         forward(1)
  227.         turtle.suckDown(35)
  228.         -- if turtle.getItemCount(1) >= 1 then
  229.         --     if  string.find(turtle.getItemDetail(1).name, "sapling") then
  230.         --         print("Didn't have any sapplings, give some in slot 1")
  231.         --         while (string.find(turtle.getItemDetail(1).name, "sapling")) == false or (string.find(turtle.getItemDetail(1).name, "sapling")) == nil do
  232.         --             sleep(10)
  233.         --             counter = counter + 1
  234.         --             if counter == 10 then
  235.         --                 break
  236.         --             end
  237.         --         end
  238.         --     end
  239.         -- elseif turtle.getItemCount(1) == 0 then
  240.         --     print("Didn't have any sapplings, give some in slot 1")
  241.         --     while turtle.getItemCount(1) == 0 do
  242.         --         sleep(10)
  243.         --         counter = counter + 1
  244.         --         if counter == 10 then
  245.         --             break
  246.         --         end
  247.         --     end
  248.         -- end
  249.         back(1)
  250.         turtle.turnLeft()
  251.         turtle.forward()
  252.     else
  253.         turtle.forward()
  254.     end
  255.     turtle.select(1)
  256.     print("Done with Start")
  257. end
  258. function walk(number)
  259.     local forward = 0
  260.     local tree_steps = 0;
  261.     repeat
  262.         if turtle.forward() == false then
  263.             getTree()
  264.             forward = forward + 1
  265.             tree_steps = tree_steps + 1
  266.         else
  267.             forward = forward + 1
  268.             tree_steps = tree_steps + 1
  269.         end
  270.         if tree_steps == 4 then
  271.             tree_steps = 0
  272.             checkSapling()
  273.         end
  274.     until forward == number
  275. end
  276. function moveRight()
  277.     turtle.turnRight()
  278.     forward(3)
  279.     walk(1)
  280.     --check
  281.     checkSapling()
  282.     --
  283.     turtle.turnRight()
  284.     right_movement = right_movement + 1
  285.     last = "right"
  286. end
  287. function moveLeft()
  288.     turtle.turnLeft()
  289.     forward(3)
  290.     walk(1)
  291.     checkSapling()
  292.     turtle.turnLeft()
  293.     right_movement = right_movement + 1
  294.     last = "left"
  295.  
  296. end
  297. function goHome()
  298.     if last == "left" then
  299.         turtle.forward()
  300.         turtle.turnRight()
  301.         turtle.forward()
  302.         turtle.turnRight()
  303.     end
  304.     forward(20)
  305.     turtle.turnRight()
  306.     forward(25)
  307.     turtle.turnRight()
  308.    
  309.     if level == 0 then
  310.         down(30)
  311.     elseif level == 1 then
  312.         down(20)
  313.     elseif level == 2 then
  314.         down(10)
  315.     elseif level == 3 then
  316.         print("last level");
  317.     end
  318.     turtle.down()
  319.  
  320.     turtle.back()
  321.  
  322.     if turtle.getItemCount(1) > 0 then
  323.         if  string.find(turtle.getItemDetail(1).name, "sapling") then
  324.             turtle.turnRight()
  325.             turtle.select(1)
  326.             if level == 0 then
  327.                 forward(10)
  328.                 turtle.dropDown(64)
  329.                 back(10)
  330.             elseif level == 1 then
  331.                 forward(7)
  332.                 turtle.dropDown(64)
  333.                 back(7)
  334.             elseif level == 2 then
  335.                 forward(4)
  336.                 turtle.dropDown(64)
  337.                 back(4)
  338.             elseif level == 3 then
  339.                 forward(1)
  340.                 turtle.dropDown(64)
  341.                 back(1)
  342.             end
  343.             turtle.turnLeft()
  344.         end
  345.     end
  346.     print("done with Go Home function")
  347.  
  348. end
  349. function checkSapling()
  350.     local success, t = turtle.inspectDown()
  351.     if success then
  352.         if string.find(t.name, "sapling") then
  353.            
  354.         else
  355.             turtle.select(4)
  356.             turtle.digDown()
  357.             turtle.select(1)
  358.             if turtle.getItemCount(1) > 1 then
  359.                 if  string.find(turtle.getItemDetail(1).name, "sapling") then
  360.                     turtle.placeDown()
  361.                 end
  362.             end
  363.         end
  364.     else
  365.         turtle.select(4)
  366.         turtle.digDown()
  367.         turtle.select(1)
  368.         if turtle.getItemCount(1) > 1 then
  369.             if  string.find(turtle.getItemDetail(1).name, "sapling") then
  370.                 turtle.placeDown()
  371.             end
  372.         end
  373.     end
  374. end
  375. function sleepFunction()
  376.     print("Going to sleep")
  377.     local slept = 0
  378.     repeat
  379.         sleep(10)
  380.         slept = slept + 10
  381.         print("Slept: " .. slept .. "/50")
  382.     until slept >= 50
  383.     print( "gotte work ")
  384. end
  385.  
  386. while true do
  387.     repeat
  388.         start()
  389.         turtle.up()
  390.         forward(2)
  391.         walk(1)
  392.         checkSapling()
  393.         repeat
  394.             walk(16)
  395.             if last == "left" then
  396.                 moveRight()
  397.             elseif last == "right" then
  398.                 moveLeft()
  399.             end
  400.         until right_movement == 6
  401.         walk(16)
  402.         goHome()
  403.         level = level + 1
  404.     until level == 4
  405.  
  406.     --reset
  407.     level = 0
  408.     last = "left"
  409.     right_movement = 0
  410.     goUp = 0
  411.  
  412.     sleepFunction()
  413.    
  414. end
Add Comment
Please, Sign In to add comment