Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Programme de minage de tunnel 1x10
- -- Slot 1 : Coffres pour vider l'inventaire
- -- Configuration
- local TUNNEL_HEIGHT = 10
- local CHEST_SLOT = 1
- local MIN_FUEL_LEVEL = 100
- -- Variables globales
- local totalDistance = 0
- -- Fonction pour vérifier et refaire le plein de carburant
- function checkFuel()
- local fuel = turtle.getFuelLevel()
- if fuel < MIN_FUEL_LEVEL then
- print("Niveau de carburant bas: " .. fuel)
- -- Chercher du carburant dans l'inventaire
- for slot = 2, 16 do
- turtle.select(slot)
- if turtle.refuel(0) then -- Test si c'est du carburant
- local needed = MIN_FUEL_LEVEL * 2 - fuel
- turtle.refuel(math.ceil(needed / 80)) -- 80 = carburant par charbon
- print("Carburant ajouté. Nouveau niveau: " .. turtle.getFuelLevel())
- break
- end
- end
- if turtle.getFuelLevel() < MIN_FUEL_LEVEL then
- print("ATTENTION: Carburant insuffisant!")
- print("Ajoutez du charbon/bois dans l'inventaire")
- end
- end
- end
- -- Fonction pour vérifier si l'inventaire est plein
- function isInventoryFull()
- for slot = 2, 16 do -- On skip le slot 1 (coffres)
- if turtle.getItemCount(slot) == 0 then
- return false
- end
- end
- return true
- end
- -- Fonction pour vider l'inventaire dans un coffre
- function emptyInventory()
- print("Inventaire plein - Vidage en cours...")
- -- Sélectionner le slot des coffres
- turtle.select(CHEST_SLOT)
- -- Vérifier qu'on a des coffres
- if turtle.getItemCount(CHEST_SLOT) == 0 then
- print("ERREUR: Pas de coffre dans le slot 1!")
- return false
- end
- -- Placer le coffre en bas
- turtle.digDown()
- if not turtle.placeDown() then
- print("ERREUR: Impossible de placer le coffre!")
- return false
- end
- -- Vider tous les slots sauf le slot 1
- for slot = 2, 16 do
- turtle.select(slot)
- turtle.dropDown()
- end
- print("Inventaire vidé avec succès!")
- turtle.select(1)
- return true
- end
- -- Fonction pour creuser en gérant le gravier/sable
- function digSafe()
- while turtle.detect() do
- turtle.dig()
- sleep(0.5) -- Attendre que le gravier/sable tombe
- end
- end
- -- Fonction pour creuser vers le haut en gérant le gravier/sable
- function digUpSafe()
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.5)
- end
- end
- -- Fonction pour miner une colonne de 10 blocs
- function mineColumn()
- -- Miner vers le haut
- for height = 1, TUNNEL_HEIGHT - 1 do
- digUpSafe()
- turtle.up()
- end
- -- Redescendre
- for height = 1, TUNNEL_HEIGHT - 1 do
- turtle.down()
- end
- end
- -- Fonction pour avancer et miner
- function mineForward()
- -- Vérifier le carburant
- checkFuel()
- -- Creuser devant si nécessaire
- digSafe()
- -- Avancer
- if turtle.forward() then
- totalDistance = totalDistance + 1
- -- Miner la colonne complète
- mineColumn()
- -- Vérifier si on doit vider l'inventaire
- if isInventoryFull() then
- emptyInventory()
- end
- return true
- else
- print("Impossible d'avancer - Obstacle!")
- return false
- end
- end
- -- Fonction principale
- function main()
- print("=== Programme de minage de tunnel ===")
- print("Dimensions: 1 large x " .. TUNNEL_HEIGHT .. " haut")
- print("Assurez-vous d'avoir:")
- print("- Des coffres dans le slot 1")
- print("- Du carburant (charbon/bois)")
- print("")
- print("Démarrage dans 3 secondes...")
- sleep(3)
- -- Boucle infinie de minage
- while true do
- if not mineForward() then
- print("Arrêt du programme - Obstacle infranchissable")
- break
- end
- -- Afficher la progression tous les 10 blocs
- if totalDistance % 10 == 0 then
- print("Distance parcourue: " .. totalDistance .. " blocs")
- print("Carburant restant: " .. turtle.getFuelLevel())
- end
- end
- print("Programme terminé.")
- print("Distance totale: " .. totalDistance .. " blocs")
- end
- -- Lancer le programme
- main()
Add Comment
Please, Sign In to add comment