DYankee

Potato Harvest

Jun 24th, 2021 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. chests = {
  2. "quark:oak_chest",
  3. "charm:oak_chest",
  4. }
  5. fuel = {
  6. "minecraft:coal_block",
  7. "actuallyadditions:block_misc",
  8. "quark:charcoal_block",
  9. }
  10.  
  11. function checkAge()
  12. isBlock, data = turtle.inspect()
  13. if (data['state']['age'] == 7)
  14. then
  15. isgrown = true
  16. elseif (data['state']['age'] ~= 7)
  17. then
  18. isgrown = false
  19. end
  20. end
  21.  
  22. function waitForGrowth()
  23. checkAge()
  24. while isgrown == false do
  25. sleep(20)
  26. checkAge()
  27. end
  28. end
  29.  
  30. function getFuelIndex()
  31. for slotNum = 1, 16, 1 do
  32. local Item = turtle.getItemDetail(slotNum)
  33. if(Item ~=nil) then
  34. for fuelIndex =1, #fuel, 1 do
  35. if(Item.name == fuel[fuelIndex]) then
  36. return slotNum
  37. end
  38. end
  39. end
  40. end
  41. end
  42.  
  43. function refuel()
  44. if(turtle.getFuelLevel() < 400) then
  45. local Index = getFuelIndex()
  46. if(Index ~= nil) then
  47. turtle.select(Index)
  48. turtle.refuel(2)
  49. end
  50. end
  51. end
  52.  
  53. function getPotatoIndex()
  54. for slotNum = 1, 16, 1 do
  55. local item = turtle.getItemDetail(slotNum)
  56. if(item ~=nil) then
  57. if(item["name"] == "minecraft:potato") then
  58. return slotNum
  59. end
  60. end
  61. end
  62. end
  63.  
  64. function harvest()
  65. checkAge()
  66. if isgrown == true then
  67. turtle.dig()
  68. turtle.suck()
  69. local index = getPotatoIndex()
  70. turtle.select(index)
  71. turtle.place()
  72. local potatoNum = turtle.getItemCount()
  73. turtle.dropDown(potatoNum - 1)
  74. goLeft()
  75. elseif isgrown == false then
  76. goLeft()
  77. end
  78. end
  79.  
  80. function goLeft()
  81. turtle.turnLeft()
  82. local isBlock = turtle.detect()
  83. if isBlock == true then
  84. state, tags = turtle.inspect()
  85. for chestIndex = 1, #chests, 1 do
  86. if(tags.name == chests[chestIndex]) then
  87. refuel()
  88. getFuelIndex()
  89. local coalBlocks = turtle.getItemCount()
  90. if coalBlocks <= 4 then
  91. turtle.suck(30)
  92. turtle.suck(30)
  93. turtle.turnLeft()
  94. waitForGrowth()
  95. elseif coalBlocks > 4 then
  96. turtle.turnLeft()
  97. waitForGrowth()
  98. harvest()
  99. end
  100. elseif (tags.name ~= chests[chestIndex]) == false then
  101. turtle.forward()
  102. turtle.turnRight()
  103. end
  104. end
  105. elseif isBlock ~= true then
  106. turtle.forward()
  107. turtle.turnRight()
  108. end
  109. end
  110.  
  111.  
  112. while true do
  113. harvest()
  114. end
Add Comment
Please, Sign In to add comment