From a793a5c366e035bda7c6a023424db50d9c6edbce Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Wed, 25 Sep 2024 10:54:49 +0000 Subject: [PATCH] Allow field-based predicates for item searches --- items.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/items.lua b/items.lua index 19920aa..e8dfcf9 100644 --- a/items.lua +++ b/items.lua @@ -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