Advertisement
RLPGhost

Bois de vie

Oct 9th, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.48 KB | None | 0 0
  1. -- Programme de Minage en tunnel sur le nombre de blocks voulu
  2. -- http://pastebin.com/CiyHEnUd
  3.  
  4. -- fonction refuel
  5.  
  6.  
  7. local niveauFuelMini = 5          -- niveau de déplacements auquel on doit refaire le plein de fuel
  8. local niveauCharbonMini = 1
  9.  
  10. local slotBois = 1        -- foction inventaire
  11. local slotBoisDeVie = 2
  12. local enderchestCharbonSlot = 15
  13. local enderchestBois = 14
  14. local enderchestVidage = 13
  15. local charbonSlot = 16
  16.  
  17. function verifFuel()              -- vérifie si on a assez de fuel (déplacements) en réserve.
  18.   -- 1 charbon = 96 deplacements
  19.   -- On vérifie le niveau de fuel
  20.         local niveauFuel = turtle.getFuelLevel()
  21.         if (niveauFuel ~= "unlimited") then
  22.                 if (niveauFuel < niveauFuelMini) then
  23.                         -- On a besoin de faire le plein
  24.                         turtle.select(charbonSlot)
  25.                         turtle.refuel(1) -- on recharge pour 96 deplacements
  26.                         if turtle.getItemCount(charbonSlot) < niveauCharbonMini then
  27.                                 rechargeCharbon() -- on refait le plein de charbon
  28.                         end
  29.                 end
  30.         end
  31. end
  32.  
  33. function rechargeCharbon()                              -- permet de refaire le plein en charbon
  34.        
  35.     turtle.select(enderchestCharbonSlot)
  36.     turtle.placeUp()
  37.     turtle.select(charbonSlot)
  38.     turtle.suckUp()
  39.    
  40.     turtle.select(enderchestCharbonSlot)
  41.     turtle.digUp()
  42.        
  43. end
  44.  
  45. function mineDevant()
  46.     while turtle.detect() do turtle.dig() end
  47. end
  48.  
  49. function movForward()
  50.     while not turtle.forward() do
  51.         sleep(1)
  52.     end
  53.     return true
  54. end
  55.  
  56. function videInventaire()   -- if turtle.getItemCount(dernierSlot) > 0
  57.  
  58.         local slot
  59.         turtle.select(enderchestVidage)
  60.         turtle.placeUp()
  61.        
  62.         turtle.select(slotBoisDeVie)
  63.        
  64.         while turtle.getItemCount(slotBoisDeVie) > 2 do
  65.             turtle.dropUp(turtle.getItemCount(slotBoisDeVie))
  66.             if turtle.getItemCount(slot) > 2 then
  67.                 sleep(0.5)
  68.             end
  69.         end
  70.  
  71.         turtle.select(enderchestVidage)
  72.         turtle.digUp()
  73. end
  74.  
  75. function turn(Str)
  76.     if Str == "G" then turtle.turnLeft()
  77.     else turtle.turnRight()
  78.     end
  79. end
  80.  
  81. function compare_mine()  
  82.  
  83.         local detectbloc = turtle.detect()
  84.  
  85.         if detectbloc == false then
  86.             turtle.select(slotBois)
  87.             detectLevelBois()
  88.             turtle.place()
  89.         end
  90.        
  91.         if detectbloc == true then
  92.             turtle.select(slotBoisDeVie)
  93.             if turtle.compare() == true then
  94.                 detectLevelBoisDeVie()
  95.                 turtle.dig()
  96.                 turtle.select(slotBois)
  97.                 detectLevelBois()
  98.                 turtle.place()
  99.                 turtle.select(slotBoisDeVie)
  100.             end
  101.            
  102.         end    
  103. end
  104.  
  105. function detectLevelBois()
  106.  
  107. -- controle du niveau avant de poser
  108.    
  109.     turtle.select(slotBois)
  110.    
  111.     if turtle.getItemCount(slotBois) < 2 then
  112.  
  113.         turtle.select(enderchestBois)
  114.         turtle.placeUp()
  115.         turtle.select(slotBois)
  116.         turtle.suckUp()
  117.         turtle.select(enderchestBois)
  118.         turtle.digUp()
  119.         turtle.select(slotBois)
  120.    
  121.     end
  122.  
  123. end
  124.  
  125. function detectLevelBoisDeVie()
  126.  
  127. -- controle du niveau avant de prendre
  128.    
  129.     turtle.select(slotBoisDeVie)
  130.    
  131.     if turtle.getItemCount(slotBoisDeVie) > 5 then
  132.    
  133.         videInventaire()
  134.    
  135.     end
  136.    
  137. end
  138.  
  139. --********************************************--
  140. --********** Programme principal *************--
  141. --********************************************--
  142.  
  143. -- Début du minage
  144.  
  145. verifFuel()
  146.  
  147. while true do
  148.  
  149. local x = 0
  150. while x < 11 do
  151.    
  152.     print("x: "..x)
  153.     verifFuel()
  154.     movForward()
  155.     turn("G")
  156.     compare_mine()
  157.     turn("D")
  158.     x=x+1
  159.        
  160. end
  161.  
  162. movForward()
  163. turn("G")
  164.  
  165. local x = 0
  166. while x < 3 do
  167.    
  168.     print("x: "..x)
  169.     verifFuel()
  170.     movForward()
  171.     turn("G")
  172.     compare_mine()
  173.     turn("D")
  174.     x=x+1
  175.        
  176. end
  177.  
  178. movForward()
  179. turn("G")
  180.  
  181. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement