Advertisement
naej

turtle minage dense ore

Sep 14th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.96 KB | None | 0 0
  1. shell.run("clear")
  2. -- Controle des parametres
  3. local tArgs = { ... }
  4.  
  5. if #tArgs == 0 then
  6.   print("Hey biatch !! je vais ou ?")
  7.   print("Syntaxe: Commande <longueur> <nb_de_tunnels>")
  8.   return
  9. end
  10.  
  11. -- Declaration des variables
  12. local length = tonumber(tArgs[1])
  13. local width = tonumber(tArgs[2])
  14. local slotNum = 0
  15. local loop = 0
  16. local retry = 0
  17.  
  18. -- Plein d'energie
  19. if turtle.getFuelLevel() == 0 then
  20.   turtle.select(16)
  21.   print("Ajoutez du Carburant dans le dernier slot.")
  22.   print("Entree pour continuer")
  23.   ok  = read()
  24.   turtle.refuel()
  25.   if turtle.getFuelLevel() == 0 then
  26.     print("Boulay !! donne moi quelque chose a cramer pour avancer !!")
  27.     return
  28.   elseif turtle.getFuelLevel() == "unlimited" then
  29.     print("Pwoua trop cheater meme pas besoin de cramer quelque chose pour foncer !!")
  30.     return
  31.   end
  32. elseif turtle.getFuelLevel() > 0 then
  33.   print("Niveau de carburant : " .. turtle.getFuelLevel())
  34.   turtle.select(16)
  35.   print("Ajoutez du Carburant dans le dernier slot pour completer le plein.")
  36.   print("Entree pour continuer")
  37.   ok  = read()
  38.   turtle.refuel()
  39. end
  40. -- Blocs a ne pas miner
  41. print("Ajoutez des blocs a ne pas miner.")
  42. print("Entree pour continuer")
  43. ok = read()
  44.  
  45. -- Fonction gestion des bocages
  46. function moveForward()
  47.   if turtle.forward() == false then
  48.     while turtle.dig() do
  49.         end
  50.         if turtle.forward() == false then
  51.           print("Deplacement impossible")
  52.           return false
  53.         end
  54.   return true
  55.   end
  56. end
  57.  
  58. -- ContrΓ΄le nombre de slot poubelle
  59. function countJunkSlot()
  60.   junkSlots = 0
  61.   i = 0
  62.   while (i < 16) do
  63.     i = i + 1
  64.     if turtle.getItemCount(i) == 1 then
  65.       junkSlots = junkSlots + 1
  66.     end
  67.   end
  68. end
  69.  
  70. -- Fonction comparaison
  71. function compare()
  72.   isJunkDown = false
  73.   isJunkUp = false
  74.   for i = 1, junkSlots do
  75.     turtle.select(i)
  76.     if turtle.compareUp()==true then
  77.       isJunkUp = true
  78.     end
  79.     if turtle.compareDown()==true then
  80.       isJunkDown = true
  81.     end
  82.   end
  83. end
  84.  
  85. -- Fonction de minage
  86. function digger(n)
  87.   print("Debut de la phase de minage.")
  88.   purge = 0
  89.   while (n > 0) do
  90.     turtle.dig()
  91.     moveForward()
  92.     compare()
  93.     if isJunkUp == false then
  94.       turtle.digUp()
  95.     end
  96.     if isJunkDown == false then
  97.       turtle.digDown()
  98.     end
  99.     if purge == 10 then
  100.       invPurge()
  101.       purge = 0
  102.     end
  103.     purge = purge + 1
  104.     n = n - 1
  105.   end
  106.   print("")
  107. end
  108.  
  109. -- Fonction de retour sur la longueur
  110. function backL(n)
  111.   print("Retour au coffre.")
  112.   turtle.turnLeft()
  113.   turtle.turnLeft()
  114.   while (n > 0) do
  115.     moveForward()
  116.         n = n - 1
  117.   end
  118. end
  119.  
  120. -- Fonction de retour sur la largeur
  121. function backW(n)
  122.   turtle.turnRight()
  123.   while (n > 0)do
  124.     moveForward()
  125.         n = n - 1
  126.   end
  127.   turtle.turnLeft()
  128. end
  129.  
  130. -- Fonction purge inventaire
  131. function invPurge()
  132.   j = junkSlots
  133.   while (j < 16) do
  134.     j = j + 1
  135.     for k = 1, junkSlots do
  136.       turtle.select(j)
  137.       if turtle.compareTo(k) == true then
  138.         turtle.dropDown()
  139.       end
  140.     end
  141.   end
  142. end
  143.  
  144. -- Fonction vidage dans le coffre
  145. function drop()
  146.   invPurge()
  147.   i = junkSlots
  148.   while (i < 16) do
  149.     i = i + 1
  150.     turtle.select(i)
  151.     turtle.drop()
  152.   end
  153. end
  154.  
  155. -- Fonction placement pour la ligne suivante
  156. function nextLine(n)
  157.   turtle.turnLeft()
  158.   while (n > 0) do
  159.     turtle.dig()
  160.         moveForward()
  161.         turtle.digUp()
  162.         n = n - 1
  163.   end
  164.   turtle.turnLeft()
  165. end
  166.  
  167. -- Programme principal
  168.  
  169. print("+--------------------------+")
  170. print("|     Debut du minage      |")
  171. print("+--------------------------+")
  172. print("")
  173. print("longueur des tunnels : " .. length)
  174. print("nombre de tunnels : " .. width)
  175. print("")
  176.  
  177. countJunkSlot()
  178. digger(length)
  179. backL(length)
  180. drop()
  181.  
  182. width = width - 1
  183.  
  184. while (loop < width) do
  185.   loop = loop + 1
  186.   nextLine(loop)
  187.   digger(length)
  188.   backL(length)
  189.   backW(loop)
  190.   drop()
  191. end
  192.  
  193. print("+--------------------------+")
  194. print("|      Fin du minage       |")
  195. print("+--------------------------+")
  196. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement