theinsekt

mine2

Feb 20th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.24 KB | None | 0 0
  1. os.loadAPI("theinsekt/mine1")
  2. os.loadAPI("theinsekt/turtle2")
  3.  
  4. -- mines in the given direction for the given length
  5. function digLoop(dir, length)
  6. -- negative direction, is just positive direction
  7. -- with inverted direction name
  8.   if length<0 then
  9.     return -digLoop(turtle2.inv(dir),-length)
  10.   end --if
  11. -- check the different possible cases
  12.   if turtle2.isTurn(dir) then
  13.     -- only turn
  14.     --print("turning")
  15.     return turn(dir,length)
  16.   elseif dir=="b" then
  17.     --print("mining back")
  18.     -- back as far as possible
  19.     local res1=mine1.goLoop(turtle2.getGo(dir),length)
  20.     local res2=0
  21.     -- check if need to dig
  22.     if res1~=length then
  23.       -- can't dig backwards, so turn and dig
  24.       turn("r",2)
  25.       local res2=digLoop("f",length-res1)
  26.       turn("l",2)
  27.     end
  28.     -- distance travelled
  29.     return res1+res2
  30.   else
  31.     --print("mining in direction")
  32.     -- mine in the given direction
  33.     return mine1.digLoop(turtle2.getDetect(dir),
  34.     turtle2.getDig(dir),turtle2.getGo(dir),
  35.     length,20)
  36.   end --else
  37. end --function
  38.  
  39. function turn(dir, length)
  40.   if length<0 then
  41.     return -turn(turtle2.inv(dir),-length)
  42.   end
  43.   return mine1.turn(turtle2.getGo(dir),
  44.   turtle2.getGo(turtle2.inv(dir)),
  45.   length)
  46. end
Advertisement
Add Comment
Please, Sign In to add comment