Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configuration
- local width = 3 -- Largeur du puits (X)
- local length = 3 -- Longueur du puits (Y)
- local fuelThreshold = 100 -- Niveau de carburant minimum avant de refaire le plein
- -- Variables
- local digDepth = 0 -- Profondeur actuelle
- local bedrockFound = false
- local homeX, homeY, homeZ = 0, 0, 0 -- Coordonnées du point de départ
- local currentX, currentY, currentZ = 0, 0, 0 -- Position actuelle de la tortue
- -- Fonction pour vérifier et refaire le plein de carburant si nécessaire
- function checkFuel()
- local currentFuel = turtle.getFuelLevel()
- -- Estimer la quantité de carburant nécessaire pour retourner à la surface
- local fuelNeededToReturn = digDepth + 10 -- +10 pour la marge
- if currentFuel < fuelThreshold + fuelNeededToReturn then
- print("Niveau de carburant bas (" .. currentFuel .. "). Retour à la surface pour refaire le plein.")
- returnToSurface()
- refuel()
- returnToDiggingSite()
- end
- end
- -- Fonction pour vider l'inventaire dans le coffre à gauche
- function dumpInventory()
- print("Vidage de l'inventaire...")
- turtle.turnLeft()
- turtle.select(1)
- for i = 1, 16 do
- local item = turtle.getItemDetail(i)
- if item and item.name ~= "minecraft:coal" and item.name ~= "minecraft:charcoal" then
- turtle.select(i)
- turtle.drop()
- end
- end
- turtle.turnRight()
- end
- -- Fonction pour refaire le plein depuis le coffre à droite
- function refuel()
- print("Ravitaillement en carburant...")
- turtle.turnRight()
- -- Chercher l'emplacement d'un slot vide
- local emptySlot = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- emptySlot = i
- break
- end
- end
- if emptySlot > 0 then
- turtle.select(emptySlot)
- turtle.suck(64) -- Prendre du charbon
- -- Refaire le plein
- local fuelNeeded = true
- while fuelNeeded do
- if turtle.getItemCount(emptySlot) > 0 then
- turtle.refuel()
- else
- turtle.suck(64)
- if turtle.getItemCount(emptySlot) == 0 then
- fuelNeeded = false
- end
- end
- if turtle.getFuelLevel() > 5000 then
- fuelNeeded = false
- end
- end
- end
- turtle.turnLeft()
- print("Niveau de carburant actuel: " .. turtle.getFuelLevel())
- end
- -- Fonction pour creuser une seule couche du puits
- function digLayer()
- local forward = true
- for w = 1, width do
- for l = 1, length - 1 do
- if not bedrockFound then
- if forward then
- turtle.dig()
- if not turtle.forward() then
- if turtle.detect() then
- -- Vérifions si c'est du bedrock
- success, block = turtle.inspect()
- if success and block.name == "minecraft:bedrock" then
- bedrockFound = true
- print("Bedrock détecté à la profondeur " .. digDepth)
- break
- end
- end
- else
- -- Mise à jour des coordonnées
- if turtle.getDirection() == 0 then -- Face au sud
- currentX = currentX + 1
- elseif turtle.getDirection() == 1 then -- Face à l'ouest
- currentY = currentY - 1
- elseif turtle.getDirection() == 2 then -- Face au nord
- currentX = currentX - 1
- elseif turtle.getDirection() == 3 then -- Face à l'est
- currentY = currentY + 1
- end
- end
- else
- turtle.dig()
- if not turtle.forward() then
- if turtle.detect() then
- -- Vérifions si c'est du bedrock
- success, block = turtle.inspect()
- if success and block.name == "minecraft:bedrock" then
- bedrockFound = true
- print("Bedrock détecté à la profondeur " .. digDepth)
- break
- end
- end
- else
- -- Mise à jour des coordonnées
- if turtle.getDirection() == 0 then -- Face au sud
- currentX = currentX + 1
- elseif turtle.getDirection() == 1 then -- Face à l'ouest
- currentY = currentY - 1
- elseif turtle.getDirection() == 2 then -- Face au nord
- currentX = currentX - 1
- elseif turtle.getDirection() == 3 then -- Face à l'est
- currentY = currentY + 1
- end
- end
- end
- end
- end
- if bedrockFound then break end
- if w < width then
- if forward then
- turtle.turnRight()
- turtle.dig()
- if not turtle.forward() then
- -- Vérifions si c'est du bedrock
- success, block = turtle.inspect()
- if success and block.name == "minecraft:bedrock" then
- bedrockFound = true
- print("Bedrock détecté à la profondeur " .. digDepth)
- break
- end
- else
- -- Mise à jour des coordonnées
- if turtle.getDirection() == 0 then -- Face au sud
- currentX = currentX + 1
- elseif turtle.getDirection() == 1 then -- Face à l'ouest
- currentY = currentY - 1
- elseif turtle.getDirection() == 2 then -- Face au nord
- currentX = currentX - 1
- elseif turtle.getDirection() == 3 then -- Face à l'est
- currentY = currentY + 1
- end
- end
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.dig()
- if not turtle.forward() then
- -- Vérifions si c'est du bedrock
- success, block = turtle.inspect()
- if success and block.name == "minecraft:bedrock" then
- bedrockFound = true
- print("Bedrock détecté à la profondeur " .. digDepth)
- break
- end
- else
- -- Mise à jour des coordonnées
- if turtle.getDirection() == 0 then -- Face au sud
- currentX = currentX + 1
- elseif turtle.getDirection() == 1 then -- Face à l'ouest
- currentY = currentY - 1
- elseif turtle.getDirection() == 2 then -- Face au nord
- currentX = currentX - 1
- elseif turtle.getDirection() == 3 then -- Face à l'est
- currentY = currentY + 1
- end
- end
- turtle.turnLeft()
- end
- forward = not forward
- end
- end
- -- Retour à la position initiale de la couche
- returnToLayerStart(forward)
- end
- -- Fonction pour retourner à la position initiale d'une couche
- function returnToLayerStart(wasForward)
- if bedrockFound then return end
- if wasForward then
- -- Si on était en train d'avancer, on doit faire demi-tour
- turtle.turnRight()
- turtle.turnRight()
- -- Parcourir à l'envers
- for l = 1, length - 1 do
- turtle.forward()
- -- Mise à jour des coordonnées
- if turtle.getDirection() == 0 then -- Face au sud
- currentX = currentX + 1
- elseif turtle.getDirection() == 1 then -- Face à l'ouest
- currentY = currentY - 1
- elseif turtle.getDirection() == 2 then -- Face au nord
- currentX = currentX - 1
- elseif turtle.getDirection() == 3 then -- Face à l'est
- currentY = currentY + 1
- end
- end
- -- Maintenant se replacer pour la prochaine couche
- for w = 1, width - 1 do
- turtle.turnLeft()
- turtle.forward()
- -- Mise à jour des coordonnées
- if turtle.getDirection() == 0 then -- Face au sud
- currentX = currentX + 1
- elseif turtle.getDirection() == 1 then -- Face à l'ouest
- currentY = currentY - 1
- elseif turtle.getDirection() == 2 then -- Face au nord
- currentX = currentX - 1
- elseif turtle.getDirection() == 3 then -- Face à l'est
- currentY = currentY + 1
- end
- turtle.turnRight()
- end
- -- Retourner à l'orientation initiale
- turtle.turnRight()
- turtle.turnRight()
- else
- -- Si on reculait déjà, c'est plus simple
- for w = 1, width - 1 do
- turtle.turnRight()
- turtle.forward()
- -- Mise à jour des coordonnées
- if turtle.getDirection() == 0 then -- Face au sud
- currentX = currentX + 1
- elseif turtle.getDirection() == 1 then -- Face à l'ouest
- currentY = currentY - 1
- elseif turtle.getDirection() == 2 then -- Face au nord
- currentX = currentX - 1
- elseif turtle.getDirection() == 3 then -- Face à l'est
- currentY = currentY + 1
- end
- turtle.turnLeft()
- end
- end
- end
- -- Fonction pour naviguer vers un point spécifique
- function navigateTo(targetX, targetY, targetZ)
- -- Ajuster l'altitude d'abord
- while currentZ < targetZ do
- if turtle.up() then
- currentZ = currentZ + 1
- else
- turtle.digUp()
- end
- end
- while currentZ > targetZ do
- if turtle.down() then
- currentZ = currentZ - 1
- else
- turtle.digDown()
- end
- end
- -- Orienter la tortue vers le sud (x+) comme référence
- -- Supposons que la tortue commence face au sud (x+)
- -- Ajuster la position X
- while currentX < targetX do
- turtle.dig()
- if turtle.forward() then
- currentX = currentX + 1
- end
- end
- while currentX > targetX do
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- if turtle.forward() then
- currentX = currentX - 1
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- -- Ajuster la position Y
- if currentY < targetY then
- turtle.turnLeft()
- while currentY < targetY do
- turtle.dig()
- if turtle.forward() then
- currentY = currentY + 1
- end
- end
- turtle.turnRight()
- else
- turtle.turnRight()
- while currentY > targetY do
- turtle.dig()
- if turtle.forward() then
- currentY = currentY - 1
- end
- end
- turtle.turnLeft()
- end
- end
- -- Fonction pour retourner à la surface
- function returnToSurface()
- print("Retour à la surface...")
- -- Se diriger vers la position au-dessus du point de départ
- navigateTo(homeX, homeY, homeZ)
- end
- -- Fonction pour aller au site de creusage
- function goToDiggingSite()
- print("Déplacement vers le site de creusage...")
- -- Se déplacer vers la position de départ du puits [1,0,0]
- navigateTo(1, 0, 0)
- -- Descendre d'un bloc pour commencer le puits à [1,0,-1]
- if turtle.down() then
- currentZ = currentZ - 1
- else
- turtle.digDown()
- turtle.down()
- currentZ = currentZ - 1
- end
- }
- -- Fonction pour retourner au site de creusage après ravitaillement
- function returnToDiggingSite()
- print("Retour au site de creusage...")
- -- Retourner au coin du puits
- navigateTo(1, 0, 0)
- -- Descendre jusqu'à la profondeur de creusage actuelle
- for i = 1, digDepth do
- if turtle.down() then
- currentZ = currentZ - 1
- else
- turtle.digDown()
- turtle.down()
- currentZ = currentZ - 1
- end
- end
- }
- -- Programme principal
- print("Début du creusage du puits " .. width .. "x" .. length)
- -- Vérifier le carburant initial
- if turtle.getFuelLevel() < 100 then
- print("Carburant insuffisant. Ravitaillement initial...")
- refuel()
- end
- -- Se déplacer vers le site de creusage initial
- goToDiggingSite()
- -- Creuser jusqu'au bedrock
- while not bedrockFound do
- -- Vérifier si l'inventaire est presque plein
- local emptySlots = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- emptySlots = emptySlots + 1
- end
- end
- if emptySlots < 3 then
- returnToSurface()
- dumpInventory()
- returnToDiggingSite()
- end
- -- Vérifier le carburant
- checkFuel()
- -- Creuser vers le bas
- if not turtle.detectDown() or turtle.digDown() then
- local success = turtle.down()
- if success then
- currentZ = currentZ - 1
- digDepth = digDepth + 1
- print("Profondeur actuelle: " .. digDepth)
- digLayer()
- else
- -- Vérifier si c'est du bedrock
- success, block = turtle.inspectDown()
- if success and block.name == "minecraft:bedrock" then
- bedrockFound = true
- print("Bedrock détecté à la profondeur " .. digDepth)
- end
- end
- else
- -- Vérifier si c'est du bedrock
- success, block = turtle.inspectDown()
- if success and block.name == "minecraft:bedrock" then
- bedrockFound = true
- print("Bedrock détecté à la profondeur " .. digDepth)
- end
- end
- end
- -- Retour à la surface et vidage final
- returnToSurface()
- dumpInventory()
- print("Creusage terminé! Puits " .. width .. "x" .. length .. " creusé jusqu'au bedrock à la profondeur " .. digDepth)
Add Comment
Please, Sign In to add comment