Advertisement
AdslHouba

Botania Livingwood/rock auto (Avec déplacement)

May 7th, 2015
520
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.72 KB | None | 0 0
  1. -- Robot producteur de ressource botania
  2. -- Video : https://www.youtube.com/watch?v=LSnDyYUoZYI
  3.  
  4. -- Function deplacement + refuel
  5. function deplace()
  6.     info("Deplacement "..turtle.getFuelLevel())
  7.     if turtle.getFuelLevel()==0 then
  8.         turtle.select(16)
  9.     turtle.refuel(1)
  10.     end
  11.     turtle.forward()
  12. end
  13.  
  14. -- Verification si faut sortir du sommeil pour recolte
  15. -- false si recoltable ou vide
  16. -- true si non recoltable
  17. function verif()
  18.     ok, donne = turtle.inspectDown()
  19.   if ok then
  20.     if donne.name=="Botania:livingrock" then
  21.       return false
  22.     elseif donne.name=="Botania:livingwood" then
  23.       return false
  24.     else
  25.       return true
  26.     end
  27.   else
  28.     perma=false
  29.     return false
  30.   end
  31. end
  32. -- Verification si block present en dessous
  33. function stop()
  34.   ok, donne = turtle.inspectDown()
  35.   if ok==false then
  36.     return true
  37.   else
  38.      return false
  39.   end
  40. end
  41. -- Attent et change le block en dessous
  42. function change()
  43.     info("Attente")
  44.     while verif() do
  45.         os.sleep(3)
  46.     end
  47.  
  48.     info("Minage / placement")
  49.     turtle.select(2)
  50.     turtle.digDown()
  51.     turtle.select(1)
  52.     turtle.placeDown()
  53. end
  54. -- Affichage info
  55. function info(text)
  56.     term.clear()
  57.     term.setCursorPos(1,1)
  58.     print(text)
  59. end
  60.  
  61. local perma=true
  62. -- function recolte
  63. function go()
  64.     local pos=0
  65.     local coin=0   
  66.     -- boucle temps que recoltable
  67.     while perma do
  68.         -- change le block
  69.         change()    
  70.         -- avance
  71.         deplace()  
  72.         -- verification position pour tourner dans les angle
  73.         pos=pos+1
  74.             if pos==2 then      
  75.             if coin==3 then
  76.                 -- point de depart
  77.                     info("Depart")
  78.                     turtle.turnLeft()
  79.                 -- pose de la recolte
  80.                     turtle.select(2)
  81.                 turtle.drop()
  82.                     -- stop si plus rien a recolter
  83.                     if stop() then
  84.                         return
  85.                         info("Fin")
  86.                     end
  87.                     -- chargement roche ou bois
  88.                     turtle.turnRight()
  89.                     charge()
  90.                 -- chargement charbon
  91.                     info("Charge charbon")
  92.                 if turtle.getItemCount(16) == 0 then
  93.                     turtle.select(16)
  94.                     turtle.suckUp()
  95.                 end    
  96.                     -- positionnemetn
  97.                     turtle.turnRight()
  98.                 coin=0
  99.             else
  100.                 turtle.turnRight() 
  101.                     coin=coin+1
  102.             end
  103.             pos=0
  104.            
  105.         end
  106.     end
  107. end
  108. -- fonction chargement roche - bois
  109. function charge()
  110.     info("Charge obj")
  111.     -- si moins de 8 on charge
  112.     if turtle.getItemCount(1) < 8 then
  113.         turtle.select(1)
  114.         turtle.suck()
  115.             qte=turtle.getItemCount(1)
  116.         -- si toujours moins de 8 on drop dans le corffre
  117.         if qte<8 then
  118.                 turtle.drop()
  119.         end
  120.         -- si trop de ressource on drop dans le coffre
  121.             if turtle.getItemCount(2) ~= 0 then
  122.             turtle.select(2)
  123.                 turtle.drop()
  124.         end
  125.     end
  126. end
  127. -- premier tour sans recolte, juste pose
  128. function premier()
  129.     info("Depos ressource vide")
  130.     local pos=0
  131.     local coin=0   
  132.     local perma2=true
  133.     turtle.select(1)
  134.     -- boucle sur un tour
  135.     while perma2 do    
  136.         turtle.placeDown()
  137.         deplace()    
  138.         pos=pos+1
  139.         if pos==2 then      
  140.             if coin==3 then
  141.                 -- si depart on stop pour passer en normal
  142.                     turtle.turnRight()
  143.                     perma2=false
  144.                     return
  145.             else
  146.                 turtle.turnRight() 
  147.                     coin=coin+1
  148.             end
  149.             pos=0
  150.            
  151.         end
  152.     end
  153. end
  154.  
  155. -- placement en fonction des deux cote vide
  156. info("Placement");
  157. ok=0
  158. while ok<2 do
  159.     turtle.turnLeft()
  160.     presence, donne = turtle.inspect()
  161.     if presence then
  162.         ok=0
  163.     else
  164.         ok=ok+1
  165.     end
  166. end
  167.  
  168. turtle.turnLeft()
  169. charge()
  170. turtle.turnRight()
  171.  
  172. -- si pas vide on passee en normal
  173. ok, donne = turtle.inspectDown()
  174. if ok then
  175.     go()
  176. else
  177.     -- si vide on verifie les ressources et on fait une premier tour
  178.     if turtle.getItemCount(1) == 0 then
  179.         info("Pas de ressource")
  180.     else
  181.         premier()
  182.         go()
  183.     end
  184. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement