diff --git a/milo/plugins/exportTask.lua b/milo/plugins/exportTask.lua index ec7f82d..3c93a6a 100644 --- a/milo/plugins/exportTask.lua +++ b/milo/plugins/exportTask.lua @@ -66,11 +66,12 @@ function ExportTask:cycle(context) end local function exportItems() - node.cacheList = node.adapter.list() + local cache,size={node.adapter.list(),node.adapter.size()} -- Make single calls, not repeat + local cacheSize=Util.size(cache) -- Same, though this call doesn't hurt as bad for key in pairs(entry.filter) do local items = Milo:getMatches(itemDB:splitKey(key), entry) for _,item in pairs(items) do - if node.adapter.size() ~= Util.size(node.cacheList) then + if size ~= cacheSize then -- Here we have a storage which has at least 1 unpopulated slot, we can fire'n'forget into this if context.storage:export(node, nil, item.count, item) == 0 then -- TODO: really shouldn't break here as there may be room in other slots @@ -79,19 +80,21 @@ function ExportTask:cycle(context) end else -- Here we have a storage with all slots occupied, sort through and find open spaces - for iNum,_ in ipairs(node.cacheList) do - local slot = node.adapter.getItemMeta(iNum) - if (slot.name == filterItem.name and slot.count ~= slot.maxCount and - (entry.ignoreDamage or slot.damage == filterItem.damage) and - (entry.ignoreNbtHash or slot.nbtHash == filterItem.nbtHash)) then - -- We found a slot that matches, and is not full, let's export to it! - context.storage:export(node, iNum, math.min(slot.maxCount-slot.count,item.count), item) + for iNum=1,size do + local slot = cache[i] + if slot then + if (slot.name == item.name and slot.count ~= item.maxCount and + (entry.ignoreDamage or slot.damage == item.damage) and + (entry.ignoreNbtHash or slot.nbtHash == item.nbtHash)) then + -- We found a slot that matches, and is not full, let's export to it! + -- Reworked to use item's .maxCount against the existing .list()[slot].count instead of repeat .getItemMeta calls + context.storage:export(node, iNum, math.min(item.maxCount-slot.count,item.count), item) + end end end end end end - node.cacheList=nil end if type(entry.slot) == 'number' then exportSingleSlot()