SNiPeRzCiinema

Turtle

Aug 23rd, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.49 KB | None | 0 0
  1. local tunnelLength = 50
  2. local length = 50
  3.  
  4. local currentTunnelLength = 0
  5. local currentLength = 0
  6.  
  7. function refuel()
  8.     for i=1,15,1 do
  9.         turtle.select(i)
  10.         if(turtle.getFuelLevel() < (length*3)+tunnelLength) then
  11.             while (turtle.refuel(1) and turtle.getFuelLevel() < (length*3)+tunnelLength) do
  12.             end
  13.         end
  14.     end
  15. end
  16. function foundEmptySlots()
  17.     foundEmpty = 0
  18.     for i=1,15,1 do
  19.         if(turtle.getItemCount(i) == 0) then
  20.             foundEmpty = foundEmpty + 1
  21.         end
  22.     end
  23.     if(turtle.getItemCount(16) == 0) then
  24.         foundEmpty = -1
  25.     end
  26.     return foundEmpty
  27. end
  28.  
  29. function mine()
  30.     while(currentTunnelLength < tunnelLength) do
  31.         refuel()
  32.         if(currentTunnelLength%3==0) then
  33.             turtle.turnLeft()
  34.             while(currentLength < length) do
  35.                 turtle.dig()
  36.                 moveForward()
  37.                 turtle.digUp()
  38.                 currentLength = currentLength+1
  39.             end
  40.             turtle.turnLeft()
  41.             turtle.turnLeft()
  42.             while(currentLength > 0) do
  43.                 moveForward()
  44.                 if(currentLength%8==0) then
  45.                     turtle.select(16)
  46.                     turtle.placeUp()
  47.                     turtle.select(1)
  48.                 end
  49.                 currentLength = currentLength-1
  50.             end
  51.             while(currentLength < length) do
  52.                 turtle.dig()
  53.                 moveForward()
  54.                 turtle.digUp()
  55.                 currentLength = currentLength+1
  56.             end
  57.             turtle.turnLeft()
  58.             turtle.turnLeft()
  59.             while(currentLength > 0) do
  60.                 moveForward()
  61.                 if(currentLength%8==0) then
  62.                     turtle.select(16)
  63.                     turtle.placeUp()
  64.                     turtle.select(1)
  65.                 end
  66.                 currentLength = currentLength-1
  67.             end
  68.             turtle.turnRight()
  69.             empties = foundEmptySlots()
  70.             if(empties < 3 or empties == -1) then
  71.                 turtle.turnLeft()
  72.                 turtle.turnLeft()
  73.                 for i=1,currentTunnelLength,1 do
  74.                     moveForward()
  75.                 end
  76.                 for i=1,15,1 do
  77.                     turtle.select(i)
  78.                     turtle.drop()
  79.                 end
  80.                 while(foundEmptySlots() == -1) do
  81.                     print("Waiting for Torches: ")
  82.                 end
  83.                 turtle.turnLeft()
  84.                 turtle.turnLeft()
  85.                 for i=1,currentTunnelLength,1 do
  86.                     moveForward()
  87.                 end
  88.             end
  89.         end
  90.        
  91.         turtle.dig()
  92.         moveForward()
  93.         turtle.digUp()
  94.         currentTunnelLength = currentTunnelLength + 1
  95.  
  96.     end
  97.     turtle.turnLeft()
  98.     turtle.turnLeft()
  99.     while(currentTunnelLength > 0) do
  100.         moveForward()
  101.         currentTunnelLength = currentTunnelLength - 1
  102.     end
  103. end
  104.  
  105. function moveForward()
  106.     while not turtle.forward() do turtle.attack() end
  107. end
  108. function moveDown()
  109.     while not turtle.down() do turtle.attackDown() end
  110. end
  111.  
  112. print("TunnelLength:")
  113. tunnelLength = tonumber(read())
  114. print("Length:")
  115. length = tonumber(read())
  116. mine()
Advertisement
Add Comment
Please, Sign In to add comment