Advertisement
Indie_Rogers

harvest

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