Indie_Rogers

harvestDown

Jun 29th, 2022 (edited)
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. blockCount = 0
  2. SLOT_COUNT = 16
  3.  
  4. function getItemIndex(itemName)
  5.     for slot = 1, SLOT_COUNT, 1 do
  6.         local item = turtle.getItemDetail(slot)
  7.         if (item ~= nil) then
  8.             if(item["name"] ==itemName) then
  9.                 return slot
  10.             end
  11.         end
  12.     end
  13. end
  14.  
  15. function grab()
  16.     for i = 1, 6, 1 do
  17.         turtle.suckDown()
  18.     end
  19. end
  20.  
  21.  
  22. function fuelCheck()
  23.     local coalIndex = getItemIndex("minecraft:coal")
  24.     if turtle.getFuelLevel() < 100 then
  25.         if coalIndex ~= nil then
  26.             turtle.select(coalIndex)
  27.             turtle.refuel()
  28.         else
  29.             return false
  30.         end
  31.     end
  32. end
  33. function growCheck()
  34.     local isBlock, data = turtle.inspectDown()
  35.     while true do
  36.         if isBlock then
  37.             if (data["state"]["age"] == 7) then
  38.                 return true
  39.             else
  40.                 return false
  41.             end
  42.         end
  43.     end
  44. end
  45.  
  46. function plantDetect()
  47.     local isBlock, data = turtle.inspectDown()
  48.     wheatSeedIndex = getItemIndex("minecraft:wheat_seeds")
  49.     turtle.select(wheatSeedIndex)
  50.     if turtle.placeDown() == false then
  51.         if turtle.inspectDown() == false then
  52.             return true
  53.         else
  54.             return false
  55.         end
  56.     else
  57.         return true
  58.     end
  59. end
  60.  
  61. function selectNext()
  62.     local wheatSeedIndex = getItemIndex("minecraft:wheat_seeds")
  63.     local coalIndex = getItemIndex("minecraft:coal")
  64.     fuelCheck()
  65.     turtle.forward()
  66.     if plantDetect() then
  67.         if fuelCheck() == false then
  68.             turtle.suckUp()
  69.             fuelCheck()
  70.         end
  71.         turnAround()
  72.     end
  73. end
  74.  
  75.  
  76. function harvest()
  77.     while true do
  78.         local wheatSeedIndex = getItemIndex("minecraft:wheat_seeds")
  79.         local boneMealIndex = getItemIndex("minecraft:bone_meal")
  80.         if turtle.inspectDown() == false then
  81.             turtle.select(wheatSeedIndex)
  82.             turtle.placeDown()
  83.             if boneMealIndex ~= nil then
  84.                 turtle.select(boneMealIndex)
  85.                 repeat
  86.                     turtle.placeDown()
  87.                 until growCheck() or boneMealIndex == nil
  88.             end
  89.         elseif (growCheck()) then
  90.             turtle.digDown()
  91.             grab()
  92.             turtle.select(wheatSeedIndex)
  93.             turtle.placeDown()
  94.         end
  95.         if plantDetect() == false and growCheck() == false then
  96.             if boneMealIndex ~= nil then
  97.                 turtle.select(boneMealIndex)
  98.                 repeat
  99.                     turtle.placeDown()
  100.                 until growCheck() or boneMealIndex == nil
  101.             end
  102.         end
  103.     selectNext()
  104.     end
  105. end
  106.  
  107.  
  108. function turnAround()
  109.    turtle.turnLeft()
  110.    turtle.turnLeft()
  111. end
  112.  
  113. while true do
  114.     harvest()
  115. end
Add Comment
Please, Sign In to add comment