Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- required ComputerCraft1.65
- local block_names = {
- {"dirt",0}, "stone", {"wool",1}
- }
- function matchNames(names, block_name, block_meta)
- for i,p in ipairs(names) do
- if type(p)=="table" then
- if string.match(block_name, p[1]) and block_meta == p[2] then
- return true
- end
- else
- if string.match(block_name, p) then
- return true
- end
- end
- end
- return false
- end
- function digExcept(tbl)
- if not tbl then return turtle.dig() end
- local status, value = turtle.inspect()
- if status then
- -- ブロックが存在するとき
- if matchNames(tbl, value["name"], value["metadata"]) then
- -- マッチしたとき
- return false, "Find the exception block"
- else
- -- マッチしないとき
- return turtle.dig()
- end
- else
- -- ブロックが存在しないとき
- return turtle.dig()
- end
- end
- function digFor(tbl)
- if not tbl then return turtle.dig() end
- local status, value = turtle.inspect()
- if status then
- -- ブロックが存在するとき
- if matchNames(tbl, value["name"], value["metadata"]) then
- -- マッチしたとき
- return turtle.dig()
- else
- -- マッチしないとき
- return false, "No block to match"
- end
- else
- -- ブロックが存在しないとき
- return turtle.dig()
- end
- end
- while true do
- -- print(digFor(block_names))
- print(digExcept(block_names))
- os.sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement