Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function veinMine(direction)
- os.loadAPI("moveApi")
- local initialPos = moveApi.loadPosition()
- local resp = false
- local data = nil
- if(direction == 5) then
- resp, data = turtle.inspectUp()
- elseif(direction == 6) then
- resp, data = turtle.inspectDown()
- else
- moveApi.face(direction)
- resp, data = turtle.inspect()
- end
- if(resp == false) then
- print("no vein to mine")
- else
- local nm = data.name
- print("vein name is "..nm)
- os.loadAPI("stack")
- local st = stack.newStack()
- local ix = initialPos.x
- local iy = initialPos.y
- local iz = initialPos.z
- local id = initialPos.dir
- local delta = moveApi.getMovementVector(direction)
- os.loadAPI("tableApi")
- str = tableApi.dump(delta)
- --print("delta for direction "..direction.." = "..str)
- stack.push(st, ix + delta.dx)
- stack.push(st,iy + delta.dy)
- stack.push(st,iz + delta.dz)
- while(st.sz ~= 0) do
- local nz = stack.pop(st)
- local ny = stack.pop(st)
- local nx = stack.pop(st)
- print(tableApi.dump(st))
- moveApi.goTo(nx,ny,nz)
- local res, updata = turtle.inspectUp()
- if(res == true and updata.name == nm) then
- stack.push(st, nx)
- stack.push(st, ny + 1)
- stack.push(st, nz)
- end
- local res, downdata = turtle.inspectDown()
- if(res == true and downdata.name == nm) then
- stack.push(st, nx)
- stack.push(st, ny - 1)
- stack.push(st, nz)
- end
- for i = 1, 4 do
- local currentPos = moveApi.loadPosition()
- local vector = moveApi.getMovementVector(currentPos.dir)
- local res, frontdata = turtle.inspect()
- if(res == true and frontdata.name == nm) then
- stack.push(st, nx + vector.dx)
- stack.push(st, ny)
- stack.push(st, nz + vector.dz)
- end
- moveApi.turnRight()
- end
- end
- moveApi.goTo(ix,iy,iz)
- moveApi.face(id)
- end
- end
Add Comment
Please, Sign In to add comment