DYankee

Radish Harvest

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