DYankee

Carrot Harvest

Jun 23rd, 2021 (edited)
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.64 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 getCarrotIndex()
  54.     for slotNum = 1, 16, 1 do
  55.         local item = turtle.getItemDetail(slotNum)
  56.         if(item ~=nil) then
  57.             if(item["name"] == "minecraft:carrot") 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 = getCarrotIndex()
  70.         turtle.select(index)
  71.         turtle.place()
  72.         local carrotNum = turtle.getItemCount()
  73.         turtle.dropDown(carrotNum - 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.turnLeft()
  93.                     waitForGrowth()
  94.                 elseif coalBlocks > 4 then
  95.                     turtle.turnLeft()
  96.                     waitForGrowth()
  97.                     harvest()
  98.                 end
  99.             elseif (tags.name ~= chests[chestIndex]) == false then
  100.                 turtle.forward()
  101.                 turtle.turnRight()
  102.             end
  103.         end
  104.     elseif isBlock ~= true then
  105.         turtle.forward()
  106.         turtle.turnRight()
  107.     end
  108. end
  109.  
  110.  
  111. while true do
  112.     harvest()
  113. end
Add Comment
Please, Sign In to add comment