Advertisement
theinsekt

veinMiner

Feb 22nd, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.10 KB | None | 0 0
  1. -- is used to dig a u shaped tunnel, and mining encountered veins.
  2. -- the parameters can be set in such a way that a room is dug,
  3. -- (veins are still mined).
  4.  
  5. args={...}
  6.  
  7. os.loadAPI("theinsekt/mine2")
  8. os.loadAPI("theinsekt/mineVein")
  9.  
  10. function veinTunnel(length, avoid,passable)
  11.   local slots=mineVein.slotsA()
  12.   if slots==nil or #slots==0 then
  13.     print("Detected no items in the first slots in the inventory.")
  14.     return true
  15.   end
  16.  
  17.   if not veinFUD(slots,avoid, 20) then
  18.       print("1: Blocked or out of fuel.")
  19.       return false
  20.   end
  21.  
  22.   local i=0
  23.   while i<length do
  24.     if mine2.digLoop("f",1)~=1 then
  25.       print("2: Blocked or out of fuel.")
  26.       return false
  27.     end
  28.     if not veinFUD(slots,avoid, 20) then
  29.       print("3: Blocked or out of fuel.")
  30.       return false
  31.     end
  32.     -- so that the player can follow
  33.     if passable then
  34.       mine2.digLoop("d",0)
  35.     end
  36.     i=i+1
  37.   end
  38.   return true
  39. end
  40.  
  41. function veinMinerU(length, width, avoid, iters,passable)
  42.   local i=0
  43.   while i<iters do
  44.     -- mine length
  45.     if not veinTunnel(length,avoid,passable) then return false end
  46.     -- turn and dig width
  47.     if width>0 then
  48.       mine2.turn("r",1)
  49.       if not veinTunnel(width,avoid,passable) then return false end
  50.       mine2.turn("r",1)
  51.     else
  52.       mine2.turn("l",1)
  53.       if not veinTunnel(-width,avoid,passable) then return false end
  54.       mine2.turn("l",1)
  55.     end
  56.     -- mine length back
  57.     if not veinTunnel(length,avoid,passable) then return false end
  58.     -- mine so prepared for next command
  59.     if width>0 then
  60.       mine2.turn("r",-1)
  61.       if not veinTunnel(width,avoid,passable) then return false end
  62.       mine2.turn("r",-1)
  63.     else
  64.       mine2.turn("l",-1)
  65.       if not veinTunnel(-width,avoid,passable) then return false end
  66.       mine2.turn("l",-1)
  67.     end
  68.     i=i+1
  69.   end
  70. end
  71.  
  72. -- returns true if back at start position
  73. -- aborts and returns false if can't get back
  74. -- limit is to avoid you loosing the turtle
  75. -- because it mines everything
  76. function veinFUD(slots,avoid, limit)
  77.   -- only need to reset once because will
  78.   -- return to start position after each call
  79.   -- to mineVein
  80.   position.reset()
  81.   -- check each visible direction, and will
  82.   -- make shure that the next is not run
  83.   -- if false is returned by the previous call.
  84.   return mineVein.mineVein("f",slots,not avoid,limit)
  85.   and mineVein.mineVein("u",slots,not avoid,limit)
  86.   and mineVein.mineVein("d",slots,not avoid,limit)
  87. end
  88.  
  89. --position.printit()
  90. --print(veinTunnel(2, false))
  91. --position.printit()
  92.  
  93. if #args~=5 then
  94.   print("Usage: veinMiner <length> <width> <iters> <avoid y/n> <passable y/n>")
  95.   return
  96. end
  97. local length=tonumber(args[1])
  98. local width=tonumber(args[2])
  99. local iters=tonumber(args[3])
  100. local avoid
  101. if args[4]=="y" then
  102.   avoid=true
  103. elseif args[4]=="n" then
  104.   avoid=false
  105. else
  106.   print("Error: avoid must be y or n")
  107.   return
  108. end
  109. local passable
  110. if args[5]=="y" then
  111.   passable=true
  112. elseif args[5]=="n" then
  113.   passable=false
  114. else
  115.   print("Error: passable must be y or n")
  116.   return
  117. end
  118.  
  119. print(veinMinerU(length, width, avoid, iters,passable))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement