Advertisement
sinkir

lua turtle simple 1 tree

May 16th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 KB | None | 0 0
  1. left = function()
  2.     return turtle.turnLeft()
  3. end
  4.  
  5. right = function()
  6.     return turtle.turnRight()
  7. end
  8.  
  9. up = function()
  10.     return turtle.up()
  11. end
  12.  
  13. down = function()
  14.     return turtle.down()
  15. end
  16.  
  17. back = function()
  18.     return turtle.back()
  19. end
  20.  
  21. go = function()
  22.     return turtle.forward()
  23. end
  24.  
  25. fuel = function()
  26.     return turtle.getFuelLevel()
  27. end
  28.  
  29. select = function(id)
  30.     return turtle.select(id)
  31. end
  32.  
  33. count = function(id)
  34.     return turtle.getItemCount(id)
  35. end
  36.  
  37. move = function(id, nb)
  38.     return turtle.transferTo(id, nb)
  39. end
  40.  
  41. --coucou coucou- -------------------------------------------
  42. function testFuel()
  43.     if(fuel() < 100)then
  44.         print('Plus de coco, test de refuel')
  45.         j = 1
  46.         if (count(j)>0) then
  47.             select(j)
  48.         end
  49.         flagstop = false
  50.         while(flagstop == false)do
  51.             if(count(j)>0 and turtle.refuel(3)==true)then
  52.                 print('refuel 3, slot '..j)
  53.                 return true
  54.             end
  55.             if(j==16)then
  56.                 print('imposible de refuel, exit')
  57.                 return false
  58.             end
  59.             j=j+1
  60.             if(count(j)>0) then
  61.                 select(j)
  62.             end
  63.         end
  64.     end
  65. end
  66.  
  67.  
  68. function init()
  69.     if(count(1)==0) then
  70.         print('Besoin du block a couper en slot 1')
  71.         return false
  72.     end
  73.     if(turtle.detectDown()==false)then
  74.         print('Pas de coffre ?')
  75.         return false
  76.     end
  77.     if(count(16)==0 and turtle.suck()==false) then
  78.         print('Pas de slaping ?')
  79.         return false
  80.     end
  81.  
  82.    
  83.    
  84.     if(count(16)==0) then
  85.         select(2)
  86.         move(16, count(1))
  87.     end
  88.     if(count(16)<64) then
  89.         print('Ya pas beaucoup de slapping :/')
  90.     end
  91.     if(testFuel()==false)then
  92.         return false
  93.     end
  94.     return true
  95. end
  96.  
  97. function testSlaping()
  98.     if(count(16)==0)then
  99.         print('plus de slaping')
  100.         return false
  101.     end
  102.     if(turtle.detect()==false)then
  103.         select(16)
  104.  
  105.         print('place un slaping')
  106.         turtle.place()
  107.         return true
  108.     end
  109. end
  110. function videInv()
  111.     for i=2,15 do
  112.         select(i)
  113.         turtle.dropDown()
  114.     end
  115. end
  116. function coupeArbre(i)
  117.     if(testFuel()==false)then
  118.         print('coupeArbre false:testFuel')
  119.         return false
  120.     end
  121.     flag=turtle.detectUp()
  122.     if(flag==true) then
  123.         --print('detectUp = true')
  124.         turtle.digUp()
  125.         up()
  126.         sleep(1)
  127.         i=i+1
  128.     end
  129.    
  130.     if (flag==false) then
  131.         --print('detectUp = false')
  132.         while(i>0)do
  133.             down()
  134.             i=i-1
  135.         end
  136.         while(back() == false)do
  137.             sleep(2)
  138.         end
  139.         select(16)
  140.         turtle.place(1)
  141.         --print('coupeArbre true')
  142.         videInv()
  143.  
  144.         return true
  145.     end
  146.     return coupeArbre(i)
  147. end
  148. -- ---------------------------------------------------------
  149.  
  150.  
  151.  
  152. stop=false
  153. if(init()==false) then
  154.     stop=true
  155. end
  156. while(stop==false)do
  157.     if(testSlaping() == false)then
  158.         stop=true
  159.     end
  160.     select(1)
  161.     if(turtle.compare()==true)then
  162.         turtle.dig()
  163.         go()
  164.         if(coupeArbre(0)==false)then
  165.             stop=true
  166.         end
  167.     end
  168.     sleep(1)
  169. end
  170. print('End')
  171. if(fuel() == 0) then
  172.   print('Ya plus de coco mon coco !')
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement