Inksaver

Turtle only kelp farm

Jan 27th, 2024 (edited)
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.65 KB | Source Code | 0 0
  1. local version = 20240209.0800
  2. --[[
  3.     https://pastebin.com/GLbfWEZr
  4.    
  5.     This script runs a turtle powered self-sustaining kelp farm.
  6.     The farm is 3 blocks deep and can be any size as long as the width/length dimensions are divisible by 2
  7.     Any corner can be used as a base with 2 smokers/hoppers and 2 separate chests/barrels for temporary and long-term storage
  8.     The turtle MUST be equipped with a diamond hoe NOT a pickaxe, otherwise it will break the farm!
  9. ]]
  10.  
  11.  
  12. local border = ""
  13.  
  14. local function clear()
  15.     term.clear()
  16.     term.setCursorPos(1,1)
  17. end
  18.  
  19. local function getBlockType(direction)
  20.     --[[ turtle.inspect() returns two values
  21.         1) boolean (true/false) success
  22.         2) table with two or more values:
  23.         .name
  24.         .state {axis = "y"}
  25.         .tags (["minecraft:logs"] = true, ["minecraft:logs_that_burn"] = true, ["minecraft:oak_logs"] = true}
  26.     ]]
  27.     local blockType = ""                    -- initialise blockType
  28.     local success = false
  29.     local data = nil                        -- initialise empty table variable
  30.     local inspect = turtle.inspect          -- assign inspect() function to a variable
  31.     if direction == "up" then
  32.         inspect = turtle.inspectUp          -- inspect re-assigned to inspectUp
  33.     elseif direction == "down" then
  34.         inspect = turtle.inspectDown        -- inspect re-assigned to inspectDown
  35.     end
  36.     success, data = inspect()               -- store information about the block below in a table
  37.     if success then                         -- block found
  38.         blockType = data.name               -- eg "minecraft:log"
  39.     end
  40.    
  41.     return blockType, data                  -- eg "minecraft:oak_log" , data table OR "", nil if empty
  42. end
  43.  
  44. local function values(t) -- general diy iterator
  45.     local i = 0
  46.     return function()
  47.         i = i + 1
  48.         return t[i]
  49.     end
  50. end
  51.  
  52. local function move(direction, steps, hoe)
  53.     local move = turtle.forward
  54.     local dig = turtle.dig
  55.     if direction == "up" then
  56.         move = turtle.up
  57.         dig = turtle.digUp
  58.     elseif direction == "down" then
  59.         move = turtle.down
  60.         dig = turtle.digDown
  61.     elseif direction == "back" then
  62.         move = turtle.back
  63.     end
  64.    
  65.     local moves = 0
  66.     for i = 1, steps do
  67.         if hoe then                         -- hoe = true so dig kelp
  68.             turtle.digDown()                -- dig down anyway
  69.             dig()
  70.         end
  71.         if move() then                      -- if move successful
  72.             moves = moves + 1
  73.         else
  74.             return false, moves             -- unable to move further
  75.         end
  76.     end
  77.     return true, moves
  78. end
  79.  
  80. local function down(steps, hoe)
  81.     steps = steps or 1                      -- if called without parameters, set default 1
  82.     hoe = hoe or false                      -- if called without parameters, set default false
  83.     return move("down", steps, hoe)
  84. end
  85.  
  86. local function up(steps, hoe)
  87.     steps = steps or 1
  88.     hoe = hoe or false
  89.     return move("up", steps, hoe)
  90. end
  91.  
  92. local function forward(steps, hoe)    
  93.     steps = steps or 1
  94.     hoe = hoe or false
  95.     return move("forward", steps, hoe)
  96. end
  97.  
  98. local function back(steps)
  99.     steps = steps or 1
  100.     hoe = hoe or false                      -- if called without parameters, set default false
  101.     return move("back", steps, hoe)
  102. end
  103.  
  104. local function turnLeft(steps)
  105.     steps = steps or 1
  106.     for i = 1, steps do
  107.         turtle.turnLeft()
  108.     end
  109.     return true
  110. end
  111.  
  112. local function turnRight(steps)
  113.     steps = steps or 1
  114.     for i = 1, steps do
  115.         turtle.turnRight()
  116.     end
  117.     return true
  118. end
  119.  
  120. local function isItemOfType(direction, itemTable)
  121.     -- check if item in front of turtle is a specific type
  122.     local success, data = false, nil
  123.     if direction == "up" then
  124.         success, data= turtle.inspectUp()
  125.     elseif direction == "down" then
  126.         success, data= turtle.inspectDown()
  127.     else
  128.         success, data= turtle.inspect()                 -- check if anything in front
  129.     end
  130.     if success then                                     -- a block is in front
  131.         if type(itemTable) == "table" then              -- Are we checking for multiple items eg {"chest", "barrel"} ?
  132.             for _, item in ipairs(itemTable) do         -- iterate items
  133.                 if data.name:find(item) ~= nil then     -- match found
  134.                     return true
  135.                 end
  136.             end
  137.         elseif type(itemTable) == "string" then         -- checking for single item
  138.             if data.name:find(itemTable) ~= nil then    -- match found
  139.                 return true
  140.             end
  141.         end
  142.     end
  143.     return false                                        -- no match
  144. end
  145.  
  146. local function turnToStorage()
  147.     local turns = 0
  148.     while not isItemOfType("forward", {"chest", "barrel"}) do   -- look for chest or barrel
  149.         turnRight(1)
  150.         turns = turns + 1
  151.         if turns == 4 then                                      -- prevent infinite loop if no barrel/chest
  152.             return false
  153.         end
  154.     end
  155.     return true
  156. end
  157.  
  158. local function turnToSmelter(number)
  159.     number = number or 1
  160.     local turns = 0
  161.     if isItemOfType("forward", {"smoker", "furnace"}) then          -- smoker/furnace in front
  162.         turnLeft(1)
  163.         if isItemOfType("forward", {"smoker", "furnace"}) then      -- smoker/furnace in front
  164.             if number == 1 then
  165.                 return true
  166.             else
  167.                 turnRight(1)
  168.                 return true
  169.             end
  170.         else
  171.             turnRight(1)
  172.             if number == 1 then
  173.                 return true
  174.             else
  175.                 turnRight(1)
  176.                 return true
  177.             end
  178.         end
  179.     else
  180.         repeat
  181.             turnLeft(1)
  182.             turns = turns + 1
  183.             if turns == 4 then
  184.                 return false
  185.             end
  186.         until isItemOfType("forward", {"smoker", "furnace"})        -- look for smoker or furnace
  187.         if number == 2 then
  188.             return true
  189.         else
  190.             turnLeft(1)
  191.             if isItemOfType("forward", {"smoker", "furnace"}) then
  192.                 return true
  193.             end
  194.         end
  195.         return true
  196.     end
  197. end
  198.  
  199. local function go(path)
  200.     local commandList = {}
  201.     local command = ""
  202.     local direction = {"up", "forward", "down"}
  203.    
  204.     path = path:gsub(" ", "")   -- remove spaces from path
  205.     -- make a list of commands from path string eg "x0F12U1" = x0, F12, U1
  206.     for i = 1, #path do
  207.         local character = path:sub(i, i)            -- examine each character in the string
  208.         if tonumber(character) == nil then          -- char is NOT a number
  209.             if command ~= "" then                   -- command is NOT empty eg "x0"
  210.                 table.insert(commandList, command)  -- add to table eg "x0"
  211.             end
  212.             command = character:upper()             -- replace command with new character eg "F"
  213.         else                                        -- char IS a number
  214.             command = command..character:upper()    -- add eg 1 to F = F1, 2 to F1 = F12
  215.             if i == #path then                      -- last character in the string
  216.                 table.insert(commandList, command)
  217.             end
  218.         end
  219.     end
  220.     -- R# L# F# B# U# D# +0 -0 d0 = Right, Left, Forward, Back, Up, Down, up while detect and return, down while not detect, down and place while not detect
  221.     -- dig:           x0,x1,x2 (up/fwd/down)
  222.     for cmd in values(commandList) do -- eg F12 or x1
  223.         local move = (cmd:sub(1, 1)):upper()
  224.         local modifier = tonumber(cmd:sub(2))
  225.  
  226.         if move == "B" then
  227.             back(modifier)
  228.         elseif move == "D" then
  229.             down(modifier)
  230.         elseif move == "F" then
  231.             forward(modifier)
  232.         elseif move == "U" then
  233.             up(modifier)
  234.         elseif move == "R" then
  235.             turnRight(modifier)
  236.         elseif move == "L" then
  237.             turnLeft(modifier)
  238.         elseif move == "X" then
  239.             if modifier == 0 then
  240.                 turtle.digUp()
  241.             elseif modifier == 1 then
  242.                 turtle.dig()
  243.             elseif modifier == 2 then
  244.                 turtle.digDown()
  245.             end
  246.         end
  247.     end
  248. end
  249.  
  250. local function addToStorage()
  251.     -- assume starting facing storage
  252.     for i = 1, 16 do
  253.         if turtle.getItemCount(i) > 0 then                      -- slot is not empty
  254.             turtle.select(i)                                    -- select slot
  255.             local data = turtle.getItemDetail(i)                -- get data of slot contents
  256.             if data.name:find("block") ~= nil then              -- block of dried kelp found
  257.                 turtle.drop()                                   -- drop into general storage
  258.             elseif data.name == "minecraft:dried_kelp" then     -- loose dried kelp somehow left behind
  259.                 turtle.dropDown()                               -- back into smelter output store
  260.             else
  261.                 turtle.dropUp()                                 -- random block found during harvesting so dump it
  262.             end
  263.         end
  264.     end
  265.     turnToSmelter(1)
  266. end
  267.  
  268. local function craftKelp()
  269.     local sourceSlots = {4,8,12,13,14,15,16}
  270.     local craftSlots = {1,2,3,5,6,7,9,10,11}
  271.     local quantity = 0
  272.    
  273.     local lib = {}
  274.    
  275.     function lib.getSourceCount()
  276.         for _, sourceSlot in ipairs(sourceSlots) do
  277.             local count = turtle.getItemCount(sourceSlot)
  278.             if count > 0 then
  279.                 turtle.select(sourceSlot)
  280.                 return sourceSlot, count
  281.             end
  282.         end
  283.     end
  284.    
  285.     for _, slot in ipairs(sourceSlots) do
  286.         turtle.select(slot)                                 -- select a slot out of crafting area
  287.         turtle.suckDown()                                   -- remove items from chest below (dried kelp)
  288.         quantity = quantity + turtle.getItemCount(slot)
  289.     end
  290.    
  291.     print(quantity.. " dried kelp found")
  292.     if quantity >= 9 then                                   -- need min 9 to craft
  293.         local amount = math.floor(quantity / 9)             -- calculate how many to put in each of 9 slots
  294.         for _, craftSlot in ipairs(craftSlots) do
  295.             local sourceSlot, available = lib.getSourceCount()
  296.             if available >= amount then
  297.                 turtle.select(sourceSlot)
  298.                 turtle.transferTo(craftSlot, amount)        -- fill slots with same amount each
  299.             else
  300.                 turtle.select(sourceSlot)
  301.                 turtle.transferTo(craftSlot, available)     -- fill slots with same amount each
  302.                 local moved = available
  303.                 sourceSlot, available = lib.getSourceCount()
  304.                 turtle.select(sourceSlot)
  305.                 turtle.transferTo(craftSlot, amount - moved)
  306.             end
  307.         end
  308.         for _, slot in ipairs(sourceSlots) do
  309.             if turtle.getItemCount(slot) > 0 then
  310.                 turtle.select(slot)    
  311.                 turtle.dropDown()                           -- drop remaining back into chest
  312.             end
  313.         end
  314.         turtle.select(1)                                    -- put crafted items in slot 1
  315.         amount = 0
  316.         if turtle.craft() then
  317.             for i = 1, 16 do
  318.                 amount = amount + turtle.getItemCount(i)
  319.             end
  320.             return amount
  321.         end
  322.     else
  323.         for i = 1, 16 do
  324.             if turtle.getItemCount(slot) > 0 then
  325.                 turtle.select(slot)    
  326.                 turtle.dropDown()
  327.             end
  328.         end -- drop remaining back into chest
  329.     end
  330.     turtle.select(1)
  331.     return 0
  332. end
  333.  
  334. local function dropKelp()
  335.     local lib = {}
  336.    
  337.     function lib.drop(half)
  338.         for i = 1, 16 do   
  339.             if turtle.getItemCount(i) > 0 then
  340.                 turtle.select(i)
  341.                 local data = turtle.getItemDetail(i)            -- get data of slot contents
  342.                 if data.name == "minecraft:kelp" then           -- kelp found
  343.                     if half == -1 then
  344.                         turtle.drop()
  345.                     else
  346.                         if half > 64 then
  347.                             turtle.drop()
  348.                             half = half - 64
  349.                         else
  350.                             turtle.drop(half)
  351.                             half = 0
  352.                         end
  353.                     end
  354.                 end
  355.                 if half == 0 then break end
  356.             end
  357.         end
  358.     end
  359.    
  360.     -- assume starting in front of hopper
  361.     local kelp = 0
  362.     if getBlockType("forward") == "minecraft:hopper" then       -- make sure in front of hopper
  363.         local count = 0
  364.         for i = 1, 16 do                                        -- iterate all slots
  365.             count = count + turtle.getItemCount(i)
  366.             kelp = count
  367.         end
  368.         if count > 0 then                                       -- slot has contents
  369.             local half = math.ceil(count / 2)
  370.             lib.drop(half)
  371.             turnLeft(1)
  372.             lib.drop(-1)
  373.         end
  374.         go("U1F1R1F1R1D2")
  375.     else
  376.         go("U1F1R1B1D2")
  377.     end
  378.     return kelp                                                 -- return total kelp found
  379. end
  380.  
  381. local function refuel(kelp)
  382.     -- assume facing 1st smelter. kelp is amount of kelp dropped into the hoppers
  383.     -- 1 kelp block smelts 20 kelp could be >200 kelp dropped
  384.     -- kelp will be nil if called at start of home run from emptyTurtle()
  385.     turnToSmelter(1)
  386.     turtle.select(1)
  387.     turtle.suck()                                       -- remove any fuel from fuel store into slot 1
  388.     turnToSmelter(2)
  389.     turtle.suck()
  390.     if turtle.getFuelLevel() < 200 then                 -- check turtle fuel level
  391.         turtle.refuel(2)                                -- refuel with 2 kelp blocks (400 moves)
  392.     end
  393.     if kelp ~= nil then
  394.         kelp = math.ceil(kelp / 40)                     -- calculate amount of fuel required per smelter. re-purpose kelp variable
  395.         turnToSmelter(1)
  396.         turtle.drop(kelp)                               -- drop fuel into smelter. estimated max 9 blocks
  397.         turnToSmelter(2)                                -- face 2nd smelter
  398.         turtle.drop(kelp)
  399.     end
  400.     turnToSmelter(1)
  401.     return true
  402. end
  403.  
  404. local function returnToHopper()
  405.     -- should be alongside a retaining wall
  406.     local lib = {}                                      -- local library
  407.    
  408.     function lib.isHopper()                             -- check if block in front is a hopper
  409.         local blockType = getBlockType("forward")
  410.         if blockType:find("hopper") ~= nil then
  411.             return true                                 -- hopper found
  412.         end
  413.         return false                                    -- hopper not found
  414.     end
  415.    
  416.     while not lib.isHopper() do                         -- move forward while hopper not found
  417.         forward(1, true)
  418.     end
  419.    
  420.     local kelp = dropKelp()                             -- drop kelp into hoppers, returns to face smelter 1
  421.     if craftKelp() > 0 then                             -- craft kelp blocks
  422.         if turtle.getFuelLevel() < 200 then                 -- check turtle fuel level
  423.             turtle.refuel(2)                                -- refuel with 2 kelp blocks (400 moves)
  424.         end
  425.         if kelp ~= nil then
  426.             refuel(kelp)
  427.             kelp = nil
  428.             turnToStorage()
  429.         end
  430.         turtle.drop()                                   -- rotate to general storage and drop excess kelp blocks
  431.     end
  432.     addToStorage()                                      -- clear inventory and face farm
  433.     turnToSmelter(1)                                    -- facing smelter 1
  434. end
  435.  
  436. local function wait()
  437.     -- wait for furnace to go out before continuing
  438.     local time = 0
  439.     local waitTime = 5
  440.     local success, data = turtle.inspect()
  441.     if success then
  442.         while data.state.lit do
  443.             clear()
  444.             -- following code for display purposes only
  445.             local mins = math.floor(time / 60)
  446.             local secs = time % 60
  447.             local output = "Waiting for smelter to finish:\n"..time.." seconds ("..mins.." minute"
  448.             if mins ~= 1 then  output = output.."s" end
  449.             output = output..", "..secs.." second"
  450.             if secs ~= 1 then  output = output.."s" end
  451.             output = output..")"
  452.             print(output)
  453.             sleep(waitTime)
  454.             time = time + waitTime
  455.             success, data = turtle.inspect()
  456.         end
  457.         clear()
  458.     end
  459. end
  460.  
  461. local function farm()
  462.     local lib = {}                                  -- local library
  463.        
  464.     function lib.harvest()                          -- dig kelp below, right and left
  465.         turtle.dig()
  466.         turtle.digDown()
  467.         local success, moves = forward(1, true)     -- true if moved forward
  468.         return success, moves                       -- false if against wall
  469.     end
  470.    
  471.     function lib.changeRow(direction)               -- move left/right, attempt 3 blocks forward
  472.         if direction == "left" then
  473.             turnLeft(1)
  474.         else
  475.             turnRight(1)
  476.         end
  477.         local success, moves = forward(1, true)     -- try to move 1 block against the wall
  478.         if success then                             -- moved 3 blocks
  479.             if direction == "left" then             -- turn to face farm for next harvest run
  480.                 turnLeft(1)
  481.             else
  482.                 turnRight(1)
  483.             end
  484.             return true
  485.         else                                        -- hit side wall, so turn 180 and prepare to head for home
  486.             if direction == "left" then
  487.                 turnLeft(2)
  488.             else
  489.                 turnRight(2)
  490.             end
  491.             return false
  492.         end
  493.     end
  494.    
  495.     wait()
  496.     turnToSmelter(2)                                -- facing smelter 2
  497.     wait()
  498.     turnToSmelter(1)                                -- facing smelter 1
  499.     go("U2F1 R1F1 L1X2D1")                          -- exit home and enter water
  500.     local outward = true                            -- set direction flag
  501.     while true do
  502.         while lib.harvest() do end                  -- harvests a whole row
  503.         if outward then
  504.             local success = lib.changeRow("right")
  505.             if not success then
  506.                 break
  507.             end
  508.         else
  509.             local success = lib.changeRow("left")
  510.             if not success then
  511.                 break
  512.             end
  513.         end
  514.         outward = not outward                       -- reverse direction
  515.     end
  516.     returnToHopper()                                -- returned to hopper
  517. end
  518.  
  519. local function emptyTurtle()
  520.     -- only used on startup
  521.     wait()                                              -- wait for smelter to finish
  522.     turtle.select(1)
  523.     turtle.suck()                                       -- remove existing furnace fuel
  524.     turnRight(1)                                        -- face 2nd smelter
  525.     wait()                                              -- wait for smelter to finish
  526.     turtle.suck()                                       -- remove existing furnace fuel
  527.     if turtle.getItemCount(1) > 0 and turtle.getFuelLevel() < 200 then                  -- check turtle fuel level
  528.         turtle.refuel(2)                                -- refuel with 2 kelp blocks (400 moves)
  529.     end
  530.     if turtle.getItemCount(1) > 0 then
  531.         turnToStorage()
  532.         turtle.drop()                                       -- drop any furnace fuel into storage
  533.         turnToSmelter(1)
  534.     else
  535.         turnToSmelter(1)
  536.     end
  537. end
  538.  
  539. local function isHome()
  540.     -- chest or barrel below confirms home position
  541.     if isItemOfType("down", {"chest", "barrel"}) then
  542.         return "c"
  543.     else
  544.         local blockType = getBlockType("down")
  545.         if blockType == "" then                             -- air. must be above home
  546.             return "a"
  547.         elseif isItemOfType("down", {"water", "kelp"}) then -- in water farming
  548.             return "w"
  549.         elseif blockType == "minecraft:hopper" then         -- on top of hopper
  550.             return "h"
  551.         else
  552.             return ""                                       -- somehow got lost
  553.         end
  554.     end
  555. end
  556.  
  557. local function goHome(startOn)
  558.     -- a, w, h, b (air, water, hopper, border)
  559.     local lib = {}
  560.     function lib.addToMap(map)
  561.         blockType = getBlockType("down")
  562.         if blockType == "" then
  563.             map = map.."a"
  564.         elseif isItemOfType("down", {"water", "kelp"}) then
  565.             map = map.."w"
  566.         elseif blockType == "minecraft:hopper" then
  567.             map = map.."h"
  568.         else
  569.             map = map.."b"
  570.         end
  571.         return map
  572.     end
  573.    
  574.     function lib.makeMap()
  575.         local map = ""
  576.         forward(1)                      -- to north
  577.         map = lib.addToMap(map)
  578.         go("B1R1F1")                    -- to east
  579.         map = lib.addToMap(map)        
  580.         go("B1L1B1")                    -- to south
  581.         map = lib.addToMap(map)        
  582.         go("F1L1F1")                    -- to west
  583.         map = lib.addToMap(map)        
  584.         go("B1R1")                      -- to start position
  585.         return map
  586.     end
  587.    
  588.     function lib.aboveHopper()  -- already on a hopper
  589.         -- go into water then call returnToHopper()
  590.         local map = lib.makeMap()
  591.        
  592.         if map == "aabw" then
  593.             go("L1F1R1")
  594.         elseif map == "abwa" then
  595.             go("B1L1")
  596.         elseif map == "bwaa" then
  597.             go("R1F1R1")
  598.         elseif map == "waab" then
  599.             go("F1R1")
  600.         elseif map == "aawb" then
  601.             go("B1")
  602.         elseif map == "awba" then
  603.             go("L1B1")
  604.         elseif map == "wbaa" then
  605.             go("R2B1")
  606.         elseif map == "baaw" then
  607.             go("R1B1")
  608.         end
  609.         down(1, true)
  610.         returnToHopper()
  611.         return true
  612.     end
  613.    
  614.     function lib.findBorder()
  615.         repeat
  616.             turtle.dig()
  617.             turtle.digDown()
  618.             local success, moves = forward(1, true)     -- true if moved forward
  619.         until not success
  620.         if getBlockType("forward") == "minecraft:hopper" then
  621.             return true
  622.         else
  623.             turnRight(1)
  624.             return false
  625.         end
  626.     end
  627.    
  628.     function lib.findHopper()
  629.         -- turtle is on top of wall looking for hopper below
  630.         local blockType = getBlockType("down")
  631.         border = blockType
  632.         local blockCount = 0
  633.         while blockType == border do                    -- border has already been confirmed
  634.             forward(1)
  635.             blockCount = blockCount + 1
  636.             blockType = getBlockType("down")
  637.             if blockType:find("hopper") ~= nil then     -- hopper found
  638.                 return true, ""
  639.             end
  640.             if blockCount > 20 then                     -- prevents travel too far from farm
  641.                 return false, "max number of moves "..blockCount.." exceeded"
  642.             end
  643.         end
  644.         return false, ""                                -- hopper not found
  645.     end
  646.    
  647.     local blockType = ""
  648.     -- already checked if above chest/barrel
  649.     -- block in front can only be air, hopper, water/kelp, or border wall blocks
  650.     -- block below already known
  651.     if startOn == "h" then                      -- on hopper
  652.         lib.aboveHopper()                       -- go into water then returnToHopper()
  653.     elseif startOn == "w" then                  -- on or in water
  654.         up(1)
  655.         if isItemOfType("down", {"water", "kelp"}) then -- above water
  656.             down(1)                             -- go back into water
  657.         else                                    -- up too far: no water below
  658.             down(2)
  659.         end
  660.         while not lib.findBorder() do end       -- find nearest border and turn right until hit hopper
  661.         returnToHopper()                        -- same as end of harvest
  662.     else                                        -- starting on air can only be above home
  663.         down(2)                                 -- go down to chest
  664.     end
  665. end
  666.  
  667. local function checkStorageLevel()
  668.     local chest = peripheral.wrap("front")
  669.     local count = 0
  670.     for slot, item in pairs(chest.list()) do
  671.         count = count + item.count
  672.     end
  673.     return count, chest.size()
  674. end
  675.  
  676. local function main()
  677.     clear()                     -- clear terminal
  678.     local startOn = isHome()    -- c = home, else a, w, h, ""
  679.     if startOn == "" then
  680.         print("Unable to determine position\nMove to start and reboot")
  681.         return
  682.     elseif startOn ~= "c" then  -- check if starting in correct position
  683.         goHome(startOn)         -- find starting position
  684.     end
  685.     if not turnToStorage() then -- ensure storage is available
  686.         print("Unable to locate storage chest / barrel")
  687.         return
  688.     end
  689.     local count, size  = checkStorageLevel()
  690.     if count / 64 > size * 0.8 then
  691.         print("Storage at 80%. Farm disabled")
  692.         return
  693.     end
  694.     turnToSmelter(1)            -- facing smelter 1
  695.     emptyTurtle()               -- wait for furnaces to finish, refuel turtle if any spare fuel
  696.     while true do
  697.         farm()                  -- enter farming process (infinite loop)
  698.         turnToSmelter(1)        -- make sure facing smelter
  699.     end
  700. end
  701.  
  702. main()
Add Comment
Please, Sign In to add comment