Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- is used to dig a u shaped tunnel, and mining encountered veins.
- -- the parameters can be set in such a way that a room is dug,
- -- (veins are still mined).
- args={...}
- os.loadAPI("theinsekt/mine2")
- os.loadAPI("theinsekt/mineVein")
- function veinTunnel(length, avoid,passable)
- local slots=mineVein.slotsA()
- if slots==nil or #slots==0 then
- print("Detected no items in the first slots in the inventory.")
- return true
- end
- if not veinFUD(slots,avoid, 20) then
- print("1: Blocked or out of fuel.")
- return false
- end
- local i=0
- while i<length do
- if mine2.digLoop("f",1)~=1 then
- print("2: Blocked or out of fuel.")
- return false
- end
- if not veinFUD(slots,avoid, 20) then
- print("3: Blocked or out of fuel.")
- return false
- end
- -- so that the player can follow
- if passable then
- mine2.digLoop("d",0)
- end
- i=i+1
- end
- return true
- end
- function veinMinerU(length, width, avoid, iters,passable)
- local i=0
- while i<iters do
- -- mine length
- if not veinTunnel(length,avoid,passable) then return false end
- -- turn and dig width
- if width>0 then
- mine2.turn("r",1)
- if not veinTunnel(width,avoid,passable) then return false end
- mine2.turn("r",1)
- else
- mine2.turn("l",1)
- if not veinTunnel(-width,avoid,passable) then return false end
- mine2.turn("l",1)
- end
- -- mine length back
- if not veinTunnel(length,avoid,passable) then return false end
- -- mine so prepared for next command
- if width>0 then
- mine2.turn("r",-1)
- if not veinTunnel(width,avoid,passable) then return false end
- mine2.turn("r",-1)
- else
- mine2.turn("l",-1)
- if not veinTunnel(-width,avoid,passable) then return false end
- mine2.turn("l",-1)
- end
- i=i+1
- end
- end
- -- returns true if back at start position
- -- aborts and returns false if can't get back
- -- limit is to avoid you loosing the turtle
- -- because it mines everything
- function veinFUD(slots,avoid, limit)
- -- only need to reset once because will
- -- return to start position after each call
- -- to mineVein
- position.reset()
- -- check each visible direction, and will
- -- make shure that the next is not run
- -- if false is returned by the previous call.
- return mineVein.mineVein("f",slots,not avoid,limit)
- and mineVein.mineVein("u",slots,not avoid,limit)
- and mineVein.mineVein("d",slots,not avoid,limit)
- end
- --position.printit()
- --print(veinTunnel(2, false))
- --position.printit()
- if #args~=5 then
- print("Usage: veinMiner <length> <width> <iters> <avoid y/n> <passable y/n>")
- return
- end
- local length=tonumber(args[1])
- local width=tonumber(args[2])
- local iters=tonumber(args[3])
- local avoid
- if args[4]=="y" then
- avoid=true
- elseif args[4]=="n" then
- avoid=false
- else
- print("Error: avoid must be y or n")
- return
- end
- local passable
- if args[5]=="y" then
- passable=true
- elseif args[5]=="n" then
- passable=false
- else
- print("Error: passable must be y or n")
- return
- end
- print(veinMinerU(length, width, avoid, iters,passable))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement