Blackhome

PaleOakFarmer

Nov 16th, 2025 (edited)
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.79 KB | Gaming | 0 0
  1. local turtlePos, direction
  2. local startPos, startDir
  3.  
  4. local function getGPSPosition()
  5.     local x, y, z = gps.locate()
  6.     if not x then print("Error: GPS not available") return nil end
  7.     return {x = math.floor(x), y = math.floor(y), z = math.floor(z)}
  8. end
  9.  
  10. local function negative(vec)
  11.     return {x = -vec.x, y = -vec.y, z = -vec.z}
  12. end
  13.  
  14. local function add(vec1, vec2)
  15.     return {x = vec1.x + vec2.x, y = vec1.y + vec2.y, z = vec1.z + vec2.z}
  16. end
  17. local function sub(vec1, vec2)
  18.     return add(vec1, negative(vec2))
  19. end
  20.  
  21. local function multiply(s, vec)
  22.     return {x = s * vec.x, y = s * vec.y, z = s * vec.z}
  23. end
  24.  
  25. local function getSign(number)
  26.     return number / math.abs(number)
  27. end
  28.  
  29. local function isEqual(vec1, vec2)
  30.     return vec1.x == vec2.x and vec1.y == vec2.y and vec1.z == vec2.z
  31. end
  32.  
  33.  
  34. -- === Basic Movement ===
  35.  
  36. local function moveForward()
  37.     if turtle.forward() then
  38.         turtlePos = add(turtlePos, direction)
  39.         return true
  40.     end
  41.     return false
  42. end
  43. local function moveUp()
  44.     if turtle.up() then
  45.         turtlePos.y = turtlePos.y + 1
  46.         return true
  47.     end
  48.     return false
  49. end
  50.  
  51. local function moveDown()
  52.     if turtle.down() then
  53.         turtlePos.y = turtlePos.y - 1
  54.         return true
  55.     end
  56.     return false
  57. end
  58.  
  59. local function forceMoveForward()
  60.     while not moveForward() do turtle.dig() end
  61. end
  62.  
  63. local function forceMoveUp()
  64.     while not moveUp() do turtle.digUp() end
  65. end
  66.  
  67. local function forceMoveDown()
  68.     while not moveDown() do turtle.digDown() end
  69. end
  70.  
  71. -- === Basic Turning ===
  72.  
  73. local function turnInDirection(dir)
  74.     if not direction then return end
  75.     if dir == "left" then
  76.         turtle.turnLeft()
  77.         direction = {x = direction.z, y = 0, z = -direction.x}
  78.     elseif dir == "right" then
  79.         turtle.turnRight()
  80.         direction = {x = -direction.z, y = 0, z = direction.x}
  81.     elseif dir == "around" then
  82.         turtle.turnLeft()
  83.         turtle.turnLeft()
  84.         direction = {x = -direction.x, y = 0, z = -direction.z}
  85.     end
  86. end
  87.  
  88. local function getTurnDirection(from, to)
  89.     local function vectorsEqual(a, b)
  90.         return a.x == b.x and a.z == b.z
  91.     end
  92.  
  93.     if vectorsEqual(from, to) then return nil end
  94.     local left  = {x = from.z, y = 0, z = -from.x}
  95.     local right = {x = -from.z, y = 0, z = from.x}
  96.     local back  = {x = -from.x, y = 0, z = -from.z}
  97.     if vectorsEqual(to, left) then
  98.         return "left"
  99.     elseif vectorsEqual(to, right) then
  100.         return "right"
  101.     elseif vectorsEqual(to, back) then
  102.         return "around"
  103.     else
  104.         error("Invalid target direction")
  105.     end
  106. end
  107.  
  108. local function getDirection()
  109.     local pos1 = getGPSPosition()
  110.     if not pos1 then error("GPS failure, cannot get direction") end
  111.  
  112.     for i = 1, 4 do
  113.         if turtle.forward() then
  114.             local pos2 = getGPSPosition()
  115.             if not pos2 then error("GPS failure after move") end
  116.             -- turtlePos = pos2
  117.             -- Richtung berechnen
  118.             direction = sub(pos2, pos1)
  119.  
  120.             -- zurück zur ursprünglichen Position
  121.             turnInDirection("around")
  122.             forceMoveForward()
  123.  
  124.             -- Sicherheitsprüfung
  125.             local posBack = getGPSPosition()
  126.             if not isEqual(pos1, posBack) then
  127.                 error("Warnung: Position hat sich beim Rückweg verschoben!")
  128.                 turtlePos = posBack -- explizit wieder auf GPS setzen
  129.             else
  130.                 turtlePos = pos1
  131.             end
  132.  
  133.             turnInDirection("around")
  134.             return
  135.         else
  136.             turtle.turnLeft()
  137.         end
  138.     end
  139.  
  140.     error("Unable to move forward in any direction for direction detection")
  141. end
  142.  
  143.  
  144. -- === Positioning ===
  145.  
  146. local function goToPos(coord)
  147.     local deltaX = coord.x - turtlePos.x
  148.     local deltaY = coord.y - turtlePos.y
  149.     local deltaZ = coord.z - turtlePos.z
  150.  
  151.     local dirX = startDir.x
  152.     local dirZ = startDir.z
  153.  
  154.     local function moveToEqualX()
  155.         while not (deltaX == 0) do
  156.             turnInDirection(getTurnDirection(direction, {x = getSign(deltaX), y = 0, z = 0}))
  157.             forceMoveForward()
  158.             deltaX = coord.x - turtlePos.x
  159.         end
  160.     end
  161.  
  162.     local function moveToEqualZ()
  163.         while not (deltaZ == 0) do
  164.             turnInDirection(getTurnDirection(direction, {x = 0, y = 0, z = getSign(deltaZ)}))
  165.             forceMoveForward()
  166.             deltaZ = coord.z - turtlePos.z
  167.         end
  168.     end
  169.  
  170.     local function moveToEqualY()
  171.         while not (deltaY == 0) do
  172.             if deltaY > 0 then
  173.                 forceMoveUp()
  174.             elseif deltaY < 0 then
  175.                 forceMoveDown()
  176.             end
  177.             deltaY = coord.y - turtlePos.y
  178.         end
  179.     end
  180.  
  181.    
  182.     if dirX == 0 then
  183.         moveToEqualZ()
  184.         moveToEqualX()
  185.     elseif dirZ == 0 then
  186.         moveToEqualX()
  187.         moveToEqualZ()
  188.     end
  189.  
  190.     if not (deltaY == 0) then
  191.         moveToEqualY()
  192.         deltaX = coord.x - turtlePos.x
  193.         deltaZ = coord.z - turtlePos.z
  194.     end
  195. end
  196.  
  197. ------------------------- Startpos adapten
  198. local function goToStartOfTree()
  199.     startTreePos = add(startPos, multiply(5, startDir))
  200.     goToPos(startTreePos)
  201.     turnInDirection(getTurnDirection(direction, startDir))
  202. end
  203.  
  204. -- === Tasks ===
  205.  
  206. local function isSapling(item)
  207.     if not item or not item.name then return false end
  208.  
  209.     local saplingSuffix = "pale_oak_sapling"
  210.     return item.name:match(":.*" .. saplingSuffix .. "$") ~= nil
  211. end
  212.  
  213. local function isBoneMeal(item)
  214.     if not item or not item.name then return false end
  215.     return item.name == "minecraft:bone_meal"
  216. end
  217.  
  218. local function isLog(item)
  219.     if not item or not item.name then return false end
  220.  
  221.     local logSuffix = "_log"
  222.     return item.name:match(":.*" .. logSuffix .. "$") ~= nil
  223. end
  224.  
  225. local function getBoneMealCount()
  226.     local num = 0
  227.     for i = 1, 16 do
  228.         local item = turtle.getItemDetail(i)
  229.        
  230.         if isBoneMeal(item) then
  231.             num = num + turtle.getItemCount(i)
  232.         end
  233.     end
  234.     return num
  235. end
  236. local function getSaplingCount()
  237.     local num = 0
  238.     for i = 1, 16 do
  239.         local item = turtle.getItemDetail(i)
  240.        
  241.         if isSapling(item) then
  242.             num = num + turtle.getItemCount(i)
  243.         end
  244.     end
  245.     return num
  246. end
  247.  
  248. local function selectSaplingSlot()
  249.     for i = 1, 16 do
  250.         local item = turtle.getItemDetail(i)
  251.        
  252.         if isSapling(item) then
  253.             turtle.select(i)
  254.             return true
  255.         end
  256.     end
  257.     return false
  258. end
  259.  
  260. local function selectBoneMealSlot()
  261.     for i = 1, 16 do
  262.         local item = turtle.getItemDetail(i)
  263.        
  264.         if isBoneMeal(item) then
  265.             turtle.select(i)
  266.             return true
  267.         end
  268.     end
  269.     return false
  270. end
  271.  
  272. local function plantSapling()
  273.     if not selectSaplingSlot() then return false end
  274.     if not turtle.place() then return false end
  275.     return true
  276. end
  277.  
  278. local function plantAllSaplings()
  279.     local function plantSaplingDown()
  280.         if not selectSaplingSlot() then return false end
  281.         if not turtle.placeDown() then
  282.             suc, item = turtle.inspectDown()
  283.             if suc and isSapling(item) then return true end
  284.             return false
  285.         end
  286.         return true
  287.     end
  288.     goToStartOfTree()
  289.     forceMoveUp()
  290.  
  291.     suc, item = turtle.inspect()
  292.     if suc and isLog(item) then
  293.         goToStartOfTree()
  294.         return false
  295.     end
  296.  
  297.     local returnValue = true
  298.  
  299.     forceMoveForward()
  300.     returnValue = returnValue and plantSaplingDown()
  301.     forceMoveForward()
  302.     returnValue = returnValue and plantSaplingDown()
  303.  
  304.     turnInDirection("right")
  305.     forceMoveForward()
  306.     turnInDirection("right")
  307.  
  308.     returnValue = returnValue and plantSaplingDown()
  309.     forceMoveForward()
  310.     returnValue = returnValue and plantSaplingDown()
  311.  
  312.     goToStartOfTree()
  313.     return returnValue
  314. end
  315.  
  316. local function fellTillLeaves_GetTurnDir(cnt)
  317.     local sucUp, itemUp = turtle.inspectUp()
  318.     local sucFor, itemFor = turtle.inspect()
  319.  
  320.     local topTurnDir = "left"
  321.  
  322.     local topPos = 12
  323.     --(not (sucUp and itemUp.name == "minecraft:pale_oak_leaves"))
  324.     while cnt < topPos do
  325.         if sucFor and isLog(itemFor) then
  326.             turtle.dig()
  327.         end
  328.         forceMoveUp()
  329.         sucUp, itemUp = turtle.inspectUp()
  330.         sucFor, itemFor = turtle.inspect()
  331.         cnt = cnt + 1
  332.     end
  333.    
  334.     if (not (sucFor and itemFor.name == "minecraft:pale_oak_leaves") and cnt < topPos) then
  335.         topTurnDir = "right"
  336.         forceMoveForward()
  337.         sucUp, itemUp = turtle.inspectUp()
  338.         while (not (sucUp and itemUp.name == "minecraft:pale_oak_leaves")) and cnt < topPos do
  339.             forceMoveUp()
  340.             sucUp, itemUp = turtle.inspectUp()
  341.             cnt = cnt + 1
  342.         end
  343.     end
  344.     return topTurnDir
  345. end
  346.  
  347. local function fellAtPos(startFellPos)
  348.     goToPos(startFellPos)
  349.     turnInDirection(getTurnDirection(direction, startDir))
  350.  
  351.     local cnt = turtlePos.y - startFellPos.y
  352.     local topTurnDir = fellTillLeaves_GetTurnDir(cnt)
  353.     cnt = turtlePos.y - startFellPos.y
  354.  
  355.     turnInDirection("right")
  356.     forceMoveForward()
  357.     turnInDirection(topTurnDir)
  358.  
  359.     topTurnDir = fellTillLeaves_GetTurnDir(cnt)
  360.    
  361.     if topTurnDir == "right" then
  362.         turnInDirection("around")
  363.     end
  364.  
  365.     while turtlePos.y > startFellPos.y do
  366.         local sucFor, itemFor = turtle.inspect()
  367.         if sucFor and isLog(itemFor) then
  368.             turtle.dig()
  369.         end
  370.         forceMoveDown()
  371.     end
  372.     sucFor, itemFor = turtle.inspect()
  373.     if sucFor and isLog(itemFor) then
  374.         turtle.dig()
  375.     end
  376. end
  377.  
  378. local function fellTree()
  379.     local forwDir = startDir
  380.     turnInDirection("left")
  381.     local leftDir = direction
  382.  
  383.     local diffRight = negative(multiply(2, leftDir))
  384.     local diffFor = multiply(2, forwDir)
  385.  
  386.     local startFellPos1 = add(negative(forwDir),add(turtlePos, multiply(2, leftDir)))
  387.     local startFellPos2 = add(startFellPos1, diffRight)
  388.     local startFellPos3 = add(startFellPos2, diffRight)
  389.  
  390.     local startFellPos4 = add(startFellPos3, diffFor)
  391.     local startFellPos5 = add(startFellPos2, diffFor)
  392.     local startFellPos6 = add(startFellPos1, diffFor)
  393.  
  394.     local startFellPos7 = add(startFellPos6, diffFor)
  395.     local startFellPos8 = add(startFellPos5, diffFor)
  396.     local startFellPos9 = add(startFellPos4, diffFor)
  397.  
  398.     fellAtPos(startFellPos1)
  399.     fellAtPos(startFellPos2)
  400.     fellAtPos(startFellPos3)
  401.     fellAtPos(startFellPos4)
  402.     fellAtPos(startFellPos5)
  403.     fellAtPos(startFellPos6)
  404.     fellAtPos(startFellPos7)
  405.     fellAtPos(startFellPos8)
  406.     fellAtPos(startFellPos9)
  407.  
  408.     goToStartOfTree()
  409.  
  410. end
  411.  
  412. -- === Inventory Management ===
  413.  
  414. local function compactInventory()
  415.     for i = 1, 16 do
  416.         local itemI = turtle.getItemDetail(i)
  417.         if itemI and itemI.count < 64 then
  418.             for j = i + 1, 16 do
  419.                 local itemJ = turtle.getItemDetail(j)
  420.                 if itemJ and itemJ.name == itemI.name then
  421.                     turtle.select(j)
  422.                     turtle.transferTo(i)
  423.                    
  424.                     -- Aktuellen Slot updaten
  425.                     itemI = turtle.getItemDetail(i)
  426.                     if not itemI or itemI.count == 64 then
  427.                         break
  428.                     end
  429.                 end
  430.             end
  431.         end
  432.     end
  433.     turtle.select(1) -- zum Standard zurückkehren
  434. end
  435.  
  436. -- Keep saplings
  437. local function dumpInventoryKeepSaplings(n)
  438.     local success, chest = turtle.inspect()
  439.     while not (success and chest.name == "minecraft:chest") do
  440.         print("No chest found. Pls place one in front.")
  441.         print("Press enter to continue.")
  442.         read()
  443.         success, chest = turtle.inspect()
  444.     end
  445.  
  446.     local saplingsKept = 0
  447.  
  448.     for slot = 1, 16 do
  449.         local item = turtle.getItemDetail(slot)
  450.         if item then
  451.             turtle.select(slot)
  452.             if isSapling(item) and saplingsKept < n then
  453.                 local keep = math.min(item.count, n - saplingsKept)
  454.                 local drop = item.count - keep
  455.                 if drop > 0 then
  456.                     turtle.drop(drop)
  457.                 end
  458.                 saplingsKept = saplingsKept + keep
  459.             elseif not isBoneMeal(item) then
  460.                 turtle.drop()
  461.             end
  462.         end
  463.     end
  464.  
  465.     turtle.select(1)
  466. end
  467.  
  468. local function turtleNeedsFuel()
  469.     local fuelLevel = turtle.getFuelLevel()
  470.  
  471.     if fuelLevel < 1000 then
  472.         if not isEqual(startPos, turtlePos) then
  473.             diffX = math.abs(startPos.x - turtlePos.x)
  474.             diffY = math.abs(startPos.y - turtlePos.y)
  475.             diffZ = math.abs(startPos.z - turtlePos.z)
  476.  
  477.             if not (fuelLevel < diffX + diffY + diffZ +5) then
  478.                 goToPos(startPos)
  479.             end
  480.         end
  481.         print("Turtle needs more fuel")
  482.         return true
  483.     end
  484.     return false
  485. end
  486.  
  487. -- gets specified item in given amount (min(available, requested)) from chest
  488. local function suckSpecificItem(itemName, count, strDir)
  489.     local chest = peripheral.wrap(strDir)
  490.     if not chest or not chest.list then
  491.         return false
  492.     end
  493.  
  494.     local chestItems = chest.list()
  495.     local foundSlots = {}
  496.     local totalAvailable = 0
  497.  
  498.     -- 1. Scanne Kiste nach dem gewünschten Item
  499.     for slot, item in pairs(chestItems) do
  500.         if item.name == itemName then
  501.             table.insert(foundSlots, {slot = slot, count = item.count})
  502.             totalAvailable = totalAvailable + item.count
  503.         end
  504.     end
  505.     count = math.min(totalAvailable, count)
  506.     if count == 0 then
  507.         return false
  508.     end
  509.  
  510.     -- 2. Finde freien Slot in der Turtle für gecachtes Item
  511.     local cachedItemSlot = nil
  512.     for i = 1, 16 do
  513.         if turtle.getItemCount(i) == 0 then
  514.             cachedItemSlot = i
  515.             break
  516.         end
  517.     end
  518.  
  519.     if not cachedItemSlot then
  520.         print("Kein freier Slot zum Zwischenspeichern des Kisten-Items.")
  521.         return false
  522.     end
  523.  
  524.     turtle.select(cachedItemSlot)
  525.     local cachedItem = nil
  526.  
  527.     local list = chest.list()
  528.     if list[1] and list[1].name ~= itemName then
  529.         if strDir == "front" then
  530.             if turtle.suck(64) then
  531.                 cachedItem = turtle.getItemDetail(cachedItemSlot)
  532.             end
  533.         elseif strDir == "top" then
  534.             if turtle.suckUp(64) then
  535.                 cachedItem = turtle.getItemDetail(cachedItemSlot)
  536.             end
  537.         elseif strDir == "bottom" then
  538.             if turtle.suckDown(64) then
  539.                 cachedItem = turtle.getItemDetail(cachedItemSlot)
  540.             end
  541.         end
  542.     end
  543.  
  544.     -- 3. Erstes gewünschtes Item in Slot 1 schieben
  545.     local nextSlotIndex = 1
  546.     if not chest.getItemDetail(1) then
  547.         local nextSource = foundSlots[nextSlotIndex]
  548.         chest.pushItems(strDir, nextSource.slot, nextSource.count, 1)
  549.         nextSlotIndex = nextSlotIndex + 1
  550.     elseif (chest.getItemDetail(1) and chest.getItemDetail(1).name == itemName) then
  551.         nextSlotIndex = nextSlotIndex + 1
  552.     end
  553.  
  554.     -- 4. Gecachtes Item zurückgeben
  555.     if cachedItem then
  556.         turtle.select(cachedItemSlot)
  557.         if strDir == "front" then
  558.             turtle.drop() -- Kiste verteilt es automatisch auf einen freien Slot ≠ 1
  559.         elseif strDir == "top" then
  560.             turtle.dropUp() -- Kiste verteilt es automatisch auf einen freien Slot ≠ 1
  561.         elseif strDir == "bottom" then
  562.             turtle.dropDown() -- Kiste verteilt es automatisch auf einen freien Slot ≠ 1
  563.         end
  564.     end
  565.  
  566.     -- 5. Zielitems absaugen
  567.     local collected = 0
  568.     turtle.select(cachedItemSlot) -- Wiederverwenden für Einsammeln
  569.     while collected < count do
  570.         local remaining = count - collected
  571.         local slot1Item = chest.getItemDetail(1)
  572.         local pullCount = math.min(slot1Item.count, remaining)
  573.        
  574.         if strDir == "front" then
  575.             if turtle.suck(pullCount) then
  576.                 collected = collected + pullCount
  577.             end
  578.         elseif strDir == "top" then
  579.             if turtle.suckUp(pullCount) then
  580.                 collected = collected + pullCount
  581.             end
  582.         elseif strDir == "bottom" then
  583.             if turtle.suckDown(pullCount) then
  584.                 collected = collected + pullCount
  585.             end
  586.         end
  587.  
  588.        
  589.  
  590.         if collected < count and nextSlotIndex <= #foundSlots then
  591.             local nextSource = foundSlots[nextSlotIndex]
  592.             chest.pushItems(strDir, nextSource.slot, nextSource.count, 1)
  593.             nextSlotIndex = nextSlotIndex + 1
  594.         end
  595.     end
  596.  
  597.     return true
  598. end
  599.  
  600.  
  601. local function processAndStockInventory()
  602.     goToPos(startPos)
  603.     turnInDirection(getTurnDirection(direction, negative(startDir)))
  604.     dumpInventoryKeepSaplings(64)
  605.     if getSaplingCount() < 8 then
  606.         suckSpecificItem("minecraft:pale_oak_sapling", 64 - getSaplingCount(), "bottom")
  607.         bFirst = true
  608.         while getSaplingCount() < 8 do
  609.             if bFirst then print("Waiting for new Saplings!") bFirst = false end
  610.             if not suckSpecificItem("minecraft:pale_oak_sapling", 64 - getSaplingCount(), "bottom") then sleep(5) end
  611.         end
  612.     end
  613.     if getBoneMealCount() < 64 then
  614.         suckSpecificItem("minecraft:bone_meal", 64 - getBoneMealCount(), "top")
  615.         bFirst = true
  616.         while getBoneMealCount() < 10 do
  617.             if bFirst then print("Waiting for new Bone Meal!") bFirst = false end
  618.             if not suckSpecificItem("minecraft:bone_meal", 64 - getBoneMealCount(), "top") then sleep(5) end
  619.         end
  620.     end
  621.     compactInventory()
  622.     goToStartOfTree()
  623. end
  624.  
  625.  
  626. -- === Initialization ===
  627.  
  628. local function destroyTreeBlocks()
  629.     local suc, item = turtle.inspect()
  630.     if not suc then
  631.         return
  632.     end
  633.  
  634.     local treeBlocks = {"minecraft:pale_oak_leaves", "minecraft:pale_oak_log", "minecraft:pale_hanging_moss"}
  635.  
  636.     cnt = 1
  637.     while cnt <= 3 do
  638.         if item.name == treeBlocks[cnt] then
  639.             turtle.dig()
  640.             return
  641.         end
  642.         cnt = cnt + 1
  643.     end
  644. end
  645.  
  646. local function saveStartingParameters()
  647.     local parameterList = {pos = turtlePos, dir = direction}
  648.  
  649.     local file = fs.open("paleOakStartingParameters.txt", "w")
  650.     file.write(textutils.serialize(parameterList))
  651.     file.close()
  652. end
  653.  
  654. local function loadStartingParameters()
  655.     if not fs.exists("paleOakStartingParameters.txt") then return false end
  656.  
  657.     local file = fs.open("paleOakStartingParameters.txt", "r")
  658.     local data = textutils.unserialize(file.readAll())
  659.  
  660.     file.close()
  661.  
  662.     startPos = data.pos
  663.     startDir = data.dir
  664.     return true
  665. end
  666.  
  667. local function initProgram()
  668.     turtlePos = getGPSPosition()
  669.     if not turtlePos then error("GPS failure, cannot run the program") end
  670.    
  671.     destroyTreeBlocks()
  672.     getDirection()
  673.  
  674.     if not loadStartingParameters() then
  675.         startPos = turtlePos
  676.         startDir = direction
  677.         saveStartingParameters()
  678.     end
  679. end
  680.  
  681.  
  682.  
  683. -- === Main ===
  684.  
  685. local function main()
  686.     bSaplingPlanted = true
  687.  
  688.     while turtle.getFuelLevel() < 5 do
  689.         print("Turtle needs more fuel")
  690.         return
  691.     end
  692.  
  693.     initProgram()
  694.     if turtleNeedsFuel() then return end
  695.  
  696.     if (getBoneMealCount() == 0) or (getSaplingCount() < 4) then
  697.         processAndStockInventory()
  698.     end
  699.  
  700.     goToStartOfTree()
  701.     plantAllSaplings()
  702.     while true do
  703.         if turtleNeedsFuel() then return end
  704.         if bSaplingPlanted then
  705.             suc, item = turtle.inspect()
  706.             if suc and isSapling(item) then
  707.                 if selectBoneMealSlot() then
  708.                     turtle.place()
  709.                 else
  710.                     processAndStockInventory()
  711.                 end
  712.             else
  713.                 if suc and isLog(item) then
  714.                     fellTree()
  715.                     bSaplingPlanted = false
  716.                 end
  717.  
  718.                 slotCount = turtle.getItemCount(16)
  719.                 if slotCount > 0 then
  720.                     processAndStockInventory()
  721.                 end
  722.             end
  723.         else
  724.             if not plantAllSaplings() then
  725.                 processAndStockInventory()
  726.                 if not plantAllSaplings() then
  727.                     fellTree()
  728.                     bSaplingPlanted = false
  729.                 end
  730.                 if not plantAllSaplings() then
  731.                     goToPos(startPos)
  732.                     print("Error: Saplings cannot be planted!")
  733.                     return
  734.                 end
  735.             end
  736.            
  737.             sleep(120)
  738.             bSaplingPlanted = true
  739.         end
  740.         if (getBoneMealCount() == 0) or (getSaplingCount() < 8) then
  741.             processAndStockInventory()
  742.         end
  743.     end
  744. end
  745.  
  746. main()
Advertisement
Add Comment
Please, Sign In to add comment