Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Programme de minage d'arbres avec une turtle de ComputerCraft
- local firstslot = 1
- local lastslot = 14
- local coalslot = 16
- local emptyslot = "right"
- local saplingslot = 15
- local fuel = turtle.getFuelLevel()
- -- Fonction pour vérifier et recharger le carburant
- function checkFuel()
- while turtle.getFuelLevel() < 20 do
- term.setTextColor(colors.red)
- print("Carburant faible, en attente de charbon...")
- term.setTextColor(colors.white)
- local item = turtle.getItemDetail(coalslot)
- if item and item.name == "minecraft:coal" then
- turtle.select(coalslot)
- turtle.refuel(1)
- checkFuelLevel()
- turtle.select(firstslot)
- break
- end
- sleep(60) -- Attend 60 secondes avant de vérifier à nouveau
- end
- end
- function checkFuelLevel()
- term.setTextColor(colors.orange)
- print("Fuel: " ..turtle.getFuelLevel())
- term.setTextColor(colors.white)
- end
- -- Fonction pour vider l'inventaire dans un coffre autour de la turtle
- function emptyInventory()
- if turtle.getItemCount(lastslot) > 0 then
- for slot = firstslot, lastslot do
- if turtle.getItemCount(slot) > 0 then
- turtle.select(slot)
- if emptyslot == "down" then
- turtle.dropDown()
- elseif emptyslot == "up" then
- turtle.dropUp()
- elseif emptyslot == "right" then
- turtle.turnRight()
- turtle.drop()
- turtle.turnLeft()
- elseif emptyslot == "left" then
- turtle.turnLeft()
- turtle.drop()
- turtle.turnRight()
- elseif emptyslot == "back" then
- turtle.turnRight()
- turtle.turnRight()
- turtle.drop()
- turtle.turnLeft()
- turtle.turnLeft()
- else
- print("haha")
- end
- end
- end
- end
- end
- -- Fonction pour vérifier et recharger les saplings
- function checkSaplings()
- if turtle.getItemCount(saplingslot) == 0 then
- term.setTextColor(colors.yellow)
- print("Pas de jeunes arbres, vérification du coffre...")
- term.setTextColor(colors.white)
- if emptyslot == "down" then
- turtle.suckDown()
- elseif emptyslot == "up" then
- turtle.suckUp()
- elseif emptyslot == "right" then
- turtle.turnRight()
- turtle.select(saplingslot)
- turtle.suck(10)
- turtle.turnLeft()
- elseif emptyslot == "left" then
- turtle.turnLeft()
- turtle.select(saplingslot)
- turtle.suck(10)
- turtle.turnRight()
- elseif emptyslot == "back" then
- turtle.turnRight()
- turtle.turnRight()
- turtle.suck(10)
- turtle.turnLeft()
- turtle.turnLeft()
- else
- print("haha")
- end
- end
- end
- -- Fonction principale pour couper un arbre
- function chopTree()
- local success, data = turtle.inspect()
- if success then
- -- Si c'est un jeune arbre, attendre qu'il pousse
- if data.name == "minecraft:sapling" or data.name == "dartcraftreloaded:force_sapling" then
- term.setTextColor(colors.blue)
- print("Jeune arbre détecté, en attente de croissance...")
- term.setTextColor(colors.white)
- while true do
- success, data = turtle.inspect()
- if success and (data.name == "minecraft:log" or data.name == "dartcraftreloaded:forcelog") then
- break
- end
- sleep(10) -- Attend 10 secondes avant de vérifier à nouveau
- end
- else
- print("Nom de bloc non reconnu: " .. data.name)
- print("Ajout de ce bloc à la liste des blocs connus.")
- return
- end
- -- Mine l'arbre jusqu'au sommet
- while success and (data.name == "minecraft:log" or data.name == "dartcraftreloaded:forcelog") do
- turtle.dig()
- turtle.digUp()
- turtle.up()
- checkFuelLevel()
- success, data = turtle.inspect()
- end
- end
- term.setTextColor(colors.green)
- print("Arbre coupé, retour à la base.")
- term.setTextColor(colors.white)
- -- Retourne à la base
- while not turtle.detectDown() do
- turtle.down()
- checkFuelLevel()
- end
- -- Place un sapling
- turtle.select(saplingslot)
- if turtle.getItemCount(saplingslot) == 0 then
- checkSaplings()
- end
- if turtle.getItemCount(saplingslot) > 0 then
- turtle.place()
- else
- term.setTextColor(colors.red)
- print("Pas de jeunes arbres disponibles!")
- term.setTextColor(colors.white)
- end
- turtle.select(firstslot)
- end
- -- Boucle principale
- while true do
- checkFuel()
- -- Vérifie l'inventaire et vide si nécessaire
- if turtle.getItemCount(lastslot) > 0 then
- print("Inventaire plein, vidange...")
- emptyInventory()
- end
- turtle.select(firstslot)
- -- Lance la coupe d'arbre
- chopTree()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement