Advertisement
theinsekt

mine3

Feb 21st, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. -- API for more complex mining functions
  2. os.loadAPI("theinsekt/turtle2")
  3. os.loadAPI("theinsekt/mine2")
  4.  
  5. function tunnel3(length)
  6.   local i=0
  7.   while i<length do
  8.     if mine2.digLoop("f",1)~=1 then
  9.       return i
  10.     end
  11.     mine2.digLoop("u",0)
  12.     mine2.digLoop("d",0)
  13.     -- removes some extra gravel
  14.     mine2.digLoop("u",0)
  15.     i=i+1
  16.   end
  17.   return i
  18. end
  19.  
  20. -- digs a 3 height tunnel, shaped
  21. -- like a horizontal U
  22. function horzU(length, width)
  23.    local length2=tunnel3(length)
  24.    if width>0 then
  25.      mine2.turn("r",1)
  26.      tunnel3(width)
  27.      mine2.turn("r",1)
  28.    else
  29.      mine2.turn("l",1)
  30.      tunnel3(-width)
  31.      mine2.turn("l",1)
  32.    end
  33.    local length3=tunnel3(length2)
  34.    -- returns the distance from start
  35.    -- in the length direction
  36.    return length2-length3
  37. end
  38.  
  39. -- Digs an u, and then a reversed u,
  40. -- this creates a zigzag pattern.
  41. -- With width=3 and length>40
  42. -- a efficient strip mining pattern is
  43. -- created.
  44. function stripMine(length, width, iters)
  45.   local i=0
  46.   while i<iters do
  47.     if horzU(length,width)~=0 then
  48.       return i
  49.     end
  50.     horzU(0,-width)
  51.     i=i+1
  52.   end
  53.   return i
  54. end
  55.  
  56. -- direction can only be u or d
  57. function stairs(dir, length)
  58.   if not (dir=="u" or dir=="d") then
  59.     print("Error: direction must be u or d")
  60.     return 0
  61.   end
  62.  
  63.   local i=0
  64.   while i<length do
  65.     mine2.digLoop("u",0)
  66.     mine2.digLoop("d",0)
  67.     if mine2.digLoop("f",1)==0 then
  68.       return i
  69.     end --if
  70.     mine2.digLoop("u",0)
  71.     mine2.digLoop("d",0)
  72.     if mine2.digLoop(dir,1)==0 then
  73.        return i
  74.     end --if
  75.     i=i+1
  76.   end
  77. end
  78.  
  79. -- test
  80. --print(stairs("d",3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement