Advertisement
naej

turtle minage opti

Sep 8th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.01 KB | None | 0 0
  1. shell.run("clear")
  2.  
  3. -- Initialisation
  4. print("+----------------------+")
  5. print("|    Minage optimise   |")
  6. print("+----------------------+")
  7. print("")
  8. print("")
  9.  
  10. -- Declaration des variables
  11. nbJunkSlot = 0
  12.  
  13. -- Fonction choix utilisateur
  14. function getParam()
  15.   print("Altitude (Y) actuel de la turtle ?")
  16.   initialY = read()
  17.   print("Profondeur a miner ?")
  18.   askHeight = read()
  19.   maxHeight = initialY - 5
  20.   if tonumber(askHeight) > maxHeight then
  21.     print("Hauteur bridee a " .. maxHeight .. " pour ne pas attaquer la bedrock")
  22.         height = maxHeight
  23.   else
  24.     height = askHeight
  25.   end
  26.   print("Longueur a miner ?")
  27.   askLength = read()
  28.   print("Largeur a miner ?")
  29.   askWidth = read()
  30.   estimateMove = (height / 3) * ((askLength * askWidth) + height)
  31.   print("Nombre de mouvements : " .. math.floor(estimateMove))  
  32. end
  33.  
  34. -- Fonction estimation fuel
  35. function estimConsum()
  36.   wooden_tool = math.floor(estimateMove / 10)
  37.   lava = math.floor(estimateMove / 1000)
  38.   blaze_rod = math.floor(estimateMove / 120)
  39.   wood_block = math.floor(estimateMove / 15)
  40.   stick = math.floor(estimateMove / 5)
  41.   coal = math.floor(estimateMove / 80)
  42.   mushroom_block = math.floor(estimateMove / 15)
  43.   print("               +---------------+")
  44.   print("Voici un       |  Conbustible  | Blocs")
  45.   print("tableau        +---------------+")
  46.   print("indicatif      | Outil en bois | " .. wooden_tool)
  47.   print("des quantitees | Lave          | " .. lava)
  48.   print("necessaires    | Blaze         | " .. blaze_rod)
  49.   print("pour miner     | Bloc de bois  | " .. wood_block)
  50.   print("sans tomber en | Stick         | " .. stick)
  51.   print("panne de       | Charbon       | " .. coal)
  52.   print("combustible.   | Bloc de champ | " .. mushroom_block)
  53.   print("               +---------------+")
  54. end
  55.  
  56. -- Controle fichier param
  57. function init()
  58.   if fs.exist(mining.ini) == false then
  59.     createParam()
  60.   else
  61.     r = fs.open("mining.ini","r")
  62.         nbJunkslot = tonumber(r.readline(1))
  63.         length = tonumber(r.readline(2))
  64.         width = tonumber(r.readline(3))
  65.         height = tonumber(r.readline(4))
  66.         curX = tonumber(r.readline(5))
  67.         curZ = tonumber(r.readline(6))
  68.         curY = tonumber(r.readline(7))
  69.         r.close()
  70.         print("Reprendre le precedent minage :")
  71.         print("nombre slot poubelle : " .. nbJunkslot)
  72.         print("Longueur largeur hauteur : " .. lenght .. " " .. width .. " " .. height)
  73.         print("Derniere position : " .. curX .. " " .. curZ .. " " .. curY)
  74.         print("tapez y ou n")
  75.         aws = read()
  76.         if aws == n then
  77.           deleteParam()
  78.                   createParam()
  79.         elseif aws == y then
  80.           -- appel fonction reprise minage
  81.         else
  82.           -- appel focntion abandon
  83.         end
  84.   end
  85. end
  86.  
  87. -- Fonction creation fichiers param
  88. function createParam()
  89.   f = fs.open("mining.ini","w")
  90.   f.write(nbJunkSlot .. "\n" .. lenght .. "\n" .. width .. "\n" .. height .. "\n")
  91.   f.close()
  92.   c = fs.open("coords.nav","w")
  93.   c.write("0\n0\n0\n")
  94.   c.close()
  95. end
  96.  
  97. -- Fonction suppression fichiers param
  98. function deleteParam()
  99.   fs.delete("mining.ini")
  100.   fs.delete("coords.nav")
  101. end
  102.  
  103. -- Fonction abandon
  104. -- function abordMining()
  105. --   print("Abandon de la session.")
  106. --   return
  107. -- end
  108.  
  109. -- Fonction deplacement avant
  110. function moveForward()
  111.   if turtle.forward() == false then
  112.     if turtle.dig() == false then
  113.       print("Je suis coincé")
  114.     elseif turtle.getFuelLevel == 0 then
  115.       print("J'ai plus de carburant")
  116.     else
  117.       turtle.forward()
  118.     end
  119.   else
  120.   end
  121. end
  122.  
  123. -- Fonction plein d'energie
  124. function refuel()
  125.   turtle.select(16)
  126.   if turtle.getFuelLevel() == 0 then
  127.     print("Placer du carburant dans le slot actif.")
  128.     while (turtle.getItemCount(16) < 1) do
  129.       sleep(0.5)
  130.     end
  131.     turtle.refuel()
  132.     print("Niveau de carburant : " .. turtle.getFuelLevel())
  133.   elseif turtle.getFuelLevel() > 0 then
  134.     print("Niveau de carburant actuel : " .. turtle.getFuelLevel())
  135.     print("Placer du carburant dans le slot actif")
  136.     print("si vous souhaitez refaire le plein")
  137.     print("et appuyez sur entree pour continuer.")
  138.     ok = read()
  139.     if turtle.getItemCount(16) > 0 then
  140.       turtle.refuel()
  141.       print("Nouveau niveau de carburant : " .. turtle.getFuelLevel())
  142.     end
  143.   end
  144. end
  145.  
  146. -- Contrôle nombre de slot poubelle
  147. function countJunkSlot()
  148.   i = 0
  149.   while (i < 16) do
  150.     i = i + 1
  151.     if turtle.getItemCount(i) == 1 then
  152.       nbJunkSlot = nbJunkSlot + 1
  153.     end
  154.   end
  155. end
  156.  
  157. -- Dechargement dans le coffre
  158. function dumpInventory()
  159.   i = nbJunkSlot
  160.   while (i < 16) do
  161.     i = i + 1
  162.     turtle.select(i)
  163.     turtle.drop()
  164.   end
  165. end
  166.  
  167. -- Comparer les blocs a miner au dessus
  168. function compBlocUp()
  169.   i = nbJunkSlot
  170.   while (i < 4) do
  171.     i = i + 1
  172.     turtle.select(i)
  173.     if turtle.compareUp() == false then
  174.       compFalse = compFalse + 1
  175.     elseif turtle.compareUp() == true then
  176.       break
  177.     end
  178.   end
  179.   if compFalse == 4 then
  180.     turtle.digUp()
  181.   else
  182.     break
  183.   end
  184.  
  185. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement