Advertisement
sinkir

lua turtle makeOneTreeSpot 2

Oct 29th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.94 KB | None | 0 0
  1. --   _____
  2. --  |  ___|   _ _ __   ___
  3. --  | |_ | | | | '_ \ / __|
  4. --  |  _|| |_| | | | | (__
  5. --  |_|   \__,_|_| |_|\___|
  6. --
  7.  
  8. left = function()
  9.     return turtle.turnLeft()
  10. end
  11.  
  12. right = function()
  13.     return turtle.turnRight()
  14. end
  15.  
  16. up = function()
  17.     return turtle.up()
  18. end
  19.  
  20. down = function()
  21.     return turtle.down()
  22. end
  23.  
  24. back = function()
  25.     return turtle.back()
  26. end
  27.  
  28. go = function()
  29.     return turtle.forward()
  30. end
  31.  
  32. fuel = function()
  33.     return turtle.getFuelLevel()
  34. end
  35.  
  36. select = function(id)
  37.     return turtle.select(id)
  38. end
  39.  
  40. count = function(id)
  41.     return turtle.getItemCount(id)
  42. end
  43.  
  44. move = function(id, nb)
  45.     return turtle.transferTo(id, nb)
  46. end
  47.  
  48. function testFuel()
  49.     if(fuel() < 16)then
  50.         print('Plus de coco, test de refuel')
  51.         select(16)
  52.         turtle.refuel(1)
  53.     end
  54.     if(count(16) == 0)then
  55.         return false
  56.     end
  57.     return true
  58. end
  59.  
  60.  
  61.  
  62.  
  63. function init()
  64.     if(count(16) == 0)then
  65.         print("Besoin de fuel en slot 16, exit")
  66.         return false
  67.     end
  68.     if(count(15) == 0)then
  69.         print("Besoin du bois a placer en slot 15...")
  70.         return false
  71.     end
  72.     if(testFuel()==false)then
  73.         return false
  74.     end
  75.     return true
  76. end
  77.  
  78.  
  79.  
  80. function whaitGo(i)
  81.     if(i == null)then
  82.         i=1
  83.     end
  84.     if(i> 60)then
  85.         return false
  86.     end
  87.     if(i> 10)then
  88.         turtle.attack()
  89.     end
  90.     if(go()==false)then
  91.         turtle.dig()
  92.         sleep(1)
  93.         return whaitGo(i+1)
  94.     end
  95.     testFuel()
  96.     return true
  97. end
  98.  
  99. function whaitUp(i)
  100.     if(i == null)then
  101.         i=1
  102.     end
  103.     if(i> 60)then
  104.         return false
  105.     end
  106.     if(up()==false)then
  107.         turtle.digUp()
  108.         sleep(1)
  109.         return whaitUp(i+1)
  110.     end
  111.     testFuel()
  112.     return true
  113. end
  114.  
  115. function whaitDown(i)
  116.     if(i == null)then
  117.         i=1
  118.     end
  119.     if(i> 60)then
  120.         return false
  121.     end
  122.     if(down()==false)then
  123.         turtle.digDown()
  124.         sleep(1)
  125.         return whaitDown(i+1)
  126.     end
  127.     testFuel()
  128.     return true
  129. end
  130.  
  131.  
  132. function whaitBack(i)
  133.     if(i == null)then
  134.         i=1
  135.     end
  136.     if(i> 60)then
  137.         return false
  138.     end
  139.     if(i> 10)then
  140.         turtle.attack()
  141.     end
  142.     if(back()==false)then
  143.         sleep(2)
  144.         return whaitBack(i+1)
  145.     end
  146.     testFuel()
  147.     return true
  148. end
  149.  
  150. function placeDown()
  151.     local ifor = 1
  152.     select(15)
  153.     if(turtle.compareDown()==false)then
  154.         if(turtle.detectDown()==true)then
  155.             turtle.digDown()
  156.         end
  157.         for ifor = 1, 15 do
  158.             if(count(ifor)>0)then
  159.                 select(ifor)
  160.                 if(turtle.compareTo(15)==true)then
  161.                     if(turtle.placeDown()==false)then
  162.                         print("placeDown == false")
  163.                         return placeDown()
  164.                     else
  165.                         whaitBlock()
  166.                         return true
  167.                     end
  168.                 end
  169.             end
  170.         end
  171.     end
  172. end
  173. function place()
  174.     local ifor = 1
  175.     select(15)
  176.  
  177.     if(turtle.compare()==false)then
  178.         if(turtle.detect()==true)then
  179.             turtle.dig()
  180.         end
  181.         for ifor = 1, 15 do
  182.             if(count(ifor)>0)then
  183.                 select(ifor)
  184.                 if(turtle.compareTo(15)==true)then
  185.                     if(turtle.place()==false)then
  186.                         print("place == false")
  187.                         return place()
  188.                     else
  189.                         whaitBlock()
  190.                         return true
  191.                     end
  192.                 end
  193.             end
  194.         end
  195.     end
  196. end
  197.  
  198. function whaitBlock()
  199.     if(count(15)==0)then
  200.         sleep(5)
  201.         print("j'attend des block <3")
  202.         return whaitBlock()
  203.     end
  204. end
  205.  
  206. function enderspot()
  207.     for toto=0,2 do
  208.         for titi=0,3 do
  209.             whaitGo()
  210.             placeRight()
  211.         end
  212.         place()
  213.         left()
  214.     end
  215. end
  216. function enderspot2()
  217.     for toto=0,2 do
  218.         for titi=0,3 do
  219.             whaitGo()
  220.             placeRight()
  221.             placeDown()
  222.         end
  223.         place()
  224.         left()
  225.     end
  226. end
  227.  
  228.  
  229.  
  230. function placeRight()
  231.     right()
  232.     place()
  233.     left()
  234. end
  235.  
  236.  
  237. --  __  __       _        ____
  238. -- |  \/  | __ _(_)_ __  / /\ \
  239. -- | |\/| |/ _` | | '_ \| |  | |
  240. -- | |  | | (_| | | | | | |  | |
  241. -- |_|  |_|\__,_|_|_| |_| |  | |
  242. --                       \_\/_/
  243.  
  244.  
  245. args = { ... }
  246. if( args[1]==null)then
  247.     args[1] = "r"
  248.     --print("Début de 'tree', par defaut, "..args[1].." blocks")
  249. else
  250.     --print("Début de 'tree', "..args[1].." blocks")
  251. end
  252.  
  253. stop=false
  254. if(init()==false) then
  255.     stop=true
  256. end
  257. if (stop==false) then
  258.     thei = 0
  259.     thei2 = 0
  260.     len = 9
  261.    
  262.     for thei2 = 0,3 do
  263.         for thei=0,len do
  264.             placeDown()
  265.             whaitGo()
  266.             if(turtle.detectUp()==true)then
  267.                 turtle.digUp()
  268.             end
  269.         end
  270.         if(args[1] == "r")then
  271.             right()
  272.         else
  273.             left()
  274.         end
  275.     end
  276.     whaitGo()
  277.     if(args[1] == "r")then
  278.         right()
  279.     else
  280.         left()
  281.     end
  282.     whaitGo()
  283.     whaitDown()
  284.     if(args[1] == "r")then
  285.         left()
  286.     else
  287.         right()
  288.     end
  289.     len = len -2
  290.     while len > 0 do
  291.         for thei2 = 0,3 do
  292.             for thei=0,len do
  293.                 placeDown()
  294.                 whaitGo()
  295.                 if(turtle.detectUp()==true)then
  296.                     turtle.digUp()
  297.                 end
  298.             end
  299.             if(args[1] == "r")then
  300.                 right()
  301.             else
  302.                 left()
  303.             end
  304.         end
  305.         whaitGo()
  306.         if(args[1] == "r")then
  307.             right()
  308.         else
  309.             left()
  310.         end
  311.         whaitGo()
  312.         if(turtle.detectUp()==true)then
  313.             select(15)
  314.             if(turtle.compareDown()==false)then
  315.                 select(1)
  316.                 turtle.digUp()
  317.             end
  318.             select(1)
  319.         end
  320.         if(args[1] == "r")then
  321.             left()
  322.         else
  323.             right()
  324.         end
  325.         len = len -2
  326.     end
  327.  
  328.     placeDown()
  329.    
  330.    
  331.     for y=0,2 do
  332.         whaitUp()
  333.     end
  334.     whaitGo()
  335.     left()
  336.     left()
  337. end
  338.  
  339. print('End')
  340. if(fuel() == 0) then
  341.   print('Ya plus de coco mon coco !')
  342. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement