TheDarBear

veinMine

Mar 4th, 2022 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. function veinMine(direction)
  2. os.loadAPI("moveApi")
  3. local initialPos = moveApi.loadPosition()
  4. local resp = false
  5. local data = nil
  6. if(direction == 5) then
  7. resp, data = turtle.inspectUp()
  8. elseif(direction == 6) then
  9. resp, data = turtle.inspectDown()
  10. else
  11. moveApi.face(direction)
  12. resp, data = turtle.inspect()
  13. end
  14. if(resp == false) then
  15. print("no vein to mine")
  16. else
  17. local nm = data.name
  18. print("vein name is "..nm)
  19. os.loadAPI("stack")
  20. local st = stack.newStack()
  21. local ix = initialPos.x
  22. local iy = initialPos.y
  23. local iz = initialPos.z
  24. local id = initialPos.dir
  25. local delta = moveApi.getMovementVector(direction)
  26. os.loadAPI("tableApi")
  27. str = tableApi.dump(delta)
  28. --print("delta for direction "..direction.." = "..str)
  29. stack.push(st, ix + delta.dx)
  30. stack.push(st,iy + delta.dy)
  31. stack.push(st,iz + delta.dz)
  32. while(st.sz ~= 0) do
  33. local nz = stack.pop(st)
  34. local ny = stack.pop(st)
  35. local nx = stack.pop(st)
  36. print(tableApi.dump(st))
  37. moveApi.goTo(nx,ny,nz)
  38. local res, updata = turtle.inspectUp()
  39. if(res == true and updata.name == nm) then
  40. stack.push(st, nx)
  41. stack.push(st, ny + 1)
  42. stack.push(st, nz)
  43. end
  44. local res, downdata = turtle.inspectDown()
  45. if(res == true and downdata.name == nm) then
  46. stack.push(st, nx)
  47. stack.push(st, ny - 1)
  48. stack.push(st, nz)
  49. end
  50. for i = 1, 4 do
  51. local currentPos = moveApi.loadPosition()
  52. local vector = moveApi.getMovementVector(currentPos.dir)
  53. local res, frontdata = turtle.inspect()
  54. if(res == true and frontdata.name == nm) then
  55. stack.push(st, nx + vector.dx)
  56. stack.push(st, ny)
  57. stack.push(st, nz + vector.dz)
  58. end
  59. moveApi.turnRight()
  60. end
  61. end
  62. moveApi.goTo(ix,iy,iz)
  63. moveApi.face(id)
  64. end
  65. end
  66.  
  67.  
Add Comment
Please, Sign In to add comment