Advertisement
meuced

bucheron

Mar 29th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.32 KB | None | 0 0
  1. local temporisation = 30        --secondes à attendre entre chaque ligne
  2. local niveauFuelMini = 100      -- niveau de déplacements auquel on doit refaire le plein de fuel
  3. local niveauCharbonMini = 0     -- quantité de charbons restants à laquelle on doit refaire le plein de charbon
  4. local niveauSaplingMini = 10
  5. local saplingSlot = 1
  6. local premierSlot = 2                                   -- premier slot où se trouve le minerai ramassé
  7. local dernierSlot = 15                                  -- dernier slot à surveiller pour enclencher le vidage de l'inventaire
  8. local charbonSlot = 16
  9. local direction = 0
  10.  
  11. function verifFuel()                                    -- vérifie si on a assez de fuel (déplacements) en réserve.
  12.   -- 1 charbon = 96 deplacements
  13.   -- On vérifie le niveau de fuel
  14.         local niveauFuel = turtle.getFuelLevel()
  15.         if (niveauFuel ~= "unlimited") then
  16.                 if (niveauFuel < niveauFuelMini) then
  17.                         -- On a besoin de faire le plein
  18.                         turtle.select(charbonSlot)
  19.                         turtle.refuel(5) -- on recharge
  20.                         -- et on vérifie si il nous reste assez de charbon
  21.                         if turtle.getItemCount(charbonSlot) < niveauCharbonMini then
  22.                                 return rechargeCharbon() -- on refait le plein de charbon
  23.                         end
  24.                 end
  25.         end
  26. end
  27.  
  28. function rechargeSapling()
  29.  
  30.     --on se remet en direction "un", face au coffre
  31.     while direction ~= 1 do
  32.             turtle.turnRight()
  33.             direction=direction+1
  34.             if direction == 4 then direction = 0 end
  35.     end
  36.  
  37.     turtle.select(saplingSlot)
  38.     turtle.suck()
  39.  
  40.     --on se remet en direction "zéro"
  41.     while direction ~= 0 do
  42.         turtle.turnRight()
  43.         direction=direction+1
  44.         if direction == 4 then direction = 0 end
  45.     end
  46.  
  47. end
  48.  
  49. function rechargeCharbon()
  50.  
  51.         --on prend du charbon dans le coffre au-dessus de la tortue
  52.         turtle.select(charbonSlot)
  53.         turtle.suckUp()
  54.         if turtle.getItemCount(charbonSlot) < 6 then
  55.             print("Merci de remettre du charbon !")
  56.             print("Appuez sur ENTREE pour reprendre.")
  57.             local a = read()
  58.         end
  59.  
  60. end
  61.  
  62. function videInventaire()
  63.        
  64.         --on se remet en direction "deux", face au coffre
  65.         while direction ~= 2 do
  66.                 turtle.turnRight()
  67.                 direction=direction+1
  68.                 if direction == 4 then direction = 0 end
  69.         end
  70.        
  71.         --on vide l'inventaire
  72.         for slot=premierSlot,dernierSlot do
  73.                 turtle.select(slot)
  74.                 while turtle.getItemCount(slot) > 0 do
  75.                         turtle.drop(turtle.getItemCount(slot))
  76.                         if turtle.getItemCount(slot) > 0 then
  77.                                 sleep(0.5)
  78.                         end
  79.                 end
  80.         end
  81.        
  82.         --on se remet en direction "zéro"
  83.         while direction ~= 0 do
  84.                 turtle.turnRight()
  85.                 direction=direction+1
  86.                 if direction == 4 then direction = 0 end
  87.         end
  88.  
  89. end
  90.  
  91. verifFuel()
  92. turtle.forward()
  93. while true do
  94.     turtle.select(1)
  95.     turtle.turnRight()
  96.     if turtle.compare() == false then
  97.         for i=1,8 do
  98.             turtle.dig()
  99.             if i ~= 8 then
  100.                 turtle.digUp()
  101.                 turtle.up()
  102.             end
  103.         end
  104.         for i=1,7 do
  105.             turtle.down()
  106.         end
  107.         turtle.place()
  108.     end
  109.     turtle.turnLeft()
  110.     for i=1, 3 do
  111.         if turtle.forward() == false then
  112.             turtle.turnLeft()
  113.             turtle.forward()
  114.             turtle.turnLeft()
  115.             verifFuel()
  116.             if turtle.getItemCount(dernierSlot) > 0 then
  117.                 videInventaire()
  118.             end
  119.             if turtle.getItemCount(saplingSlot) < niveauSaplingMini then
  120.                 rechargeSapling()
  121.             end
  122.             sleep(temporisation)
  123.             turtle.forward()
  124.             break
  125.         end
  126.     end
  127.     sleep(0.1)
  128. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement