Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 指定した方向のブロックをcompare_fnが返すスロットのアイテムと置換する
- -- @params direction 方向。0=正面,1=上,2=下,3=右,4=左
- -- @params compare_fn 比較関数。inspectの結果(bool, any)が渡される。設置に使用するアイテムのあるスロット番号か設置しない場合nilを返す
- function break_if(direction, compare_fn)
- function impl(inspect_fn, dig_fn, place_fn)
- local use_slot = compare_fn(inspect_fn())
- if not (nil ~= use_slot) then
- return true
- end
- local dig_re, dig_message = dig_fn()
- if not dig_re then
- return false, dig_message
- end
- return true
- end
- if (direction == 0) then
- return impl(turtle.inspect, turtle.dig)
- elseif (direction == 1) then
- return impl(turtle.inspectUp, turtle.digUp)
- elseif (direction == 2) then
- return impl(turtle.inspectDown, turtle.digDown)
- elseif (direction == 3) then
- turtle.turnRight()
- local re, message = impl(turtle.inspect, turtle.dig)
- turtle.turnLeft()
- return re, message
- elseif (direction == 4) then
- turtle.turnLeft()
- local re, message = impl(turtle.inspect, turtle.dig)
- turtle.turnRight()
- return re, message
- end
- return false, string.format("unknown direction: %d", direction)
- end
- -- local w, h, len = ...
- function replace_cond(i_re, i_v)
- if i_re == nil then
- return nil
- end
- if i_v.name ~= "appliedenergistics2:sky_stone_chest" then
- return 1
- end
- print("not to break", i_v.name)
- return nil
- end
- local n = ...
- print("dig down y axis to ", n)
- local move_fns = { turtle.down, turtle.forward }
- for i = 0, n * 2 do
- break_if(2, replace_cond)
- break_if(0, replace_cond)
- print(i % 2)
- local move_re = move_fns[i % 2 + 1]()
- if not move_re then
- print("failed to move")
- break
- end
- if (i + 1) % 4 == 0 then
- turtle.turnRight()
- print("turn")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement