Advertisement
hevohevo

digFor

Jan 24th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.72 KB | None | 0 0
  1. -- required ComputerCraft1.65
  2. local block_names = {
  3.   {"dirt",0}, "stone", {"wool",1}
  4. }
  5.  
  6. function digFor(tbl)
  7.   if not tbl then return turtle.dig() end
  8.  
  9.   local status, value = turtle.inspect()
  10.   if status then
  11.     local name = value["name"]
  12.     local meta = value["metadata"]
  13.  
  14.     for i,v in ipairs(block_names) do
  15.       if type(v)=="table" then
  16.         if string.match(name,v[1]) and meta == v[2] then
  17.           return turtle.dig()
  18.         end
  19.       else
  20.         if string.match(name,v) then
  21.           return turtle.dig()
  22.         end
  23.       end
  24.     end
  25.     return false, "No block to match"
  26.    
  27.   else
  28.     return turtle.dig()
  29.   end
  30. end
  31.  
  32. while true do
  33.   print(digFor(block_names))
  34.   os.sleep(5)
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement