giwdul

MiningTurtle

Jun 12th, 2025 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.33 KB | None | 0 0
  1. -- Programme de minage de tunnel 1x10
  2. -- Slot 1 : Coffres pour vider l'inventaire
  3.  
  4. -- Configuration
  5. local TUNNEL_HEIGHT = 10
  6. local CHEST_SLOT = 1
  7. local MIN_FUEL_LEVEL = 100
  8.  
  9. -- Variables globales
  10. local totalDistance = 0
  11.  
  12. -- Fonction pour vérifier et refaire le plein de carburant
  13. function checkFuel()
  14.     local fuel = turtle.getFuelLevel()
  15.     if fuel < MIN_FUEL_LEVEL then
  16.         print("Niveau de carburant bas: " .. fuel)
  17.        
  18.         -- Chercher du carburant dans l'inventaire
  19.         for slot = 2, 16 do
  20.             turtle.select(slot)
  21.             if turtle.refuel(0) then -- Test si c'est du carburant
  22.                 local needed = MIN_FUEL_LEVEL * 2 - fuel
  23.                 turtle.refuel(math.ceil(needed / 80)) -- 80 = carburant par charbon
  24.                 print("Carburant ajouté. Nouveau niveau: " .. turtle.getFuelLevel())
  25.                 break
  26.             end
  27.         end
  28.        
  29.         if turtle.getFuelLevel() < MIN_FUEL_LEVEL then
  30.             print("ATTENTION: Carburant insuffisant!")
  31.             print("Ajoutez du charbon/bois dans l'inventaire")
  32.         end
  33.     end
  34. end
  35.  
  36. -- Fonction pour vérifier si l'inventaire est plein
  37. function isInventoryFull()
  38.     for slot = 2, 16 do -- On skip le slot 1 (coffres)
  39.         if turtle.getItemCount(slot) == 0 then
  40.             return false
  41.         end
  42.     end
  43.     return true
  44. end
  45.  
  46. -- Fonction pour vider l'inventaire dans un coffre
  47. function emptyInventory()
  48.     print("Inventaire plein - Vidage en cours...")
  49.    
  50.     -- Sélectionner le slot des coffres
  51.     turtle.select(CHEST_SLOT)
  52.    
  53.     -- Vérifier qu'on a des coffres
  54.     if turtle.getItemCount(CHEST_SLOT) == 0 then
  55.         print("ERREUR: Pas de coffre dans le slot 1!")
  56.         return false
  57.     end
  58.    
  59.     -- Placer le coffre en bas
  60.     turtle.digDown()
  61.     if not turtle.placeDown() then
  62.         print("ERREUR: Impossible de placer le coffre!")
  63.         return false
  64.     end
  65.    
  66.     -- Vider tous les slots sauf le slot 1
  67.     for slot = 2, 16 do
  68.         turtle.select(slot)
  69.         turtle.dropDown()
  70.     end
  71.    
  72.     print("Inventaire vidé avec succès!")
  73.     turtle.select(1)
  74.     return true
  75. end
  76.  
  77. -- Fonction pour creuser en gérant le gravier/sable
  78. function digSafe()
  79.     while turtle.detect() do
  80.         turtle.dig()
  81.         sleep(0.5) -- Attendre que le gravier/sable tombe
  82.     end
  83. end
  84.  
  85. -- Fonction pour creuser vers le haut en gérant le gravier/sable
  86. function digUpSafe()
  87.     while turtle.detectUp() do
  88.         turtle.digUp()
  89.         sleep(0.5)
  90.     end
  91. end
  92.  
  93. -- Fonction pour miner une colonne de 10 blocs
  94. function mineColumn()
  95.     -- Miner vers le haut
  96.     for height = 1, TUNNEL_HEIGHT - 1 do
  97.         digUpSafe()
  98.         turtle.up()
  99.     end
  100.    
  101.     -- Redescendre
  102.     for height = 1, TUNNEL_HEIGHT - 1 do
  103.         turtle.down()
  104.     end
  105. end
  106.  
  107. -- Fonction pour avancer et miner
  108. function mineForward()
  109.     -- Vérifier le carburant
  110.     checkFuel()
  111.    
  112.     -- Creuser devant si nécessaire
  113.     digSafe()
  114.    
  115.     -- Avancer
  116.     if turtle.forward() then
  117.         totalDistance = totalDistance + 1
  118.        
  119.         -- Miner la colonne complète
  120.         mineColumn()
  121.        
  122.         -- Vérifier si on doit vider l'inventaire
  123.         if isInventoryFull() then
  124.             emptyInventory()
  125.         end
  126.        
  127.         return true
  128.     else
  129.         print("Impossible d'avancer - Obstacle!")
  130.         return false
  131.     end
  132. end
  133.  
  134. -- Fonction principale
  135. function main()
  136.     print("=== Programme de minage de tunnel ===")
  137.     print("Dimensions: 1 large x " .. TUNNEL_HEIGHT .. " haut")
  138.     print("Assurez-vous d'avoir:")
  139.     print("- Des coffres dans le slot 1")
  140.     print("- Du carburant (charbon/bois)")
  141.     print("")
  142.     print("Démarrage dans 3 secondes...")
  143.     sleep(3)
  144.    
  145.     -- Boucle infinie de minage
  146.     while true do
  147.         if not mineForward() then
  148.             print("Arrêt du programme - Obstacle infranchissable")
  149.             break
  150.         end
  151.        
  152.         -- Afficher la progression tous les 10 blocs
  153.         if totalDistance % 10 == 0 then
  154.             print("Distance parcourue: " .. totalDistance .. " blocs")
  155.             print("Carburant restant: " .. turtle.getFuelLevel())
  156.         end
  157.     end
  158.    
  159.     print("Programme terminé.")
  160.     print("Distance totale: " .. totalDistance .. " blocs")
  161. end
  162.  
  163. -- Lancer le programme
  164. main()
Add Comment
Please, Sign In to add comment