From 72c978ee751522cb9ecfd6365f6a4c9b8ae97590 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 22 Mar 2026 21:42:58 -0400 Subject: [PATCH] feat: add find_item functionality to locate items in chests --- inventoryManager.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/inventoryManager.lua b/inventoryManager.lua index 46aff86..725371b 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -705,6 +705,43 @@ local function main() state.bumpStateVersion() end pcall(broadcastState) + + elseif message.type == "find_item" and message.items then + -- Return chest+slot locations for the first matching item + -- message.items = list of item names to search (in priority order) + -- message.limit = max items to return info for (default 64) + local limit = message.limit or 64 + local results = {} + for _, itemName in ipairs(message.items) do + if cache.catalogue[itemName] then + for _, source in ipairs(cache.catalogue[itemName]) do + local chest = ops.wrapCached(source.chest) + if chest then + for slot, slotItem in pairs(chest.list()) do + if slotItem.name == itemName then + table.insert(results, { + chest = source.chest, + slot = slot, + name = itemName, + count = slotItem.count, + }) + if #results >= limit then break end + end + end + end + if #results >= limit then break end + end + end + if #results > 0 then break end -- found fuel, stop searching + end + log.info("NET", "find_item: found %d source(s)", #results) + pcall(function() + ctx.networkModem.transmit(replyChannel, cfg.ORDER_CHANNEL, { + type = "find_item_result", + commandId = message.commandId, + results = results, + }) + end) end end) -- pcall handler