Advertisement
sinkir

lua turtle one tree 2

Oct 29th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.96 KB | None | 0 0
  1. -- pastebin get kRkVtY4d startup
  2. -- -------------------------------------------
  3. -- one tree -Sinkir-
  4. -- Version 2.0 (2014/10/29)
  5.  
  6. -- SCANER FUNCTION :
  7. -- slot 16 ender chest Fuel               +-+-+-+-+
  8. -- slot 15 ender chest BoneMeal           | | | | |
  9. -- slot 14 BoneMeal                       | | | | |
  10. -- slot 13 Saplings                       | | | | |
  11. --                                        |S|b|B|F|
  12. --                                        +-+-+-+-+
  13. -- -------------------------------------------
  14.  
  15.  
  16.  
  17. --   _____
  18. --  |  ___|   _ _ __   ___
  19. --  | |_ | | | | '_ \ / __|
  20. --  |  _|| |_| | | | | (__
  21. --  |_|   \__,_|_| |_|\___|
  22. --
  23.  
  24.  
  25. function testFuel()
  26.     if(fuel() < 32)then
  27.             if(count(16) == 0)then
  28.                     print("slot 16 empty")
  29.                     sleep(20)
  30.                     os.reboot()
  31.             end    
  32.             print('Plus de coco, test de refuel')
  33.             while(turtle.detectUp())do
  34.                     turtle.digUp()
  35.                     sleep(1)
  36.             end
  37.             select(16)
  38.             turtle.placeUp()
  39.             sleep(1)
  40.             --print('Placed, sucking..')
  41.             if(turtle.suckUp() == false)then
  42.                     turtle.digUp()
  43.                     print("Suck fuel false")
  44.                     sleep(20)
  45.                     os.reboot()
  46.             end
  47.             turtle.refuel()
  48.             sleep(0.2)
  49.             turtle.digUp()
  50.     end
  51.     return true
  52. end
  53.  
  54. function testBoneMeal()
  55.     if(count(14) < 6)then
  56.             if(count(15) == 0)then
  57.                     print("slot 15 empty")
  58.                     --sleep(20)
  59.                     --os.reboot()
  60.                     return false
  61.             end    
  62.             select(1)
  63.             while(turtle.detectUp())do
  64.                     turtle.digUp()
  65.                     sleep(1)
  66.             end
  67.             select(15)
  68.             turtle.placeUp()
  69.             sleep(1)
  70.             select(14)
  71.             --print('Placed, sucking..')
  72.             if(turtle.suckUp(turtle.getItemSpace(14)) == false)then
  73.                     turtle.digUp()
  74.                     print("Suck BoneMeal false")
  75.                     sleep(20)
  76.                     os.reboot()
  77.             end
  78.             select(15)
  79.             turtle.digUp()
  80.     end
  81.     return true
  82. end
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. left = function()
  90.     if(turtle.turnLeft()==false)then
  91.         sleep(1)
  92.         left()
  93.     else
  94.         return true
  95.     end
  96. end
  97. right = function()
  98.     if(turtle.turnRight()==false)then
  99.         sleep(1)
  100.         right()
  101.     else
  102.         return true
  103.     end
  104. end
  105. count = function(id)
  106.     return turtle.getItemCount(id)
  107. end
  108. back = function()
  109.     return turtle.back()
  110. end
  111. go = function()
  112.     return turtle.forward()
  113. end
  114. select = function(id)
  115.     return turtle.select(id)
  116. end
  117. fuel = function()
  118.     return turtle.getFuelLevel()
  119. end
  120. move = function(id, nb)
  121.     return turtle.transferTo(id, nb)
  122. end
  123. --
  124. --
  125.  
  126.  
  127. --
  128. --
  129.  
  130.  
  131.  
  132.  
  133. function videInv()
  134.  
  135.     for i=1,12 do
  136.         if(count(i)>0)then
  137.             select(i)
  138.             if(turtle.compareTo(14) == true)then
  139.                     if(count(16) < 64) then
  140.                             turtle.transferTo(16, turtle.getItemSpace(16))
  141.                     end
  142.             end
  143.            
  144.             if(turtle.compareTo(13) == true)then
  145.                     if(count(16) < 64) then
  146.                             turtle.transferTo(16, turtle.getItemSpace(16))
  147.                     end
  148.             end
  149.             turtle.dropDown()
  150.         end
  151.     end
  152.     return true
  153. end
  154.  
  155. function lost()
  156.         print("je suis perdu :/")
  157.         for i=1,12 do
  158.             if(turtle.detectUp())then
  159.                 turtle.digUp()
  160.                 turtle.up()
  161.             end
  162.         end
  163.         while turtle.detectDown() == false do
  164.             turtle.down()
  165.             sleep(0.2)
  166.         end
  167.        
  168.         turtle.back()
  169.         if(turtle.detectDown() == false)then
  170.             turtle.forward()
  171.             turtle.left()
  172.             turtle.back()
  173.         end
  174.         if(turtle.detectDown() == false)then
  175.             turtle.forward()
  176.             turtle.left()
  177.             turtle.back()
  178.         end
  179.         if(turtle.detectDown() == false)then
  180.             turtle.forward()
  181.             turtle.left()
  182.             turtle.back()
  183.         end
  184.         if(turtle.detectDown() == false)then
  185.             print("i'm lost exit")
  186.             shell.exit()
  187.         end
  188.        
  189.        
  190. end
  191.  
  192. function init()
  193.     if(count(16) == 0)then
  194.         print("No ender chest for fuel in slot 16.., exit")
  195.         return false
  196.     end
  197.     if(count(15) == 0)then
  198.         print("No ender chest for BoneMeal in slot 15")
  199.     end
  200.     if(count(14) == 0)then
  201.         print("No BoneMeal in slot 14")
  202.     end
  203.     if(count(13) == 0)then
  204.         print("No Saplings in slot 13, exit")
  205.         return false
  206.     end
  207.     testFuel()
  208.     testBoneMeal()
  209.     select(1)
  210.    
  211.     if(turtle.detectDown() == false)then
  212.         lost()
  213.     elseif(turtle.detectDown()and turtle.detectUp())then
  214.         lost()
  215.     end
  216.  
  217.     return true
  218. end
  219.  
  220.  
  221. function tree()
  222.     select(1)
  223.     turtle.dig()
  224.     turtle.forward()
  225.     while turtle.detectUp() do
  226.         turtle.digUp()
  227.         sleep(0.2)
  228.         turtle.up()
  229.         sleep(0.5)
  230.  
  231.         turtle.dig()
  232.         left()
  233.         turtle.dig()
  234.         left()
  235.         turtle.dig()
  236.         left()
  237.         turtle.dig()
  238.         left()
  239.  
  240.  
  241.     end
  242.     while turtle.detectDown() == false do
  243.             turtle.down()
  244.             while turtle.suckDown() do
  245.                 sleep(0.5)
  246.             end
  247.             sleep(0.2)
  248.     end
  249.     turtle.back()
  250.     while turtle.suck() do
  251.         sleep(0.5)
  252.     end
  253.        
  254.    
  255. end
  256.    
  257.  
  258.  
  259. --  __  __       _        ____
  260. -- |  \/  | __ _(_)_ __  / /\ \
  261. -- | |\/| |/ _` | | '_ \| |  | |
  262. -- | |  | | (_| | | | | | |  | |
  263. -- |_|  |_|\__,_|_|_| |_| |  | |
  264. --                       \_\/_/
  265.  
  266.  
  267.  
  268.  
  269. stop=false
  270.  
  271. if(init()==false) then
  272.     stop=true
  273. end
  274.  
  275. i = 0
  276. stopCounter = 1
  277. while(stop==false)do
  278.     if(turtle.detect())then
  279.         if(count(14) > 1)then
  280.             turtle.select(14)
  281.             for i=0, 5 do
  282.                 turtle.place()
  283.             end
  284.         end
  285.        
  286.         tree()
  287.     else
  288.         turtle.select(13)
  289.         turtle.place()     
  290.     end
  291.    
  292.    
  293.    
  294.     videInv()
  295.    
  296.     testFuel()
  297.     testBoneMeal()
  298.  
  299.     sleep(0.2)
  300. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement