Advertisement
visiongaming43

Untitled

Jun 12th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. -- List of keywords that the turtle will use to figure out what to plant
  2. local ACCEPTABLE_SEEDS = {
  3. "seed",
  4. "minecraft:carrot",
  5. "minecraft:potato",
  6. "minecraft:nether_wart"
  7. }
  8. -- List of keywords that the turtle will use to figure out what to break
  9. local ACCEPTABLE_PLANTS = {
  10. "croptopia:",
  11. "carrot",
  12. "wheat",
  13. "beetroot",
  14. "potato",
  15. "nether_wart"
  16. }
  17.  
  18. local posLib = require("posLib")
  19. local invLib = require("invLib")
  20. local farmX, farmY, farmZ, farmHeading, length, width, direction
  21.  
  22. function getCoordinatesFromFile()
  23. local farmSettings = fs.open("FARM_STATS", "r")
  24. farmX = tonumber(farmSettings.readLine())
  25. farmY = tonumber(farmSettings.readLine())
  26. farmZ = tonumber(farmSettings.readLine())
  27. farmSettings.close()
  28. return farmX, farmY, farmZ
  29. end
  30.  
  31. function getHeadingFromFile()
  32. local farmSettings = fs.open("FARM_STATS", "r")
  33. for _ = 1, 3 do
  34. farmSettings.readLine()
  35. end
  36. farmHeading = tonumber(farmSettings.readLine())
  37. farmSettings.close()
  38. return farmHeading
  39. end
  40.  
  41. function getDimensionsFromFile()
  42. local farmSettings = fs.open("FARM_STATS", "r")
  43. for _ = 1, 4 do
  44. farmSettings.readLine()
  45. end
  46. length = tonumber(farmSettings.readLine())
  47. width = tonumber(farmSettings.readLine())
  48. farmSettings.close()
  49. return length, width
  50. end
  51.  
  52. function getDirectionFromFile()
  53. local farmSettings = fs.open("FARM_STATS", "r")
  54. for _ = 1, 6 do
  55. farmSettings.readLine()
  56. end
  57. direction = farmSettings.readLine()
  58. farmSettings.close()
  59. return direction
  60. end
  61.  
  62. function getAllInformationFromFile()
  63. local farmSettings = fs.open("FARM_STATS", "r")
  64. local farminfo = {}
  65. farminfo["farmX"] = tonumber(farmSettings.readLine())
  66. farminfo["farmY"] = tonumber(farmSettings.readLine())
  67. farminfo["farmZ"] = tonumber(farmSettings.readLine())
  68. farminfo["farmHeading"] = tonumber(farmSettings.readLine())
  69. farminfo["length"] = tonumber(farmSettings.readLine())
  70. farminfo["width"] = tonumber(farmSettings.readLine())
  71. farminfo["direction"] = farmSettings.readLine()
  72. farmSettings.close()
  73. return farminfo
  74. end
  75.  
  76. local farmInfo = getAllInformationFromFile()
  77.  
  78. local firstTurn
  79. if (farmInfo["direction"] == "LEFT") then
  80. firstTurn = posLib.turnLeft
  81. else
  82. firstTurn = posLib.turnRight
  83. end
  84.  
  85. local lastSeedIndex = findSlot(ACCEPTABLE_SEEDS, 1, 16)
  86.  
  87. function moveToStart()
  88. posLib.moveTo(farmInfo["farmX"], farmInfo["farmY"], farmInfo["farmZ"])
  89. posLib.faceHeading(farmInfo["farmHeading"])
  90. end
  91.  
  92. function plantSeed()
  93. if (not lastSeedIndex) then
  94. lastSeedIndex = findSlot(ACCEPTABLE_SEEDS, 1, 16)
  95. if (not lastSeedIndex) then
  96. return
  97. end
  98. end
  99. turtle.select(lastSeedIndex)
  100. turtle.placeDown()
  101. end
  102.  
  103. function harvestBlock()
  104. local isBlock, blockData = turtle.inspectDown()
  105. if (isBlock) then
  106. for index, name in ACCEPTABLE_PLANTS do
  107. if (blockData['name'] == name and blockData['age'] == 7) then
  108. turtle.digDown()
  109. plantSeed()
  110. break
  111. end
  112. end
  113. return
  114. end
  115. plantSeed()
  116. end
  117.  
  118. -- RUNS = MATH.MIN(length, width)*2 - 1
  119. -- TURNS = RUNS - 1
  120. -- 0 -1 -1 -2 -2 -3 -3 ...
  121. -- START AT 0, THE NEXT TWO ARE ONE LESS PERMANENTLY
  122. -- ALWAYS ENDS ON LENGTH IF STARTS BY LENGTH
  123. function riceFarm()
  124. local l = length
  125. while (l > 0) do
  126. posLib.forward()
  127. harvestBlock()
  128. l = l - 1
  129. end
  130. local w = width - 1
  131. if (w <= 0) then return end
  132. firstTurn()
  133. while (w > 0) do
  134. posLib.forward()
  135. harvestBlock()
  136. w = w - 1
  137. end
  138. firstTurn()
  139. length = length - 1
  140. width = width - 1
  141. return riceFarm()
  142. end
  143.  
  144. return { getCoordinatesFromFile = getCoordinatesFromFile, getHeadingFromFile = getHeadingFromFile,
  145. getDimensionsFromFile = getDimensionsFromFile, getDirectionFromFile = getDirectionFromFile,
  146. getAllInformationFromFile = getAllInformationFromFile, moveToStart = moveToStart, plantSeed = plantSeed,
  147. harvestBlock = harvestBlock, riceFarm = riceFarm }
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement