Bimgo

Fiixii52_debug

Jul 1st, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.89 KB | None | 0 0
  1.    
  2.  
  3.     local BedrockDetection = false
  4.     local Charcoalslot = 1
  5.     local Charcoalmini = 5
  6.     local Fuellvlmini = 5
  7.     local Endercharcoalslot = 15
  8.     local Enderchestslot = 16
  9.     local premierminerai = 2
  10.     local dernierminerai = 14
  11.     local x = 1
  12.     local y = 1
  13.     local z = 1
  14.     impair = true
  15.     tourner = true
  16.      
  17.     -- Fonctions : Début
  18.      
  19.     -- Fonction Charcoalfuel : Detecte s'il faut se réapprovisionner en charcoal
  20.      
  21.     function Charcoalrefuel()
  22.                    
  23.             local Fuellvl = turtle.getFuelLevel()
  24.             if Fuellvl < Fuellvlmini then
  25.                 turtle.select(Charcoalslot)
  26.                 if turtle.getItemCount(Charcoalslot) < Charcoalmini then
  27.                       Charcoalreload()
  28.                 end
  29.                 turtle.reFuel(1)
  30.             else
  31.                   return true
  32.             end
  33.     end
  34.      
  35.     function Charcoalreload() -- Fonction de rechargement en charcoal
  36.      
  37.                 if turtle.detectUp() then
  38.                     turtle.digUp()
  39.                     os.sleep(0.5)
  40.                     end
  41.              
  42.                 if turtle.getItemCount(dernierminerai) > 62 then
  43.                         VidageInventaire()      
  44.      
  45.                 end
  46.                 turtle.select(Endercharcoalslot)
  47.                 turtle.placeUp()
  48.                 turtle.select(Charcoalslot)
  49.                 turtle.suckUp()
  50.      
  51.                 turtle.select(Endercharcoalslot)
  52.                 turtle.digUp()
  53.      
  54.     end
  55.      
  56.     function VidageInventaire() -- Fonction de vidage des minerais creusés dans l'enderchest dédié à ça
  57.      
  58.           local slot
  59.           if turtle.detectUp() then
  60.               turtle.digUp()
  61.               os.sleep(0.5)
  62.           end
  63.           turtle.select(Enderchestslot)
  64.           turtle.placeUp()
  65.           for slot=premierminerai,dernierminerai do
  66.                    turtle.select(slot)
  67.                    while turtle.getItemCount(slot) > 0 do
  68.                            turtle.dropUp(turtle.getItemCount(slot))
  69.                            
  70.                    end
  71.           end
  72.      
  73.           turtle.select(Enderchestslot)
  74.           turtle.digUp()
  75.      
  76.     end
  77.      
  78.     function Remplissageslot()
  79.      
  80.           if turtle.getItemCount(dernierminerai) > 0 then
  81.               VidageInventaire()
  82.           else
  83.                    return true
  84.          
  85.           end
  86.     end
  87.      
  88.     function move(direction)
  89.      
  90.           while true do
  91.                   if direction == "forward" then
  92.                          if turtle.detect() then
  93.                                turtle.dig()
  94.                          else
  95.                                if turtle.forward() then
  96.                                       return true
  97.                                else
  98.                                     turtle.attack()
  99.                                end
  100.                          end
  101.      
  102.                   elseif direction == "up" then
  103.                            if turtle.detectUp() then
  104.                                turtle.digUp()
  105.                                os.sleep(0.5)
  106.                        
  107.                            else
  108.                                 if turtle.up() then
  109.                                      return true
  110.                                 else
  111.                                      turtle.attackUp()
  112.                                 end
  113.                            end
  114.                   end
  115.           end
  116.              
  117.           while true do
  118.                   if direction == "down" then
  119.                           if turtle.detectDown() then
  120.                                turtle.digDown()
  121.                                os.sleep(0.5)
  122.                           else
  123.                                if turtle.down() then
  124.                                      return true
  125.                                else
  126.                                      turtle.attackDown()
  127.                                end
  128.                           end
  129.                   end
  130.           end
  131.     end
  132.      
  133.     function RetourBedrock() -- Retour vers le point le point de départ si la turtle a atteint la bedrock
  134.        
  135.         for i=z-1,1,-1 do
  136.                 move("up")
  137.         end
  138.      
  139.         if impair then
  140.             turtle.turnLeft()
  141.         else
  142.             turtle.turnRight()
  143.         end
  144.      
  145.         for i=Quarrydim,1,-1 do
  146.                 move("forward")
  147.         end
  148.     end
  149.      
  150.     -- Fonctions : Fin
  151.      
  152.      
  153.     -- Programme : Début
  154.      
  155.     term.clear()
  156.     term.setCursorPos(1,1)
  157.     print("Programme de quarry avec mining turtle - Par Fiixii52")
  158.      
  159.     while true do
  160.     shell.run('clear') -- add bimgo
  161.              term.setCursorPos(1,3)
  162.              print("Mettez du coal / charcoal dans le premier slot de la turtle")
  163.              io.read()
  164.      
  165.              if turtle.getItemCount(Charcoalslot) > 0 then
  166.                    break
  167.              else
  168.                    term.setCursorPos(1,5)
  169.                    print("Coal / Charcoal non détecté. Veuillez recommencer")
  170.                    io.read()
  171.              end
  172.     end
  173.      
  174.     while true do
  175.     shell.run('clear') -- add bimgo
  176.             term.setCursorPos(1,3)
  177.              print("Mettez l'enderchest dédié au charcoal dans le slot 15 de la turtle")
  178.              io.read()
  179.      
  180.              if turtle.getItemCount(Endercharcoalslot) > 0 then
  181.                    break
  182.              else
  183.                    term.setCursorPos(1,5)
  184.                    print("Enderchest au charcoal non détecté. Veuillez recommencer")
  185.                    io.read()
  186.              end
  187.     end
  188.      
  189.     while true do
  190.         shell.run('clear') -- add bimgo
  191.              term.setCursorPos(1,3)
  192.              print("Mettez l'enderchest dédié aux minerais dans le dernier slot de la turtle")
  193.              io.read()
  194.      
  195.              if turtle.getItemCount(Enderchestslot) > 0 then
  196.                     break
  197.              else
  198.                     term.setCursorPos(1,5)
  199.                     print("Enderchest au minerais non détecté. Veuillez recommencer")
  200.                     io.read()
  201.              end
  202.     end
  203.      
  204.     while true do
  205.         shell.run('clear') -- add bimgo
  206.              term.setCursorPos(1,3)
  207.              print("Indiquez la longueur de la quarry : ")
  208.              Quarrydim = io.read()
  209.              Quarrydim = tonumber(Quarrydim)
  210.      
  211.              if Quarrydim == nil then
  212.                      print("Erreur de frappe. Veuillez recommencer")
  213.                      io.read()
  214.              else
  215.                      break
  216.              end                
  217.     end
  218.      
  219.     while true do
  220.         shell.run('clear') -- add bimgo
  221.              term.clear()
  222.              print("Charcoal du slot 1 détecté")
  223.              print("Enderchest dédié au coal / charcoal détecté")
  224.              print("Enderchest dédié aux minerais détecté")
  225.              print("Dimension de la quarry : "..Quarrydim.." x "..Quarrydim.."")
  226.              print("Confirmer le lancement de la turtle ?")
  227.              print("Appuyez sur O pour confirmer le lancement, N pour l'annuler")
  228.                      param1 = read()
  229.                      print("touche pressee "..param1)
  230.                      sleep(10)
  231.                      if param1 == "o" then
  232.                          break
  233.                  elseif param1 == "n" then
  234.                          os.reboot()
  235.                  end
  236.     end
  237.      
  238.     while true do -- Programme : Boucle principale
  239.        while turtle.digUp() do
  240.               os.sleep(0.5)
  241.        end
  242.        Remplissageslot()
  243.        
  244.        repeat -- Excavate fonction avec 3 repeat emboîtés (Merci lucasgood :D)
  245.           repeat
  246.                  repeat
  247.                         x = x + 1
  248.                             move("forward")
  249.                             Charcoalrefuel()
  250.                             Remplissageslot()
  251.                  until x == Quarrydim
  252.                  turtle.turnRight()
  253.                  move("forward")
  254.                  turtle.turnRight()
  255.                      x = 1
  256.                      
  257.                  repeat
  258.                         x = x + 1
  259.                             move("forward")
  260.                             Charcoalrefuel()
  261.                             Remplissageslot()
  262.                  until x == Quarrydim
  263.                  turtle.turnLeft()
  264.                  move("forward")
  265.                  turtle.turnLeft()
  266.                      x = 1
  267.           y = y + 2
  268.           until y == Quarrydim
  269.      
  270.            for i=1,2 do
  271.                 move("down")
  272.                 os.sleep(0.5)
  273.            end
  274.                
  275.                x = 1
  276.                y = 1
  277.          
  278.            if not move("down") then -- Si la turtle ne peut pas miner en bas, c'est la bedrock
  279.                BedrockDetection = true
  280.                RetourBedrock()
  281.            else
  282.                return true
  283.            end
  284.      
  285.            z = z + 1
  286.        until z == Quarrydim
  287.     end
Advertisement
Add Comment
Please, Sign In to add comment