Advertisement
visiongaming43

Untitled

May 21st, 2022
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 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. print("xDist: " .. xDist .. "\nyDist: " .. yDist .. "\nzDist: " .. zDist)
  35. local xMethod
  36. local yMethod
  37. local zMethod
  38. if (curX > x) then xMethod = turtle.forward else xMethod = turtle.back end
  39. if (curY > y) then yMethod = turtle.down else yMethod = turtle.up end
  40. if (curZ > z) then zMethod = turtle.forward else zMethod = turtle.back end
  41.  
  42. while (xDist > 0) do
  43. xMethod()
  44. xDist = xDist - 1
  45. end
  46. turtle.turnLeft()
  47. while (zDist > 0) do
  48. zMethod()
  49. zDist = zDist - 1
  50. end
  51. while (yDist > 0) do
  52. yMethod()
  53. yDist = yDist - 1
  54. end
  55. end
  56.  
  57. function getSeedIndex()
  58. for slot = 1, 16, 1 do
  59. local item = turtle.getItemDetail(slot)
  60. if ( (item ~= nil) and ( (string.match(item.name, "seed") ) or (string.match(item.name, "potato") ) or (string.match(item.name, "carrot") ) ) ) then
  61. return slot
  62. end
  63. end
  64. end
  65.  
  66. function getCrop()
  67. local isBlock, data = turtle.inspectDown()
  68. if(isBlock)then
  69. 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
  70. turtle.digDown()
  71. seedIndex = getSeedIndex()
  72. if(seedIndex ~= nil) then
  73. turtle.select(seedIndex)
  74. turtle.placeDown()
  75. end
  76. end
  77. else
  78. seedIndex = getSeedIndex()
  79. if(seedIndex ~= nil) then
  80. turtle.digDown()
  81. turtle.select(seedIndex)
  82. turtle.placeDown()
  83. end
  84. end
  85. end
  86.  
  87. function resetPos()
  88. local file = fs.open("Settings", "r")
  89. local startX = file.readLine()
  90. local startY = file.readLine()
  91. local startZ = file.readLine()
  92. moveTo(startX, startY, startZ)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement