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