-------------------------- -- inventory management -- -------------------------- function checkInventory() checkTakenInventory() if (takenSlots == 16) then returnHome() dropoff() end end ------------------------- -- @return: -- takenSlots[int] -- takenSlotsArray[Array(int - ordered)] ------------------------- function checkTakenInventory() takenSlots = 0 takenSlotsArry = {} for i = 1, 16, 1 do turtle.select(i) if (turtle.getItemCount <= 1) then table.insert(takenSlotsArry, i) takenSlots = takenSlots + 1 end end return takenSlots, takenSlotsArry end ------------------------- -- @return: -- freeSlots[int] -- freeSlotsArray[Array(int - ordered)] ------------------------- function checkFreeInventory() freeSlots = 0 freeSlotsArry = {} for i = 1, 16, 1 do turtle.select(i) if (turtle.getItemCount == 0) then freeSlots = freeSlots + 1 table.insert(freeSlotsArry, i) end end return freeSlots, freeSlotsArry end function dropOff(dropOffLevel) if (dropOffLevel == 0) then dropOffAll(side, sides) elseif(dropOffLevel == 1) then dropOffLFA(side, sides) elseif(dropOffLevel == 2) then dropOffLSF(side, sides) else debugString = "Drop Off Level was invalid: level "..dropOffLevel debugLevel = 1 debugTerminal(debugString, debugLevel) end end function dropOffAll(side, sides, actionDelay) turtle.select(1) -- We assume there is something in slot 1 isDroppingOffInventory = true if not(turtle.drop(sides[side])) then debugString = "Unable to find deposit inventory" debugLevel = 1 debugOutput(debugString, debugLevel) else for i = 1, 16, 1 do turtle.select(i) while not(turtle.drop) do os.sleep(actionDelay) -- Inventory became full, wait for it to clear end turtle.drop(sides[side]) end turtle.select(1) end isDroppingOffInventory = false end function dropOffLFA(side, sides, actionDelay) -- A drop off that ignores fuels -- Start at slot 1 for everything turtle.select(1) isDroppingOffInventory = true if not(turtle.drop(sides[side])) then debugString = "Unable to find deposit inventory" debugLevel = 1 debugOutput(debugString, debugLevel) else for i = 1, 16, 1 do turtle.select(i) while not(turtle.drop(sides[side])) do os.sleep(actionDelay) end if not(turtle.refuel()) then turtle.drop(sides[side]) end end end -- Locate all of the fuel to the end of our inventory local t = 16 local T = 17 for i = 1, 16, 1 do turtle.select(T - i) if (turtle.getItemCount() ~= 0) then turtle.transferTo(t) t = t - 1 end end turtle.select(1) isDroppingOffInventory = false end function dropoffLSF(side, sides) -- drop of Items, leave 1 stack of fuel local leftFuel = false local fuelSlot = 1 turtle.select(1) -- We assume there is something in slot 1 isDroppingOffInventory = true if not(turtle.drop(sides[side])) then debugString = "Unable to find deposit inventory" debugLevel = 1 debugOutput(debugString, debugLevel) else for i = 1, 16, 1 do if ((turtle.refuel()) and not(leftFuel)) then leftFuel = true fuelSlot = i else turtle.drop(sides[side]) end end end if (fuelSlot ~= 16) then turtle.select(fuelSlot) turtle.transferTo(16) end turtle.select(1) isDroppingOffInventory = false end