recipe nbts + item get/add helper

This commit is contained in:
kepler155c@gmail.com
2019-01-04 00:29:03 -05:00
parent d0a7a6e488
commit 6606975f5b
7 changed files with 62 additions and 41 deletions

View File

@@ -51,7 +51,26 @@ function itemDB:splitKey(key, item)
return item
end
function itemDB:get(key)
function itemDB:get(key, populateFn)
if not key then error('itemDB:get: key is required', 2) end
if type(key) == 'string' then
key = self:splitKey(key)
else
key = Util.shallowCopy(key)
end
local item = self:_get(key)
if not item and populateFn then
item = populateFn()
if item then
item = self:add(item)
end
end
return item and Util.merge(key, item)
end
function itemDB:_get(key)
if not key then error('itemDB:get: key is required', 2) end
if type(key) == 'string' then
key = self:splitKey(key)