Advertisement
visiongaming43

Untitled

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