Advertisement
visiongaming43

Untitled

May 22nd, 2022
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. require("TurtleLib/generalLibrary")
  2.  
  3. SEED_LIST = { "croptopia", "seed", "carrot" }
  4. SEED_LIST_SIZE = tableLength(SEED_LIST)
  5.  
  6. function getSeedIndex()
  7. return findSlot(SEED_LIST)
  8. end
  9.  
  10. function checkForCrop(data)
  11. for value in ipairs(SEED_LIST) do
  12. if (string.match(data['name'], value) == true and data['state']['age'] == 7) then return true end
  13. end
  14. return false
  15. end
  16.  
  17. function getCrop()
  18. local isBlock, data = turtle.inspectDown()
  19. if (isBlock) then
  20. if (checkForCrop(data)) then
  21. turtle.digDown()
  22. else
  23. return
  24. end
  25. end
  26. local seedIndex = getSeedIndex()
  27. if (seedIndex ~= -1) then
  28. turtle.select(seedIndex)
  29. turtle.placeDown()
  30. end
  31. end
  32.  
  33. function resetPos()
  34. local file = fs.open("Settings", "r")
  35. local startX = tonumber(file.readLine())
  36. local startY = tonumber(file.readLine())
  37. local startZ = tonumber(file.readLine())
  38. file.readLine()
  39. file.readLine()
  40. file.readLine()
  41. local direction = file.readLine()
  42. file.close()
  43. moveTo(startX, startY, startZ)
  44. faceDirection(direction)
  45. end
  46.  
  47. function checkPos()
  48. local startX, startY, startZ = getCoordinates()
  49. local startDirection = getDirection()
  50. os.sleep(1)
  51. local file = fs.open("Settings", "r")
  52. local posX = file.readLine()
  53. local posY = file.readLine()
  54. local posZ = file.readLine()
  55. skipLines(file, 3)
  56. local posDirection = file.readLine()
  57. if (startX == posX and startY == posY and startZ == posZ and startDirection == posDirection) then
  58. return true
  59. else
  60. return false
  61. end
  62. end
  63.  
  64. function farm()
  65. local file = fs.open("Settings", "r")
  66. skipLines(file, 3)
  67. local length = file.readLine()
  68. local width = file.readLine()
  69. local orientation = file.readLine()
  70. local firstTurn
  71. if (orientation == "LEFT") then
  72. firstTurn = turtle.turnLeft
  73. else
  74. firstTurn = turtle.turnRight
  75. end
  76.  
  77. keepDigging()
  78. turtle.forward()
  79. firstTurn()
  80.  
  81. for row = 1, length do
  82. for col = 1, width - 1 do
  83. getCrop()
  84. keepDigging()
  85. turtle.forward()
  86. end
  87. getCrop()
  88. oppositeTurn(firstTurn)
  89. turtle.forward()
  90. firstTurn = oppositeTurn(firstTurn)
  91. end
  92.  
  93. resetPos()
  94. if (not checkPos()) then
  95. error("TURTLE HAS NOT GONE TO ORIGINAL FARMING COORDINATES! ANALYZE CODE!")
  96. else
  97. printColor(colors.green, "TURTLE HAS SUCCESSFULLY RESET ITS POSITION!\n\nREADY TO RESTART...")
  98. end
  99. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement