Advertisement
visiongaming43

Untitled

May 21st, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. -- DEFAULTS TO TURNING TURTLE NORTH ( Z - AXIS )
  2. function faceNorth()
  3. local startX, startY, startZ = gps.locate()
  4. startY = nil
  5. turtle.back()
  6. local endX, endY, endZ = gps.locate()
  7. endY = nil
  8. turtle.forward()
  9. if(endX < startX) then turtle.turnLeft()
  10. elseif (endX > startX) then turtle.turnRight()
  11. elseif (endZ < startZ) then turtle.turnRight() turtle.turnRight()
  12. end
  13. end
  14.  
  15. -- MOVES TO COORDINATES X, Y, Z
  16. function moveTo(x, y, z)
  17. faceNorth()
  18. local curX, curY, curZ = gps.locate()
  19. local xDist = math.abs(x - curX)
  20. local yDist = math.abs(y - curY)
  21. local zDist = math.abs(z - curZ)
  22. local xMethod local yMethod local zMethod
  23. if (curX > x) then xMethod = turtle.back else xMethod = turtle.forward end
  24. if (curY > y) then yMethod = turtle.down else yMethod = turtle.up end
  25. if (curZ > z) then zMethod = turtle.back else zMethod = turtle.forward end
  26.  
  27. while (zDist > 0) do
  28. zMethod()
  29. zDist = zDist - 1
  30. end
  31. turtle.turnLeft()
  32. while (xDist > 0) do
  33. xMethod()
  34. xDist = xDist - 1
  35. end
  36. while (yDist > 0) do
  37. yMethod()
  38. yDist = yDist - 1
  39. end
  40. end
  41.  
  42. function resetPos()
  43. local file = fs.open("Settings", "r")
  44. local startX = file.readLine()
  45. local startY = file.readLine()
  46. local startZ = file.readLine()
  47. file.close()
  48. moveTo(startX, startY, startZ)
  49. end
  50.  
  51. function getSeedIndex()
  52. for slot = 1, 16, 1 do
  53. local item = turtle.getItemDetail(slot)
  54. if ( (item ~= nil) and ( (string.match(item.name, "seed") ) or (string.match(item.name, "potato") ) or (string.match(item.name, "carrot") ) ) ) then
  55. return slot
  56. end
  57. end
  58. end
  59.  
  60. function getCrop()
  61. local isBlock, data = turtle.inspectDown()
  62. if(isBlock)then
  63. if ( ( string.match(data.name, "croptopia:") or string.match(data.name, "wheat") or string.match(data.name, "potato") or string.match(data.name, "carrot")) and data['state']['age'] == 7) then
  64. turtle.digDown()
  65. seedIndex = getSeedIndex()
  66. if(seedIndex ~= nil) then
  67. turtle.select(seedIndex)
  68. turtle.placeDown()
  69. end
  70. end
  71. else
  72. seedIndex = getSeedIndex()
  73. if(seedIndex ~= nil) then
  74. turtle.digDown()
  75. turtle.select(seedIndex)
  76. turtle.placeDown()
  77. end
  78. end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement