diff options
author | ubq323 <ubq323@ubq323.website> | 2022-08-04 15:54:49 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2022-08-04 15:54:49 +0100 |
commit | 6891da43b38f5eaeeec2082186a76d0cff71474d (patch) | |
tree | ffd2a17e1bffc9a52b2ee009d88faf352c13e237 | |
parent | 89e83c9a3811bc2e0a39bb8fcda4dfe4715cf60e (diff) |
storage
-rw-r--r-- | storage.lua | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/storage.lua b/storage.lua index 97796c5..20fe3a4 100644 --- a/storage.lua +++ b/storage.lua @@ -8,17 +8,32 @@ local chest_types = { "minecraft:ironchest_iron", } -local chests = {} -for _,ty in ipairs(chest_types) do - -- don't want sides, only ones over a network - local tc = { peripheral.find(ty,function(n,p) return not sides[n] end) } - for _,chest in ipairs(tc) do - local name = peripheral.getName(chest) - chests[name] = { - content = chest.list(), - size = chest.size(), - pphl = chest, - } +local function scan() + + local chests = {} + for _,ty in ipairs(chest_types) do + -- don't want sides, only ones over a network + local tc = { peripheral.find(ty,function(n,p) return not sides[n] end) } + for _,chest in ipairs(tc) do + local name = peripheral.getName(chest) + chests[name] = { + content = chest.list(), + size = chest.size(), + pphl = chest, + } + end + end +end + +local function search(query) + local chests = scan() + for chname,chest in pairs(chests) do + for i=1,chest.size do + local it = chest.content[i] + if it and it.name:lower():find(query) then + print(it.name,"x"..it.count) + end + end end end -return chests + |