Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("theinsekt/mine1")
- os.loadAPI("theinsekt/turtle2")
- -- mines in the given direction for the given length
- function digLoop(dir, length)
- -- negative direction, is just positive direction
- -- with inverted direction name
- if length<0 then
- return -digLoop(turtle2.inv(dir),-length)
- end --if
- -- check the different possible cases
- if turtle2.isTurn(dir) then
- -- only turn
- --print("turning")
- return turn(dir,length)
- elseif dir=="b" then
- --print("mining back")
- -- back as far as possible
- local res1=mine1.goLoop(turtle2.getGo(dir),length)
- local res2=0
- -- check if need to dig
- if res1~=length then
- -- can't dig backwards, so turn and dig
- turn("r",2)
- local res2=digLoop("f",length-res1)
- turn("l",2)
- end
- -- distance travelled
- return res1+res2
- else
- --print("mining in direction")
- -- mine in the given direction
- return mine1.digLoop(turtle2.getDetect(dir),
- turtle2.getDig(dir),turtle2.getGo(dir),
- length,20)
- end --else
- end --function
- function turn(dir, length)
- if length<0 then
- return -turn(turtle2.inv(dir),-length)
- end
- return mine1.turn(turtle2.getGo(dir),
- turtle2.getGo(turtle2.inv(dir)),
- length)
- end
Advertisement
Add Comment
Please, Sign In to add comment