diff --git a/Logistics/V5/startup.lua b/Logistics/V5/startup.lua index bbe583f..d436b57 100644 --- a/Logistics/V5/startup.lua +++ b/Logistics/V5/startup.lua @@ -9,7 +9,7 @@ local settings = { delay = 0.01 -- 轮询延迟,默认0.01秒 } local Tlist = {} -- 缓存传输列表 -local lastOutput = {} -- 记录每个优先级组上次使用的输出容器 +local lastOutput = {} -- 记录每个任务每个优先级组上次使用的输出容器 -- 加载配置 local function loadConfig() @@ -234,8 +234,8 @@ local function getTransferLimit(itemName, containerConfig) end -- 在 executeItemTask 函数中添加更多调试日志 -local function executeItemTask(task) - log(LOG_LEVEL.INFO, "开始执行物品任务", "Starting item transfer task") +local function executeItemTask(task, taskIndex) + log(LOG_LEVEL.INFO, "开始执行物品任务 #"..taskIndex, "Starting item transfer task #"..taskIndex) -- 收集所有输入容器的物品 local allItemsToTransfer = {} @@ -414,11 +414,15 @@ local function executeItemTask(task) local group = outputGroups[priority] -- 轮询输出 - local startIdx = lastOutput[priority] or 1 + local key = taskIndex.."_"..priority -- 使用任务索引和优先级作为唯一键 + log(LOG_LEVEL.DEBUG, "输出容器键: "..key, "Output container key: "..key) + + local startIdx = lastOutput[key] or 1 local idx = startIdx local attempts = 0 repeat + log(LOG_LEVEL.DEBUG, "输出容器idx:" .. tostring(idx) .. " #group:" .. tostring(#group)) local output = group[idx] log(LOG_LEVEL.DEBUG, "尝试输出容器: "..output.name.." (优先级 "..priority..", 尝试 "..attempts.."/"..#group..")", "Attempting output container: "..output.name.." (priority "..priority..", attempt "..attempts.."/"..#group..")") @@ -492,7 +496,8 @@ local function executeItemTask(task) end -- 更新轮询索引 - lastOutput[priority] = idx % #group + 1 + log(LOG_LEVEL.DEBUG, "轮询: idx:" .. tostring(idx) .. " #group:" .. tostring(#group)) + lastOutput[key] = idx % #group + 1 break else log(LOG_LEVEL.WARNING, "推送失败到 "..output.name.." (可能容器已满或无法接收)", @@ -526,8 +531,8 @@ local function executeItemTask(task) end -- 执行流体传输任务 -local function executeFluidTask(task) - log(LOG_LEVEL.INFO, "开始执行流体任务", "Starting fluid transfer task") +local function executeFluidTask(task, taskIndex) + log(LOG_LEVEL.INFO, "开始执行流体任务 #"..taskIndex, "Starting fluid transfer task #"..taskIndex) local transferred = false @@ -598,7 +603,8 @@ local function executeFluidTask(task) local group = outputGroups[priority] -- 轮询输出 - local startIdx = lastOutput[priority] or 1 + local key = taskIndex.."_"..priority -- 使用任务索引和优先级作为唯一键 + local startIdx = lastOutput[key] or 1 local idx = startIdx local attempts = 0 @@ -651,7 +657,7 @@ local function executeFluidTask(task) end -- 更新轮询索引 - lastOutput[priority] = idx % #group + 1 + lastOutput[key] = idx % #group + 1 else log(LOG_LEVEL.WARNING, "推送失败到 "..output.name, "Push failed to "..output.name) end @@ -695,11 +701,11 @@ local function executeFluidTask(task) end -- 执行任务 -local function executeTask(task) +local function executeTask(task, taskIndex) if task.type == "item" then - return executeItemTask(task) + return executeItemTask(task, taskIndex) elseif task.type == "fluid" then - return executeFluidTask(task) + return executeFluidTask(task, taskIndex) else log(LOG_LEVEL.ERROR, "错误: 未知任务类型: "..(task.type or "nil"), "Error: Unknown task type: "..(task.type or "nil")) return false @@ -712,7 +718,7 @@ local function taskLoop() while true do for i, task in ipairs(tasks) do log(LOG_LEVEL.INFO, "开始任务 #"..i, "Starting task #"..i) - local success, result = pcall(executeTask, task) + local success, result = pcall(executeTask, task, i) if not success then log(LOG_LEVEL.ERROR, "任务 #"..i.." 错误: "..tostring(result), "Task #"..i.." error: "..tostring(result)) elseif result then @@ -794,7 +800,7 @@ local function processCommand(cmd) for itemName in pairs(config.blacklist) do table.insert(items, itemName) end - echo(" 极"..name.." ("..cacheStr..", 黑名单: "..table.concat(items, ", ")..")", + echo(" "..name.." ("..cacheStr..", 黑名单: "..table.concat(items, ", ")..")", " "..name.." ("..cacheStrEn..", blacklist: "..table.concat(items, ", ")..")") else echo(" "..name.." ("..cacheStr..")", " "..name.." ("..cacheStrEn..")") @@ -818,7 +824,7 @@ local function processCommand(cmd) end end echo(" "..name.." (优先级:"..priority..", "..cacheStr..", 白名单: "..table.concat(items, ", ")..")", - " "..name.." (priority:"..priority..", "..cacheStrEn..", whitelist: "..table.concat(items, ", ")..")") + " "..name.." (priority:"..priority..", "..cacheStrEn..", whitelist: "..table.concat(items, ", ")..")") elseif config.blacklist then local items = {} for itemName in pairs(config.blacklist) do @@ -938,5 +944,4 @@ parallel.waitForAll( end end, taskLoop -) - +) \ No newline at end of file