修复添加数量限制出错问题

This commit is contained in:
HKXluo
2025-10-22 13:10:10 +08:00
parent aff82936a2
commit 9893c2dada

View File

@@ -56,18 +56,23 @@ local function parseItemRequirements(input)
-- Split key-value pairs
for pair in content:gmatch("[^,]+") do
-- 支持JSON格式: "key":value
local key, value = pair:match("[\"']?(.-)[\"']?%s*:%s*(%d+)")
if key and value then
requirements[key] = tonumber(value)
end
end
else
-- Simple format: item:minCount
-- 只支持等号格式: item=count
for item in input:gmatch("%S+") do
local name, minCount = item:match("([^:]+):(%d+)")
-- 匹配等号格式: modid:itemid=count
local name, minCount = item:match("([^=]+)=(%d+)")
-- 如果匹配到等号格式
if name and minCount then
requirements[name] = tonumber(minCount)
else
-- 没有等号,视为只有物品名
requirements[item] = 0 -- No minimum requirement
end
end
@@ -488,7 +493,7 @@ local function processCommand(cmd)
local fluidsList = {}
for name, minAmount in pairs(task.fluids) do
if minAmount > 0 then
table.insert(fluidsList, name..":"..minAmount.."mB")
table.insert(fluidsList, name.."="..minAmount.."mB")
else
table.insert(fluidsList, name)
end
@@ -502,7 +507,7 @@ local function processCommand(cmd)
local itemsList = {}
for name, minCount in pairs(task.items) do
if minCount > 0 then
table.insert(itemsList, name..":"..minCount)
table.insert(itemsList, name.."="..minCount)
else
table.insert(itemsList, name)
end
@@ -533,13 +538,11 @@ local function processCommand(cmd)
print("Available commands:")
print("add <source> <destination> [items] - Add item transfer task")
print(" Items format:")
print(" Simple: item1[:minCount] item2[:minCount] ...")
print(" JSON-like: {\"item1\":minCount, \"item2\":minCount}")
print(" Simple: item1[=minCount] item2[=minCount] ...")
print(" Set minCount to 0 to transfer all available items")
print("addfluid <source> <destination> [fluids] - Add fluid transfer task")
print(" Fluids format:")
print(" Simple: fluid1[:minAmount] fluid2[:minAmount] ...")
print(" JSON-like: {\"fluid1\":minAmount, \"fluid2\":minAmount}")
print(" Simple: fluid1[=minAmount] fluid2[:minAmount] ...")
print(" Set minAmount to 0 to transfer all available fluid")
print("list - List all tasks")
print("remove <index> - Remove task")