Advertisement
Indie_Rogers

autoharvest

Jun 29th, 2022 (edited)
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. blockCount = 0
  2. SLOT_COUNT = 16
  3.  
  4. function modemCheck()
  5. local isBlock, data = turtle.inspectUp()
  6. if (data["state"]["peripheral"] == true) then
  7. return true
  8. else
  9. return false
  10. end
  11. end
  12. if modemCheck() then
  13. rednet.open("top")
  14. end
  15. function getItemIndex(itemName)
  16. for slot = 1, SLOT_COUNT, 1 do
  17. local item = turtle.getItemDetail(slot)
  18. if (item ~= nil) then
  19. if(item["name"] ==itemName) then
  20. return slot
  21. end
  22. end
  23. end
  24. end
  25.  
  26. function grab()
  27. for i = 1, 6, 1 do
  28. turtle.suck()
  29. end
  30. end
  31.  
  32.  
  33. function fuelCheck()
  34. local coalIndex = getItemIndex("minecraft:coal")
  35. if turtle.getFuelLevel() < 100 then
  36. if coalIndex ~= nil then
  37. turtle.select(coalIndex)
  38. turtle.refuel()
  39. else
  40. return false
  41. end
  42. end
  43. end
  44. function growCheck()
  45. local isBlock, data = turtle.inspect()
  46. while true do
  47. if (data["state"]["age"] == 7) then
  48. return true
  49. else
  50. return false
  51. end
  52. end
  53. end
  54.  
  55. function boundaryDetect()
  56. local isBlock, data = turtle.inspectDown()
  57. while true do
  58. if isBlock then
  59. if data["tags"]["minecraft:planks"] then
  60. return true
  61. else
  62. return false
  63. end
  64. else
  65. return false
  66. end
  67. end
  68. end
  69.  
  70. function selectNext()
  71. local wheatSeedIndex = getItemIndex("minecraft:wheat_seeds")
  72. local coalIndex = getItemIndex("minecraft:coal")
  73. fuelCheck()
  74. turtle.turnRight()
  75. turtle.forward()
  76. blockCount = blockCount + 1
  77. turtle.turnLeft()
  78. if boundaryDetect() then
  79. if fuelCheck() == false then
  80. turtle.suckUp()
  81. fuelCheck()
  82. end
  83. startOver()
  84. end
  85. end
  86.  
  87.  
  88. function harvest()
  89. while true do
  90. local wheatSeedIndex = getItemIndex("minecraft:wheat_seeds")
  91. local boneMealIndex = getItemIndex("minecraft:bone_meal")
  92. if turtle.inspect() == false then
  93. turtle.select(wheatSeedIndex)
  94. turtle.place()
  95. if boneMealIndex ~= nil then
  96. turtle.select(boneMealIndex)
  97. repeat
  98. turtle.place()
  99. until growCheck() or boneMealIndex == nil
  100. end
  101. selectNext()
  102. elseif (growCheck()) then
  103. turtle.dig()
  104. grab()
  105. turtle.select(wheatSeedIndex)
  106. turtle.place()
  107. selectNext()
  108. elseif boneMealIndex ~= nil then
  109. turtle.select(boneMealIndex)
  110. repeat
  111. turtle.place()
  112. until growCheck() or boneMealIndex == nil
  113. else
  114. selectNext()
  115. end
  116. end
  117. end
  118.  
  119.  
  120. function startOver()
  121. local wheatIndex = getItemIndex("minecraft:wheat")
  122. turtle.turnLeft()
  123. for i = 1, blockCount, 1 do
  124. turtle.forward()
  125. fuelCheck()
  126. end
  127. if wheatIndex ~= nil then
  128. while true do
  129. turtle.select(wheatIndex)
  130. turtle.drop(turtle.getItemCount(wheatIndex))
  131. if turtle.getItemCount(wheatIndex) == 0 then
  132. break
  133. end
  134. end
  135. end
  136. turtle.turnRight()
  137. blockCount = 0
  138. end
  139.  
  140. while true do
  141. local senderId, message, protocol = rednet.receive()
  142. if protocol == "harvest" then
  143. harvest()
  144. end
  145. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement