Advertisement
Birog

Schienen

Mar 17th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. local tArgs = { ... }
  2. if #tArgs ~= 1 then
  3.     print( "Usage: tunnel <length>" )
  4.     return
  5. end
  6.  
  7. -- Mine in a quarry pattern until we hit something we can't dig
  8. local length = tonumber( tArgs[1] )
  9. if length < 1 then
  10.     print( "Tunnel length must be positive" )
  11.     return
  12. end
  13.    
  14. local depth = length
  15. local collected = 0
  16. local anzahl = 0
  17. local fach = 1
  18.  
  19. local function refuel()
  20.     local fuelLevel = turtle.getFuelLevel()
  21.     if fuelLevel == "unlimited" or fuelLevel > 0 then
  22.         return
  23.     end
  24.    
  25.     local function tryRefuel()
  26.         for n=1,16 do
  27.             if turtle.getItemCount(n) > 0 then
  28.                 turtle.select(n)
  29.                 if turtle.refuel(1) then
  30.                     turtle.select(1)
  31.                     return true
  32.                 end
  33.             end
  34.         end
  35.         turtle.select(1)
  36.         return false
  37.     end
  38.    
  39.     if not tryRefuel() then
  40.         print( "Add more fuel to continue." )
  41.         while not tryRefuel() do
  42.             sleep(1)
  43.         end
  44.         print( "Resuming Tunnel." )
  45.     end
  46. end
  47.  
  48. local function Nachlegen()
  49.  anzahl = turtle.getItemCount(fach)
  50.  if anzahl == 0 then
  51.   fach = fach+1
  52.   turtle.select(fach)
  53.  end
  54. end
  55.  
  56. local function collect()
  57.     collected = collected + 1
  58.     if math.fmod(collected, 25) == 0 then
  59.         print( "Mined "..collected.." items." )
  60.     end
  61. end
  62.  
  63. local function tryForward()
  64.     refuel()
  65.     while not turtle.forward() do
  66.         if turtle.detect() then
  67.             if not tryDig() then
  68.                 return false
  69.             end
  70.         elseif turtle.attack() then
  71.             collect()
  72.         else
  73.             sleep( 0.5 )
  74.         end
  75.     end
  76.     return true
  77. end
  78.  
  79. local function tryDig()
  80.     while turtle.detect() do
  81.         if turtle.dig() then
  82.             collect()
  83.             sleep(0.5)
  84.         else
  85.             return false
  86.         end
  87.     end
  88.     return true
  89. end
  90.  
  91. local function tryDigDown()
  92.     while turtle.detectDown() do
  93.         if turtle.digDown() then
  94.             collect()
  95.             sleep(0.5)
  96.         else
  97.             return false
  98.         end
  99.     end
  100.     return true
  101. end
  102.  
  103. for n=1,length do
  104.     tryDig()
  105.     tryDigDown()
  106.     if n<length then
  107.         tryDig()
  108.         if not tryForward() then
  109.             print( "Aborting Tunnel." )
  110.             break
  111.         end
  112.     else
  113.         print( "Tunnel complete." )
  114.     end
  115.  
  116. end
  117.  
  118. print( "Returning to start..." )
  119.  
  120. -- Return to where we started
  121. turtle.turnLeft()
  122. turtle.turnLeft()
  123. while depth > 0 do
  124.     if turtle.forward() then
  125.         Nachlegen()
  126.         turtle.placeDown()
  127.         depth = depth - 1
  128.     else
  129.         turtle.dig()
  130.     end
  131. end
  132. turtle.turnRight()
  133. turtle.turnRight()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement