Advertisement
pedrosgali

Branch 2.0

Feb 19th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.94 KB | None | 0 0
  1. os.loadAPI("Lib/move")
  2. args = {...}
  3.  
  4. banList = {"stone", "dirt", "gravel"}
  5. retPoint = {x = 0, y = 0, z = 0, h = 0}
  6. --Set minHeight to 4 to get bedrock layer.
  7. minHeight = 4
  8.  
  9. function splitString(str)
  10.   return string.sub(str, 11, #str)
  11. end
  12.  
  13. function checkFull()
  14.   for i = 1, 16 do
  15.     if turtle.getItemCount(i) == 0 then
  16.       return false
  17.     end
  18.   end
  19.   return true
  20. end
  21.  
  22. function checkFront()
  23.   local s, d = turtle.inspect()
  24.   if not s then return false end
  25.   local name = splitString(d.name)
  26.   for i = 1, #banList do
  27.     if name == banList[i] then
  28.       return false
  29.     end
  30.   end
  31.   turtle.dig()
  32.   move.report("Treasure found!")
  33. end
  34.  
  35. function setReturnPoint()
  36.   retPoint = {
  37.   x = move.data.pos.x,
  38.   y = move.data.pos.y,
  39.   z = move.data.pos.z,
  40.   h = move.data.pos.h,
  41.   }
  42. end
  43.  
  44. function branch(length)
  45.   for i = 1, length do
  46.     if checkFull() then
  47.       setReturnPoint()
  48.       move.toNoSafety(move.getTarget())
  49.       move.unload(true)
  50.       move.findZ(retPoint.z)
  51.       move.findX(retPoint.x)
  52.       move.face(retPoint.h)
  53.     end
  54.     move.fd(1, true)
  55.     move.rt(1)
  56.     checkFront()
  57.     move.lt(2)
  58.     checkFront()
  59.     move.rt(1)
  60.   end
  61.   move.rt(2)
  62.   move.fd(length, true)
  63. end
  64.  
  65. function trunk(length, bLength)--Length is multiplied by three to mean how many branches you want.
  66.   move.setReturnPoint()
  67.   for i = 1, length do
  68.     move.report("Starting Trunk Segment "..i..".")
  69.     move.fd(3, true)
  70.     move.rt(1)
  71.     branch(bLength)
  72.     branch(bLength)
  73.     move.lt(1)
  74.     move.report("Trunk Segment "..i.." complete.")
  75.   end
  76.   move.rt(2)
  77.   move.fd(length * 3)
  78.   move.rt(2)
  79.   move.report("Trunk complete.")
  80. end
  81.  
  82. function mine(tLen, bLen, yLevels)
  83.   for i = 1, yLevels do
  84.     move.report("Mining layer "..i)
  85.     move.findY(minHeight + i, true)
  86.     trunk(tLen, bLen)
  87.   end
  88.   move.to(move.home.x, move.home.y, move.home.z, move.home.h)
  89. end
  90.  
  91. mine(tonumber(args[1]), tonumber(args[2]), tonumber(args[3]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement