Allow field-based predicates for item searches
This commit is contained in:
parent
8db324647d
commit
a793a5c366
@ -63,6 +63,7 @@ function Cache.makeCache(cacheLoader)
|
||||
|
||||
local entry = nil
|
||||
if #chest.list() == 0 and type(cacheLoader) == "function" then
|
||||
print("Using cacheloader")
|
||||
entry = cacheLoader(name, chest)
|
||||
end
|
||||
|
||||
@ -174,6 +175,10 @@ function Cache:find(predicate)
|
||||
end
|
||||
|
||||
local function checkField(base, check)
|
||||
if type(base) == "function" then
|
||||
return base(check)
|
||||
end
|
||||
|
||||
local baseType = type(base)
|
||||
if baseType == nil then
|
||||
return true
|
||||
@ -198,10 +203,10 @@ end
|
||||
|
||||
function FILTER_MATCHING_SLOTS(target)
|
||||
return function(detail)
|
||||
return checkField(target.name, detail.name) and
|
||||
return target == nil or (checkField(target.name, detail.name) and
|
||||
checkField(target.displayName, detail.displayName) and
|
||||
checkField(target.damage, detail.damage) and
|
||||
checkField(target.enchantments, detail.enchantments)
|
||||
checkField(target.enchantments, detail.enchantments))
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user