From d02f3d36a68e12313b48a2015d9fdbd74ae3ecd2 Mon Sep 17 00:00:00 2001 From: cynagen <43963132+cynagen@users.noreply.github.com> Date: Sun, 17 May 2020 19:44:20 -0700 Subject: [PATCH] Update exportTask.lua Fixing some logic, make less plethora calls --- milo/plugins/exportTask.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/milo/plugins/exportTask.lua b/milo/plugins/exportTask.lua index 766b81b..3c3e3e7 100644 --- a/milo/plugins/exportTask.lua +++ b/milo/plugins/exportTask.lua @@ -66,32 +66,38 @@ function ExportTask:cycle(context) end local function exportItems() + local debugLog="exportItems()" node.cacheList = node.adapter.list() 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 + debugLog=debugLog.." empty slot found" -- 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 + debugLog=debugLog.." failed to export, break" -- TODO: really shouldn't break here as there may be room in other slots -- leaving for now for performance reasons break end else -- Here we have a storage with all slots occupied, sort through and find open spaces + debugLog=debugLog.." no empty slots found, cycling slots" 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 + debugLog=debugLog.." found matching slot, exporting" -- We found a slot that matches, and is not full, let's export to it! - context.storage:export(node, iNum, slot.maxCount - slot.count, item) + context.storage:export(node, iNum, math.min(slot.maxCount-slot.count,item.count), item) end end end end end node.cacheList=nil + _G._syslog(debugLog) end if type(entry.slot) == 'number' then exportSingleSlot()