Handle nil-valued item details in cache update
This commit is contained in:
parent
c5034f8964
commit
8db324647d
32
items.lua
32
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user