Advertisement
Birog

Quarry zwischen Bereich

Aug 12th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local depth = ll
  2. local collected = 0
  3.  
  4. local function collect()
  5.     collected = collected + 1
  6.     if math.fmod(collected, 25) == 0 then
  7.         print( "Mined "..collected.." items." )
  8.     end
  9. end
  10.  
  11. local function tryDig()
  12.     while turtle.detect() do
  13.         if turtle.dig() then
  14.             collect()
  15.             sleep(0.5)
  16.         else
  17.             return false
  18.         end
  19.     end
  20.     return true
  21. end
  22.  
  23. local function tryDigUp()
  24.     while turtle.detectUp() do
  25.         if turtle.digUp() then
  26.             collect()
  27.             sleep(0.5)
  28.         else
  29.             return false
  30.         end
  31.     end
  32.     return true
  33. end
  34.  
  35. local function tryDigDown()
  36.         while turtle.detectDown() do
  37.                 if turtle.digDown() then
  38.                         collect()
  39.                         sleep(0.5)
  40.                 else
  41.                         return false
  42.                 end
  43.         end
  44.         return true
  45. end
  46.  
  47. local function refuel()
  48.     local fuelLevel = turtle.getFuelLevel()
  49.     if fuelLevel == "unlimited" or fuelLevel > 0 then
  50.         return
  51.     end
  52.    
  53.     local function tryRefuel()
  54.         for n=1,16 do
  55.             if turtle.getItemCount(n) > 0 then
  56.                 turtle.select(n)
  57.                 if turtle.refuel(1) then
  58.                     turtle.select(1)
  59.                     return true
  60.                 end
  61.             end
  62.         end
  63.         turtle.select(1)
  64.         return false
  65.     end
  66.    
  67.     if not tryRefuel() then
  68.         print( "Add more fuel to continue." )
  69.         while not tryRefuel() do
  70.             sleep(1)
  71.         end
  72.         print( "Resuming Tunnel." )
  73.     end
  74. end
  75.  
  76. local function tryUp()
  77.     refuel()
  78.     while not turtle.up() do
  79.         if turtle.detectUp() then
  80.             if not tryDigUp() then
  81.                 return false
  82.             end
  83.         elseif turtle.attackUp() then
  84.             collect()
  85.         else
  86.             sleep( 0.5 )
  87.         end
  88.     end
  89.     return true
  90. end
  91.  
  92. local function tryBack()
  93.         refuel()
  94.         while not turtle.back() do
  95.                 if turtle.detect() then
  96.                         if not tryDig() then
  97.                                 return false
  98.                         end
  99.                 elseif turtle.attack() then
  100.                         collect()
  101.                 else
  102.                         sleep( 0.5 )
  103.                 end
  104.         end
  105.         return true
  106. end
  107.  
  108. local function tryDown()
  109.     refuel()
  110.     while not turtle.down() do
  111.         if turtle.detectDown() then
  112.             if not turtle.digDown() then
  113.                 return false
  114.             end
  115.         elseif turtle.attackDown() then
  116.             collect()
  117.         else
  118.             sleep( 0.5 )
  119.         end
  120.     end
  121.     return true
  122. end
  123.  
  124. local function tryForward()
  125.     refuel()
  126.     while not turtle.forward() do
  127.         if turtle.detect() then
  128.             if not tryDig() then
  129.                 return false
  130.             end
  131.         elseif turtle.attack() then
  132.             collect()
  133.         else
  134.             sleep( 0.5 )
  135.         end
  136.     end
  137.     return true
  138. end
  139. print("Wie lang ist der Bereich?")
  140. ll=io.read()
  141. print("Wie tief ist der Bereich")
  142. tt=io.read()
  143. tt=tt-1
  144.  
  145. print( "Tunnelling..." )
  146.  
  147. for n=1,ll do
  148.         for x1=1,tt do
  149.         tryDigDown()
  150.             tryDown()
  151.     end
  152.         turtle.turnRight()
  153.     tryDig()
  154.     tryForward()
  155.     for x2=1,tt do
  156.             tryDigUp()
  157.             tryUp()
  158.         end
  159.     tryBack()
  160.         turtle.turnLeft()
  161.     tryDig()
  162.     tryForward()
  163.  
  164. --  if n < ll then
  165. --      tryDig()
  166. --      if not tryForward() then
  167. --          print( "Aborting Tunnel." )
  168. --          break
  169. --      end
  170. --  else
  171. --      print( "Tunnel complete." )
  172. --  end
  173.  
  174. end
  175.  
  176.  
  177. print( "Returning to start..." )
  178.  
  179. -- Return to where we started
  180. turtle.turnLeft()
  181. turtle.turnLeft()
  182. while depth > 1 do
  183.     if tryForward() then
  184.         depth = depth - 1
  185.     else
  186.         turtle.dig()
  187.     end
  188. end
  189. turtle.turnRight()
  190. turtle.turnRight()
  191.  
  192.  
  193. print( "Tunnel complete." )
  194. print( "Mined "..collected.." items total." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement