From 0e2f714c13a301faaeb8fd5c85d25d48e41aa1f5 Mon Sep 17 00:00:00 2001 From: cynagen <43963132+cynagen@users.noreply.github.com> Date: Sat, 16 May 2020 19:36:59 -0700 Subject: [PATCH] Update exportTask.lua Fleshed out the exportItems function which was blindly firing items into full chests. Made it a little more sensitive, slight increase in average processing time, but no more erroneous hits to export causing perf issues. --- milo/plugins/exportTask.lua | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/milo/plugins/exportTask.lua b/milo/plugins/exportTask.lua index 279573b..e59de1e 100644 --- a/milo/plugins/exportTask.lua +++ b/milo/plugins/exportTask.lua @@ -69,10 +69,25 @@ function ExportTask:cycle(context) 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.adapter.list()) and context.storage:export(node, nil, item.count, item) == 0 then - -- TODO: really shouldn't break here as there may be room in other slots (probably not) - -- leaving for now for performance reasons - break + node.cacheList = node.adapter.list() + if node.adapter.size() ~= Util.size(node.cacheList) 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 + -- leaving for now for performance reasons + break + 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, slot.maxCount - slot.count, item) + end + end end end end