diff --git a/items.lua b/items.lua index 8d69a73..31cb5dc 100644 --- a/items.lua +++ b/items.lua @@ -8,6 +8,18 @@ for _,v in ipairs(peripheral.getNames()) do end end +local function countPopulated(chest) + local count = 0 + local list = chest.list() + for _,_ in ipairs(list) do + count = count + 1 + end + for _,_ in pairs(list) do + count = count + 1 + end + return count +end + local function countNamed(tbl) local count = 0 for _,_ in pairs(tbl) do @@ -62,7 +74,7 @@ function Cache.makeCache(cacheLoader) print(percent:sub(1, math.min(#percent, 6))..("0"):rep(6 - #percent).."% ("..progress.."/"..count..")") local entry = nil - if #chest.list() == 0 and type(cacheLoader) == "function" then + if countPopulated(chest) == 0 and type(cacheLoader) == "function" then entry = cacheLoader(name, chest) end