Blackhome

PaleOakFarmer

Nov 16th, 2025 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.72 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.     while (not (sucUp and itemUp.name == "minecraft:pale_oak_leaves")) and cnt < 13 do
  323.         if sucFor and isLog(itemFor) then
  324.             turtle.dig()
  325.         end
  326.         forceMoveUp()
  327.         sucUp, itemUp = turtle.inspectUp()
  328.         sucFor, itemFor = turtle.inspect()
  329.         cnt = cnt + 1
  330.     end
  331.    
  332.     if (not (sucFor and itemFor.name == "minecraft:pale_oak_leaves") and cnt < 13) then
  333.         topTurnDir = "right"
  334.         forceMoveForward()
  335.         sucUp, itemUp = turtle.inspectUp()
  336.         while (not (sucUp and itemUp.name == "minecraft:pale_oak_leaves")) and cnt < 13 do
  337.             forceMoveUp()
  338.             sucUp, itemUp = turtle.inspectUp()
  339.             cnt = cnt + 1
  340.         end
  341.     end
  342.     return topTurnDir
  343. end
  344.  
  345. local function fellAtPos(startFellPos)
  346.     goToPos(startFellPos)
  347.     turnInDirection(getTurnDirection(direction, startDir))
  348.  
  349.     local cnt = turtlePos.y - startFellPos.y
  350.     local topTurnDir = fellTillLeaves_GetTurnDir(cnt)
  351.     cnt = turtlePos.y - startFellPos.y
  352.  
  353.     turnInDirection("right")
  354.     forceMoveForward()
  355.     turnInDirection(topTurnDir)
  356.  
  357.     topTurnDir = fellTillLeaves_GetTurnDir(cnt)
  358.    
  359.     if topTurnDir == "right" then
  360.         turnInDirection("around")
  361.     end
  362.  
  363.     while turtlePos.y > startFellPos.y do
  364.         local sucFor, itemFor = turtle.inspect()
  365.         if sucFor and isLog(itemFor) then
  366.             turtle.dig()
  367.         end
  368.         forceMoveDown()
  369.     end
  370.     sucFor, itemFor = turtle.inspect()
  371.     if sucFor and isLog(itemFor) then
  372.         turtle.dig()
  373.     end
  374. end
  375.  
  376. local function fellTree()
  377.     local forwDir = startDir
  378.     turnInDirection("left")
  379.     local leftDir = direction
  380.  
  381.     local diffRight = negative(multiply(2, leftDir))
  382.     local diffFor = multiply(2, forwDir)
  383.  
  384.     local startFellPos1 = add(negative(forwDir),add(turtlePos, multiply(2, leftDir)))
  385.     local startFellPos2 = add(startFellPos1, diffRight)
  386.     local startFellPos3 = add(startFellPos2, diffRight)
  387.  
  388.     local startFellPos4 = add(startFellPos3, diffFor)
  389.     local startFellPos5 = add(startFellPos2, diffFor)
  390.     local startFellPos6 = add(startFellPos1, diffFor)
  391.  
  392.     local startFellPos7 = add(startFellPos6, diffFor)
  393.     local startFellPos8 = add(startFellPos5, diffFor)
  394.     local startFellPos9 = add(startFellPos4, diffFor)
  395.  
  396.     fellAtPos(startFellPos1)
  397.     fellAtPos(startFellPos2)
  398.     fellAtPos(startFellPos3)
  399.     fellAtPos(startFellPos4)
  400.     fellAtPos(startFellPos5)
  401.     fellAtPos(startFellPos6)
  402.     fellAtPos(startFellPos7)
  403.     fellAtPos(startFellPos8)
  404.     fellAtPos(startFellPos9)
  405.  
  406.     goToStartOfTree()
  407.  
  408. end
  409.  
  410. -- === Inventory Management ===
  411.  
  412. local function compactInventory()
  413.     for i = 1, 16 do
  414.         local itemI = turtle.getItemDetail(i)
  415.         if itemI and itemI.count < 64 then
  416.             for j = i + 1, 16 do
  417.                 local itemJ = turtle.getItemDetail(j)
  418.                 if itemJ and itemJ.name == itemI.name then
  419.                     turtle.select(j)
  420.                     turtle.transferTo(i)
  421.                    
  422.                     -- Aktuellen Slot updaten
  423.                     itemI = turtle.getItemDetail(i)
  424.                     if not itemI or itemI.count == 64 then
  425.                         break
  426.                     end
  427.                 end
  428.             end
  429.         end
  430.     end
  431.     turtle.select(1) -- zum Standard zurückkehren
  432. end
  433.  
  434. -- Keep saplings
  435. local function dumpInventoryKeepSaplings(n)
  436.     local success, chest = turtle.inspect()
  437.     while not (success and chest.name == "minecraft:chest") do
  438.         print("No chest found. Pls place one in front.")
  439.         print("Press enter to continue.")
  440.         read()
  441.         success, chest = turtle.inspect()
  442.     end
  443.  
  444.     local saplingsKept = 0
  445.  
  446.     for slot = 1, 16 do
  447.         local item = turtle.getItemDetail(slot)
  448.         if item then
  449.             turtle.select(slot)
  450.             if isSapling(item) and saplingsKept < n then
  451.                 local keep = math.min(item.count, n - saplingsKept)
  452.                 local drop = item.count - keep
  453.                 if drop > 0 then
  454.                     turtle.drop(drop)
  455.                 end
  456.                 saplingsKept = saplingsKept + keep
  457.             elseif not isBoneMeal(item) then
  458.                 turtle.drop()
  459.             end
  460.         end
  461.     end
  462.  
  463.     turtle.select(1)
  464. end
  465.  
  466. local function turtleNeedsFuel()
  467.     local fuelLevel = turtle.getFuelLevel()
  468.  
  469.     if fuelLevel < 1000 then
  470.         if not isEqual(startPos, turtlePos) then
  471.             diffX = math.abs(startPos.x - turtlePos.x)
  472.             diffY = math.abs(startPos.y - turtlePos.y)
  473.             diffZ = math.abs(startPos.z - turtlePos.z)
  474.  
  475.             if not (fuelLevel < diffX + diffY + diffZ +5) then
  476.                 goToPos(startPos)
  477.             end
  478.         end
  479.         print("Turtle needs more fuel")
  480.         return true
  481.     end
  482.     return false
  483. end
  484.  
  485. -- gets specified item in given amount (min(available, requested)) from chest
  486. local function suckSpecificItem(itemName, count, strDir)
  487.     local chest = peripheral.wrap(strDir)
  488.     if not chest or not chest.list then
  489.         return false
  490.     end
  491.  
  492.     local chestItems = chest.list()
  493.     local foundSlots = {}
  494.     local totalAvailable = 0
  495.  
  496.     -- 1. Scanne Kiste nach dem gewünschten Item
  497.     for slot, item in pairs(chestItems) do
  498.         if item.name == itemName then
  499.             table.insert(foundSlots, {slot = slot, count = item.count})
  500.             totalAvailable = totalAvailable + item.count
  501.         end
  502.     end
  503.     count = math.min(totalAvailable, count)
  504.     if count == 0 then
  505.         return false
  506.     end
  507.  
  508.     -- 2. Finde freien Slot in der Turtle für gecachtes Item
  509.     local cachedItemSlot = nil
  510.     for i = 1, 16 do
  511.         if turtle.getItemCount(i) == 0 then
  512.             cachedItemSlot = i
  513.             break
  514.         end
  515.     end
  516.  
  517.     if not cachedItemSlot then
  518.         print("Kein freier Slot zum Zwischenspeichern des Kisten-Items.")
  519.         return false
  520.     end
  521.  
  522.     turtle.select(cachedItemSlot)
  523.     local cachedItem = nil
  524.  
  525.     local list = chest.list()
  526.     if list[1] and list[1].name ~= itemName then
  527.         if strDir == "front" then
  528.             if turtle.suck(64) then
  529.                 cachedItem = turtle.getItemDetail(cachedItemSlot)
  530.             end
  531.         elseif strDir == "top" then
  532.             if turtle.suckUp(64) then
  533.                 cachedItem = turtle.getItemDetail(cachedItemSlot)
  534.             end
  535.         elseif strDir == "bottom" then
  536.             if turtle.suckDown(64) then
  537.                 cachedItem = turtle.getItemDetail(cachedItemSlot)
  538.             end
  539.         end
  540.     end
  541.  
  542.     -- 3. Erstes gewünschtes Item in Slot 1 schieben
  543.     local nextSlotIndex = 1
  544.     if not chest.getItemDetail(1) then
  545.         local nextSource = foundSlots[nextSlotIndex]
  546.         chest.pushItems(strDir, nextSource.slot, nextSource.count, 1)
  547.         nextSlotIndex = nextSlotIndex + 1
  548.     elseif (chest.getItemDetail(1) and chest.getItemDetail(1).name == itemName) then
  549.         nextSlotIndex = nextSlotIndex + 1
  550.     end
  551.  
  552.     -- 4. Gecachtes Item zurückgeben
  553.     if cachedItem then
  554.         turtle.select(cachedItemSlot)
  555.         if strDir == "front" then
  556.             turtle.drop() -- Kiste verteilt es automatisch auf einen freien Slot ≠ 1
  557.         elseif strDir == "top" then
  558.             turtle.dropUp() -- Kiste verteilt es automatisch auf einen freien Slot ≠ 1
  559.         elseif strDir == "bottom" then
  560.             turtle.dropDown() -- Kiste verteilt es automatisch auf einen freien Slot ≠ 1
  561.         end
  562.     end
  563.  
  564.     -- 5. Zielitems absaugen
  565.     local collected = 0
  566.     turtle.select(cachedItemSlot) -- Wiederverwenden für Einsammeln
  567.     while collected < count do
  568.         local remaining = count - collected
  569.         local slot1Item = chest.getItemDetail(1)
  570.         local pullCount = math.min(slot1Item.count, remaining)
  571.        
  572.         if strDir == "front" then
  573.             if turtle.suck(pullCount) then
  574.                 collected = collected + pullCount
  575.             end
  576.         elseif strDir == "top" then
  577.             if turtle.suckUp(pullCount) then
  578.                 collected = collected + pullCount
  579.             end
  580.         elseif strDir == "bottom" then
  581.             if turtle.suckDown(pullCount) then
  582.                 collected = collected + pullCount
  583.             end
  584.         end
  585.  
  586.        
  587.  
  588.         if collected < count and nextSlotIndex <= #foundSlots then
  589.             local nextSource = foundSlots[nextSlotIndex]
  590.             chest.pushItems(strDir, nextSource.slot, nextSource.count, 1)
  591.             nextSlotIndex = nextSlotIndex + 1
  592.         end
  593.     end
  594.  
  595.     return true
  596. end
  597.  
  598.  
  599. local function processAndStockInventory()
  600.     goToPos(startPos)
  601.     turnInDirection(getTurnDirection(direction, negative(startDir)))
  602.     dumpInventoryKeepSaplings(64)
  603.     if getSaplingCount() < 8 then
  604.         suckSpecificItem("minecraft:pale_oak_sapling", 64 - getSaplingCount(), "bottom")
  605.         bFirst = true
  606.         while getSaplingCount() < 8 do
  607.             if bFirst then print("Waiting for new Saplings!") bFirst = false end
  608.             if not suckSpecificItem("minecraft:pale_oak_sapling", 64 - getSaplingCount(), "bottom") then sleep(5) end
  609.         end
  610.     end
  611.     if getBoneMealCount() < 64 then
  612.         suckSpecificItem("minecraft:bone_meal", 64 - getBoneMealCount(), "top")
  613.         bFirst = true
  614.         while getBoneMealCount() < 10 do
  615.             if bFirst then print("Waiting for new Bone Meal!") bFirst = false end
  616.             if not suckSpecificItem("minecraft:bone_meal", 64 - getBoneMealCount(), "top") then sleep(5) end
  617.         end
  618.     end
  619.     compactInventory()
  620.     goToStartOfTree()
  621. end
  622.  
  623.  
  624. -- === Initialization ===
  625.  
  626. local function destroyTreeBlocks()
  627.     local suc, item = turtle.inspect()
  628.     if not suc then
  629.         return
  630.     end
  631.  
  632.     local treeBlocks = {"minecraft:pale_oak_leaves", "minecraft:pale_oak_log", "minecraft:pale_hanging_moss"}
  633.  
  634.     cnt = 1
  635.     while cnt <= 3 do
  636.         if item.name == treeBlocks[cnt] then
  637.             turtle.dig()
  638.             return
  639.         end
  640.         cnt = cnt + 1
  641.     end
  642. end
  643.  
  644. local function saveStartingParameters()
  645.     local parameterList = {pos = turtlePos, dir = direction}
  646.  
  647.     local file = fs.open("paleOakStartingParameters.txt", "w")
  648.     file.write(textutils.serialize(parameterList))
  649.     file.close()
  650. end
  651.  
  652. local function loadStartingParameters()
  653.     if not fs.exists("paleOakStartingParameters.txt") then return false end
  654.  
  655.     local file = fs.open("paleOakStartingParameters.txt", "r")
  656.     local data = textutils.unserialize(file.readAll())
  657.  
  658.     file.close()
  659.  
  660.     startPos = data.pos
  661.     startDir = data.dir
  662.     return true
  663. end
  664.  
  665. local function initProgram()
  666.     turtlePos = getGPSPosition()
  667.     if not turtlePos then error("GPS failure, cannot run the program") end
  668.    
  669.     destroyTreeBlocks()
  670.     getDirection()
  671.  
  672.     if not loadStartingParameters() then
  673.         startPos = turtlePos
  674.         startDir = direction
  675.         saveStartingParameters()
  676.     end
  677. end
  678.  
  679.  
  680.  
  681. -- === Main ===
  682.  
  683. local function main()
  684.     bSaplingPlanted = true
  685.  
  686.     while turtle.getFuelLevel() < 5 do
  687.         print("Turtle needs more fuel")
  688.         return
  689.     end
  690.  
  691.     initProgram()
  692.     if turtleNeedsFuel() then return end
  693.  
  694.     if (getBoneMealCount() == 0) or (getSaplingCount() < 4) then
  695.         processAndStockInventory()
  696.     end
  697.  
  698.     goToStartOfTree()
  699.     plantAllSaplings()
  700.     while true do
  701.         if turtleNeedsFuel() then return end
  702.         if bSaplingPlanted then
  703.             suc, item = turtle.inspect()
  704.             if suc and isSapling(item) then
  705.                 if selectBoneMealSlot() then
  706.                     turtle.place()
  707.                 else
  708.                     processAndStockInventory()
  709.                 end
  710.             else
  711.                 if suc and isLog(item) then
  712.                     fellTree()
  713.                     bSaplingPlanted = false
  714.                 end
  715.  
  716.                 slotCount = turtle.getItemCount(16)
  717.                 if slotCount > 0 then
  718.                     processAndStockInventory()
  719.                 end
  720.             end
  721.         else
  722.             if not plantAllSaplings() then
  723.                 processAndStockInventory()
  724.                 if not plantAllSaplings() then
  725.                     fellTree()
  726.                     bSaplingPlanted = false
  727.                 end
  728.                 if not plantAllSaplings() then
  729.                     goToPos(startPos)
  730.                     print("Error: Saplings cannot be planted!")
  731.                     return
  732.                 end
  733.             end
  734.             bSaplingPlanted = true
  735.         end
  736.         if (getBoneMealCount() == 0) or (getSaplingCount() < 8) then
  737.             processAndStockInventory()
  738.         end
  739.     end
  740.  
  741.    
  742.  
  743. end
  744.  
  745. main()
Advertisement
Add Comment
Please, Sign In to add comment