Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- API
- -- help functions to implement mining of veins.
- --args={...}
- os.loadAPI("theinsekt/turtle2")
- os.loadAPI("theinsekt/mine2")
- os.loadAPI("theinsekt/position") -- will be used to set a radius
- -- check for vein in the given direction and mines it if valuable
- -- returns true if has returned to starting position or
- -- hasn't moved from starting position
- -- this is because wanna avoid runaway turtle.
- -- slots are a 1 indexed array that contains
- -- the item slots that will be used to compare
- -- if the ore in the given direction is a valuable ore.
- function mineVein(dir,slots, is_good,limit)
- -- if it's not a block it can't be a vein
- if not turtle2.detect(dir) then
- return true
- end
- -- check limit
- if position.whatIfLargest(dir,1)>limit then
- return true
- end
- --print("checking ore...")
- if isValuable(dir,slots,is_good) then
- turtle.select(1)
- --print("valuable!")
- if mine2.digLoop(dir,1)~=1 then
- -- could not mine
- -- but is at starting position
- return true
- end
- position.update(dir,1) --test
- --print("got it!")
- if not mineVeinR(slots,is_good,limit) then
- -- other could not go back
- return false
- end
- if mine2.digLoop(dir,-1)~=-1 then
- -- could not go back
- print("can't go back, aborting!")
- return false
- end
- position.update(dir,-1) --test
- else
- --print("crap!")
- end
- -- no problems
- return true
- end
- -- check for vein in all directions
- function mineVeinR(slots,is_good,limit)
- local i=0
- while i<4 do
- if not mineVein("f",slots,is_good,limit) then
- return false
- end
- mine2.turn("r",1)
- position.update("r",1) --test
- i=i+1
- end
- if not mineVein("u",slots,is_good,limit) then
- return false
- end
- if not mineVein("d",slots,is_good,limit) then
- return false
- end
- return true
- end
- function isValuable(dir, slots, is_good)
- if same(dir,slots) then
- return is_good
- else
- return not is_good
- end
- end
- function same(dir, slots)
- local compare=turtle2.getCompare(dir)
- for index, slot in ipairs(slots) do
- turtle.select(slot)
- if compare() then
- return true
- end
- end
- return false
- end
- function slotsA()
- local slots={}
- local index=1
- local i=1
- while i<=16 do
- if turtle.getItemCount(i)==0 then
- break
- end
- slots[index]=i
- index=index+1
- i=i+1
- end
- return slots
- end
- --[[commented out
- -- tests
- local slots=slotsA()
- same("f", slots)
- --position.update("f",1)
- --local x,y,z,rot=position.get()
- --print(x.." "..y." "..z.." "..rot)
- if #args==1 then
- local dir=args[1]
- print("starting mineVein")
- position.reset()
- print(mineVein(dir,slots,true,20))
- print("finished")
- end
- ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement