Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ########################################
- -- digFor / digExcept
- -- versoin 0.1
- -- (c) 2015 hevohevo, License: MIT
- -- twitter: @hevohevo, http://hevohevo.hatenablog.com/
- -- 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
- -- 各種digFor/digExcept関数を作るための元関数
- function _digFor(tbl, inspect_func, dig_func, except_flag)
- if type(tbl) ~= "table" then return dig_func() end
- local status, value = inspect_func()
- print(value["name"])
- if status then
- -- ブロックが存在するとき
- if _matchNames(tbl, value["name"], value["metadata"]) then
- if except_flag then -- 除外フラグtrueならマッチしたときに何もしない
- return false, "Find an exception block"
- else
- return dig_func()
- end
- else
- if except_flag then -- 除外フラグfalseならマッチしたときに採掘
- return dig_func()
- else
- return false, "No block to match"
- end
- end
- else
- -- ブロックが存在しないとき
- return dig_func()
- end
- end
- -- 各方向の関数を定義
- -- digFor/digExcept, digUpFor/digUpExcept, digDownFor/digDownExcept
- function digFor(tbl)
- return _digFor(tbl, turtle.inspect, turtle.dig, false)
- end
- function digExcept(tbl)
- return _digFor(tbl, turtle.inspect, turtle.dig, true)
- end
- function digUpFor(tbl)
- return _digFor(tbl, turtle.inspectUp, turtle.digUp, false)
- end
- function digUpExcept(tbl)
- return _digFor(tbl, turtle.inspectUp, turtle.digUp, true)
- end
- function digDownFor(tbl)
- return _digFor(tbl, turtle.inspectDown, turtle.digDown, false)
- end
- function digDownExcept(tbl)
- return _digFor(tbl, turtle.inspectDown, turtle.digDown, true)
- end
- -- main部分
- while true do
- print(digUpExcept(block_names))
- os.sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement