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
|
return count
|
||||||
end
|
end
|
||||||
|
|
||||||
local function cacheFromItemDetail(detail)
|
local function cacheFromItemDetail(detail, chest, slot)
|
||||||
|
if detail == nil then
|
||||||
|
return {
|
||||||
|
maxCount = chest.getItemLimit(slot)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name = detail.name,
|
name = detail.name,
|
||||||
enchantments = detail.enchantments,
|
enchantments = detail.enchantments,
|
||||||
@ -28,23 +34,17 @@ local function cacheFromItemDetail(detail)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function cacheFromSlot(chest, slot)
|
||||||
|
return cacheFromItemDetail(chest.getItemDetail(slot), chest, slot)
|
||||||
|
end
|
||||||
|
|
||||||
local function scanChest(chest)
|
local function scanChest(chest)
|
||||||
local entry = {}
|
local entry = {}
|
||||||
for slot=1,chest.size() do
|
for slot=1,chest.size() do
|
||||||
local detail = chest.getItemDetail(slot)
|
table.insert(
|
||||||
if detail ~= nil then
|
entry,
|
||||||
table.insert(
|
cacheFromSlot(chest, slot)
|
||||||
entry,
|
)
|
||||||
cacheFromItemDetail(detail)
|
|
||||||
)
|
|
||||||
else
|
|
||||||
table.insert(
|
|
||||||
entry,
|
|
||||||
{
|
|
||||||
maxCount = chest.getItemLimit(slot)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return entry
|
return entry
|
||||||
end
|
end
|
||||||
@ -103,7 +103,7 @@ function Cache:reloadSlot(chestName, slot)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
chest[slot] = cacheFromItemDetail(store[chestName].getItemDetail(slot))
|
chest[slot] = cacheFromSlot(store[chestName], slot)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user