From 8db324647dffb3683b462c0d34f89ab84516289d Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Wed, 25 Sep 2024 10:35:53 +0000 Subject: [PATCH] Handle nil-valued item details in cache update --- items.lua | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) 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