diff --git a/items.lua b/items.lua index 4de49d8..19920aa 100644 --- a/items.lua +++ b/items.lua @@ -16,7 +16,13 @@ local function countNamed(tbl) return count end -local function cacheFromItemDetail(detail) +local function cacheFromItemDetail(detail, chest, slot) + if detail == nil then + return { + maxCount = chest.getItemLimit(slot) + } + end + return { name = detail.name, enchantments = detail.enchantments, @@ -28,23 +34,17 @@ local function cacheFromItemDetail(detail) } end +local function cacheFromSlot(chest, slot) + return cacheFromItemDetail(chest.getItemDetail(slot), chest, slot) +end + local function scanChest(chest) local entry = {} for slot=1,chest.size() do - local detail = chest.getItemDetail(slot) - if detail ~= nil then - table.insert( - entry, - cacheFromItemDetail(detail) - ) - else - table.insert( - entry, - { - maxCount = chest.getItemLimit(slot) - } - ) - end + table.insert( + entry, + cacheFromSlot(chest, slot) + ) end return entry end @@ -103,7 +103,7 @@ function Cache:reloadSlot(chestName, slot) return false end - chest[slot] = cacheFromItemDetail(store[chestName].getItemDetail(slot)) + chest[slot] = cacheFromSlot(store[chestName], slot) return true end