Advertisement
DYankee

Wheat harvest

Oct 30th, 2021 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. chests = {
  2.     "quark:oak_chest",
  3.     "charm:oak_chest",
  4. }
  5.  
  6. fuel = {
  7.     "minecraft:coal_block",
  8.     "actuallyadditions:block_misc",
  9.     "quark:charcoal_block",
  10.     "thermal:charcoal_block",
  11. }
  12.  
  13. function checkAge()
  14.     local isBlock, data = turtle.inspect()
  15.     if (data['state']['age'] == 7)
  16.     then
  17.         isgrown = true
  18.     elseif (data['state']['age'] ~= 7)
  19.     then
  20.         isgrown = false
  21.     end
  22. end
  23.  
  24. function getFuelIndex()
  25.     for slotNum = 1, 16, 1 do
  26.         local Item = turtle.getItemDetail(slotNum)
  27.         if(Item ~=nil) then
  28.             for fuelIndex = 1, #fuel, 1 do
  29.                 if(Item.name == fuel[fuelIndex]) then
  30.                 return slotNum
  31.                 end
  32.             end
  33.         end
  34.     end
  35. end
  36.  
  37. function refuel()
  38.     fIndex = getFuelIndex()
  39.     fCount = turtle.getItemCount(fIndex)
  40.     while fCount == nil or fCount < 4 do
  41.         print("Out of Fuel1")
  42.         turtle.suckUp(30)
  43.         fIndex = getFuelIndex()
  44.         fCount = turtle.getItemCount(fIndex)
  45.             if fCount == nil or fCount < 4 then
  46.                 sleep(60)
  47.             end
  48.     end
  49.     if(turtle.getFuelLevel() < 400) then
  50.         fIndex = getFuelIndex()
  51.         if(fIndex ~= nil) then
  52.         turtle.select(fIndex)
  53.          turtle.refuel(2)
  54.         end
  55.     elseif fIndex == nil then
  56.         while fIndex == nil do
  57.             print("Out of fuel2")
  58.             refuel()
  59.         end
  60.     end
  61. end
  62.  
  63. function getSeedIndex()
  64.     for slotNum = 1, 16, 1 do
  65.         local item = turtle.getItemDetail(slotNum)
  66.         if(item ~=nil) then
  67.             if(item["name"] == "minecraft:wheat_seeds") then
  68.                 return slotNum
  69.             end
  70.         end
  71.     end
  72. end
  73.  
  74. function getWheatIndex()
  75.     for slotNum = 1, 16, 1 do
  76.         local item = turtle.getItemDetail(slotNum)
  77.         if(item ~=nil) then
  78.             if(item["name"] == "minecraft:wheat") then
  79.                 return slotNum
  80.             end
  81.         end
  82.     end
  83. end
  84.  
  85. function harvestRow()
  86.     RL = 6
  87.     checkAge()
  88.     while isgrown ~= true do
  89.         sleep(10)
  90.         checkAge()
  91.     end
  92.     if isgrown == true then
  93.         for CB = 1, RL -1, 1 do
  94.             checkAge()
  95.             if isgrown == true then
  96.                 turtle.dig()
  97.                 turtle.suck()
  98.                 turtle.suck()
  99.                 seedSlot = getSeedIndex()
  100.                 turtle.select(seedSlot)
  101.                 turtle.place()
  102.                 local seedNum = turtle.getItemCount()
  103.                 if seedNum > 4 then
  104.                     turtle.dropDown(seedNum - 1)
  105.                 end
  106.                 local wheatSlot = getWheatIndex()
  107.                 turtle.select(wheatSlot)
  108.                 turtle.dropDown(64)
  109.             end
  110.             turtle.turnLeft()
  111.             turtle.forward()
  112.             turtle.turnRight()
  113.         end
  114.         checkAge()
  115.         if isgrown == true then
  116.             turtle.dig()
  117.             turtle.suck()
  118.             turtle.suck()
  119.             seedSlot = getSeedIndex()
  120.             turtle.select(seedSlot)
  121.             turtle.place()
  122.             local seedNum = turtle.getItemCount()
  123.             turtle.dropDown(seedNum - 1)
  124.         end
  125.     end
  126. end
  127.  
  128. function harvest()
  129.     harvestRow()
  130.     turtle.turnLeft()
  131.     turtle.turnLeft()
  132.     harvestRow()
  133.     refuel()
  134.     turtle.turnLeft()
  135.     turtle.turnLeft()
  136. end
  137. while true do
  138.     harvest()
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement