修复物品数量bug

This commit is contained in:
HKXluo
2025-10-22 12:49:18 +08:00
parent d91ba48e20
commit e79f135b12
3 changed files with 1160 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
-- Turtle Logistics System v4.2 (Fluid Support)
-- Turtle Logistics System v4.3 (Silent Mode & Full Transfer)
-- Supports direct container-to-container transfers for items and fluids
-- Config saved in config.cfg
@@ -160,7 +160,7 @@ local function executeFluidTransfer(task)
return false
end
-- Check min amount requirements
-- Check min amount requirements (only if minAmount > 0)
if task.fluids then
local sourceTanks = getFluidTanks(task.source)
if not sourceTanks then return false end
@@ -173,8 +173,8 @@ local function executeFluidTransfer(task)
end
for fluidName, minAmount in pairs(task.fluids) do
-- Only check if minAmount > 0
if minAmount > 0 and (fluidAmounts[fluidName] or 0) < minAmount then
print("Not enough "..fluidName.." ("..(fluidAmounts[fluidName] or 0).." < "..minAmount..")")
return false
end
end
@@ -192,17 +192,17 @@ local function executeFluidTransfer(task)
if shouldTransfer and tank.name and tank.amount > 0 then
local amount = tank.amount
if task.fluids and task.fluids[tank.name] then
amount = math.min(amount, task.fluids[tank.name])
-- If minAmount is 0, transfer all available
if task.fluids[tank.name] == 0 then
amount = tank.amount
else
amount = math.min(amount, task.fluids[tank.name])
end
end
-- Push fluid from source to destination
local transferred = source.pushFluid(task.destination, task.concat, task.name)
local transferred = source.pushFluid(task.destination, amount, tank.name)
totalTransferred = totalTransferred + transferred
-- Update transferred amount in requirements
if task.fluids and task.fluids[tank.name] then
task.fluids[tank.name] = task.fluids[tank.name] - transferred
end
end
end
@@ -230,7 +230,7 @@ local function executeTransfer(task)
-- Get destination name for pushItems
local destName = peripheral.getName(destination)
-- Check min count requirements
-- Check min count requirements (only if minCount > 0)
if task.items then
local sourceItems = getContainerItems(task.source)
local itemCounts = {}
@@ -242,8 +242,8 @@ local function executeTransfer(task)
end
for itemName, minCount in pairs(task.items) do
-- Only check if minCount > 0
if minCount > 0 and (itemCounts[itemName] or 0) < minCount then
print("Not enough "..itemName.." ("..(itemCounts[itemName] or 0).." < "..minCount..")")
return false
end
end
@@ -259,16 +259,16 @@ local function executeTransfer(task)
if shouldTransfer then
local count = item.count
if task.items and task.items[item.name] then
count = math.min(count, task.items[item.name])
-- If minCount is 0, transfer all available
if task.items[item.name] == 0 then
count = item.count
else
count = math.min(count, task.items[item.name])
end
end
local transferred = source.pushItems(destName, slot, count)
totalTransferred = totalTransferred + transferred
-- Update transferred count in requirements
if task.items and task.items[item.name] then
task.items[item.name] = task.items[item.name] - transferred
end
end
end
@@ -318,7 +318,7 @@ local function executeTransfer(task)
return false
end
-- Check min count requirements
-- Check min count requirements (only if minCount > 0)
if task.items then
local sourceItems = getContainerItems(task.source)
local itemCounts = {}
@@ -330,8 +330,8 @@ local function executeTransfer(task)
end
for itemName, minCount in pairs(task.items) do
-- Only check if minCount > 0
if minCount > 0 and (itemCounts[itemName] or 0) < minCount then
print("Not enough "..itemName.." ("..(itemCounts[itemName] or 0).." < "..minCount..")")
return false
end
end
@@ -347,7 +347,12 @@ local function executeTransfer(task)
if shouldTransfer then
local count = item.count
if task.items and task.items[item.name] then
count = math.min(count, task.items[item.name])
-- If minCount is 0, transfer all available
if task.items[item.name] == 0 then
count = item.count
else
count = math.min(count, task.items[item.name])
end
end
if source.pushItems(turtleName, slot, count) > 0 then
@@ -530,10 +535,12 @@ local function processCommand(cmd)
print(" Items format:")
print(" Simple: item1[:minCount] item2[:minCount] ...")
print(" JSON-like: {\"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(" Set minAmount to 0 to transfer all available fluid")
print("list - List all tasks")
print("remove <index> - Remove task")
print("setname <name> - Set turtle peripheral name")
@@ -548,7 +555,7 @@ end
-- Initialize
loadConfig()
print("Turtle Logistics System v4.2 started. Type 'help' for commands.")
print("Turtle Logistics System v4.3 started. Type 'help' for commands.")
print("Current turtle name: "..turtleName)
-- Main loop