Advertisement
Vodka51200

Farm_ForceSpling 1.12.2

Jul 7th, 2024 (edited)
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.24 KB | Gaming | 0 0
  1. -- Programme de minage d'arbres avec une turtle de ComputerCraft
  2.  
  3. local firstslot = 1
  4. local lastslot = 14
  5. local coalslot = 16
  6. local emptyslot = "right"
  7. local saplingslot = 15
  8. local fuel = turtle.getFuelLevel()
  9. -- Fonction pour vérifier et recharger le carburant
  10. function checkFuel()
  11.     while turtle.getFuelLevel() < 20 do
  12.         term.setTextColor(colors.red)
  13.         print("Carburant faible, en attente de charbon...")
  14.         term.setTextColor(colors.white)
  15.         local item = turtle.getItemDetail(coalslot)
  16.         if item and item.name == "minecraft:coal" then
  17.             turtle.select(coalslot)
  18.             turtle.refuel(1)
  19.             checkFuelLevel()
  20.             turtle.select(firstslot)
  21.             break
  22.         end
  23.         sleep(60)  -- Attend 60 secondes avant de vérifier à nouveau
  24.     end
  25. end
  26.  
  27. function checkFuelLevel()
  28.     term.setTextColor(colors.orange)
  29.     print("Fuel: " ..turtle.getFuelLevel())
  30.     term.setTextColor(colors.white)
  31. end
  32.  
  33. -- Fonction pour vider l'inventaire dans un coffre autour de la turtle
  34. function emptyInventory()
  35.     if turtle.getItemCount(lastslot) > 0 then
  36.         for slot = firstslot, lastslot do
  37.             if turtle.getItemCount(slot) > 0 then
  38.                 turtle.select(slot)
  39.                 if emptyslot == "down" then
  40.                     turtle.dropDown()
  41.                 elseif emptyslot == "up" then
  42.                     turtle.dropUp()
  43.                 elseif emptyslot == "right" then
  44.                     turtle.turnRight()
  45.                     turtle.drop()
  46.                     turtle.turnLeft()
  47.                 elseif emptyslot == "left" then
  48.                     turtle.turnLeft()
  49.                     turtle.drop()
  50.                     turtle.turnRight()
  51.                 elseif emptyslot == "back" then
  52.                     turtle.turnRight()
  53.                     turtle.turnRight()
  54.                     turtle.drop()
  55.                     turtle.turnLeft()
  56.                     turtle.turnLeft()
  57.                 else
  58.                     print("haha")
  59.                 end
  60.             end
  61.         end
  62.     end
  63. end
  64.  
  65. -- Fonction pour vérifier et recharger les saplings
  66. function checkSaplings()
  67.     if turtle.getItemCount(saplingslot) == 0 then
  68.         term.setTextColor(colors.yellow)
  69.         print("Pas de jeunes arbres, vérification du coffre...")
  70.         term.setTextColor(colors.white)
  71.         if emptyslot == "down" then
  72.             turtle.suckDown()
  73.         elseif emptyslot == "up" then
  74.             turtle.suckUp()
  75.         elseif emptyslot == "right" then
  76.             turtle.turnRight()
  77.             turtle.select(saplingslot)
  78.             turtle.suck(10)
  79.             turtle.turnLeft()
  80.         elseif emptyslot == "left" then
  81.             turtle.turnLeft()
  82.             turtle.select(saplingslot)
  83.             turtle.suck(10)
  84.             turtle.turnRight()
  85.         elseif emptyslot == "back" then
  86.             turtle.turnRight()
  87.             turtle.turnRight()
  88.             turtle.suck(10)
  89.             turtle.turnLeft()
  90.             turtle.turnLeft()
  91.         else
  92.             print("haha")
  93.         end
  94.     end
  95. end
  96.  
  97. -- Fonction principale pour couper un arbre
  98. function chopTree()
  99.     local success, data = turtle.inspect()
  100.     if success then
  101.         -- Si c'est un jeune arbre, attendre qu'il pousse
  102.         if data.name == "minecraft:sapling" or data.name == "dartcraftreloaded:force_sapling" then
  103.             term.setTextColor(colors.blue)
  104.             print("Jeune arbre détecté, en attente de croissance...")
  105.             term.setTextColor(colors.white)
  106.             while true do
  107.                 success, data = turtle.inspect()
  108.                 if success and (data.name == "minecraft:log" or data.name == "dartcraftreloaded:forcelog") then
  109.                     break
  110.                 end
  111.                 sleep(10)  -- Attend 10 secondes avant de vérifier à nouveau
  112.             end
  113.         else
  114.             print("Nom de bloc non reconnu: " .. data.name)
  115.             print("Ajout de ce bloc à la liste des blocs connus.")
  116.             return  
  117.         end
  118.         -- Mine l'arbre jusqu'au sommet
  119.         while success and (data.name == "minecraft:log" or data.name == "dartcraftreloaded:forcelog") do
  120.             turtle.dig()
  121.             turtle.digUp()
  122.             turtle.up()
  123.             checkFuelLevel()
  124.             success, data = turtle.inspect()
  125.         end
  126.     end
  127.     term.setTextColor(colors.green)
  128.     print("Arbre coupé, retour à la base.")
  129.     term.setTextColor(colors.white)
  130.  
  131.     -- Retourne à la base
  132.     while not turtle.detectDown() do
  133.         turtle.down()
  134.         checkFuelLevel()
  135.     end
  136.  
  137.     -- Place un sapling
  138.     turtle.select(saplingslot)
  139.     if turtle.getItemCount(saplingslot) == 0 then
  140.         checkSaplings()
  141.     end
  142.     if turtle.getItemCount(saplingslot) > 0 then
  143.         turtle.place()
  144.     else
  145.         term.setTextColor(colors.red)
  146.         print("Pas de jeunes arbres disponibles!")
  147.         term.setTextColor(colors.white)
  148.     end
  149.     turtle.select(firstslot)
  150. end
  151.  
  152. -- Boucle principale
  153. while true do
  154.     checkFuel()
  155.    
  156.     -- Vérifie l'inventaire et vide si nécessaire
  157.     if turtle.getItemCount(lastslot) > 0 then
  158.         print("Inventaire plein, vidange...")
  159.         emptyInventory()
  160.     end
  161.     turtle.select(firstslot)
  162.     -- Lance la coupe d'arbre
  163.     chopTree()
  164. end
  165.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement