Advertisement
Thilus

Basic Mining Program - Lua

Jul 24th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. local height = 4
  2. local depth = 64
  3. local torchSpace = 8
  4.  
  5.  
  6. -- Fonction de mouvement
  7. function UP()
  8.     while (turtle.detect()) do
  9.         turtle.dig()
  10.         os.sleep(0.5)
  11.     end
  12.     while (turtle.detectUp()) do
  13.         turtle.digUp()
  14.         os.sleep(0.5)
  15.     end
  16.     turtle.up()
  17. end
  18.  
  19. function TURN()
  20.     while (turtle.detect()) do
  21.         turtle.dig()
  22.         os.sleep(0.5)
  23.     end
  24.     turtle.turnRight()
  25.     turtle.turnRight()
  26.     while (turtle.detect()) do
  27.         turtle.dig()
  28.         os.sleep(0.5)
  29.     end
  30. end
  31.  
  32. function DOWN()
  33.     turtle.down()
  34.     while (turtle.detect()) do
  35.         turtle.dig()
  36.         os.sleep(0.5)
  37.     end
  38. end
  39.  
  40. function FORWARD()
  41.     while (turtle.detect()) do
  42.         turtle.dig()
  43.         os.sleep(0.5)
  44.     end
  45.     while (not turtle.forward()) do
  46.         turtle.dig()
  47.         os.sleep(0.5)
  48.     end
  49. end
  50.  
  51.  
  52. -- Rechargement
  53. function REFUEL()
  54.     turtle.select(1)
  55.     if (turtle.refuel(1)) then
  56.         return true
  57.     else
  58.         for i=2, 16 do
  59.             turtle.select(i)
  60.             if (turtle.refuel(1)) then
  61.                 return true
  62.             end
  63.         end
  64.     end
  65.     return false
  66. end
  67.  
  68. function TORCH()
  69.     for i=0, 1 do turtle.turnLeft() end
  70.     turtle.select(2)
  71.     turtle.place()
  72.     for i=0, 1 do turtle.turnRight() end
  73. end
  74.  
  75.  
  76. -- Séquence principale
  77. function STEP(advencement)
  78.     turtle.turnLeft()
  79.  
  80.     -- Montée
  81.     for i=1, height-1 do
  82.         UP()
  83.     end
  84.  
  85.     -- Retournement
  86.     TURN()
  87.  
  88.     -- Descente
  89.     for i=1, height-1 do
  90.         DOWN()
  91.     end
  92.  
  93.     turtle.turnLeft()
  94.  
  95.     -- Avancement
  96.     if (advencement > 1) then
  97.         FORWARD()
  98.     end
  99.  
  100.     -- Torches
  101.     if (advencement % torchSpace == 0) then
  102.         TORCH()
  103.     end
  104. end
  105.  
  106.  
  107. -- Boucle principale
  108. for i=depth, 1, -1 do
  109.     if (turtle.getFuelLevel() < (height*height)-1) then
  110.         if REFUEL() then
  111.             STEP(i)
  112.         else
  113.             os.sleep(20)
  114.             i = i + 1
  115.             print("Waiting for fuel")
  116.         end
  117.     else
  118.         STEP(i)
  119.     end
  120. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement