Compare commits
2 Commits
d91ba48e20
...
aff82936a2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aff82936a2 | ||
|
|
e79f135b12 |
@@ -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
|
-- Supports direct container-to-container transfers for items and fluids
|
||||||
-- Config saved in config.cfg
|
-- Config saved in config.cfg
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ local function executeFluidTransfer(task)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check min amount requirements
|
-- Check min amount requirements (only if minAmount > 0)
|
||||||
if task.fluids then
|
if task.fluids then
|
||||||
local sourceTanks = getFluidTanks(task.source)
|
local sourceTanks = getFluidTanks(task.source)
|
||||||
if not sourceTanks then return false end
|
if not sourceTanks then return false end
|
||||||
@@ -173,8 +173,8 @@ local function executeFluidTransfer(task)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for fluidName, minAmount in pairs(task.fluids) do
|
for fluidName, minAmount in pairs(task.fluids) do
|
||||||
|
-- Only check if minAmount > 0
|
||||||
if minAmount > 0 and (fluidAmounts[fluidName] or 0) < minAmount then
|
if minAmount > 0 and (fluidAmounts[fluidName] or 0) < minAmount then
|
||||||
print("Not enough "..fluidName.." ("..(fluidAmounts[fluidName] or 0).." < "..minAmount..")")
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -192,17 +192,17 @@ local function executeFluidTransfer(task)
|
|||||||
if shouldTransfer and tank.name and tank.amount > 0 then
|
if shouldTransfer and tank.name and tank.amount > 0 then
|
||||||
local amount = tank.amount
|
local amount = tank.amount
|
||||||
if task.fluids and task.fluids[tank.name] then
|
if task.fluids and task.fluids[tank.name] then
|
||||||
|
-- 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])
|
amount = math.min(amount, task.fluids[tank.name])
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Push fluid from source to destination
|
-- 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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -230,7 +230,7 @@ local function executeTransfer(task)
|
|||||||
-- Get destination name for pushItems
|
-- Get destination name for pushItems
|
||||||
local destName = peripheral.getName(destination)
|
local destName = peripheral.getName(destination)
|
||||||
|
|
||||||
-- Check min count requirements
|
-- Check min count requirements (only if minCount > 0)
|
||||||
if task.items then
|
if task.items then
|
||||||
local sourceItems = getContainerItems(task.source)
|
local sourceItems = getContainerItems(task.source)
|
||||||
local itemCounts = {}
|
local itemCounts = {}
|
||||||
@@ -242,8 +242,8 @@ local function executeTransfer(task)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for itemName, minCount in pairs(task.items) do
|
for itemName, minCount in pairs(task.items) do
|
||||||
|
-- Only check if minCount > 0
|
||||||
if minCount > 0 and (itemCounts[itemName] or 0) < minCount then
|
if minCount > 0 and (itemCounts[itemName] or 0) < minCount then
|
||||||
print("Not enough "..itemName.." ("..(itemCounts[itemName] or 0).." < "..minCount..")")
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -259,16 +259,16 @@ local function executeTransfer(task)
|
|||||||
if shouldTransfer then
|
if shouldTransfer then
|
||||||
local count = item.count
|
local count = item.count
|
||||||
if task.items and task.items[item.name] then
|
if task.items and task.items[item.name] then
|
||||||
|
-- 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])
|
count = math.min(count, task.items[item.name])
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local transferred = source.pushItems(destName, slot, count)
|
local transferred = source.pushItems(destName, slot, count)
|
||||||
totalTransferred = totalTransferred + transferred
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -318,7 +318,7 @@ local function executeTransfer(task)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check min count requirements
|
-- Check min count requirements (only if minCount > 0)
|
||||||
if task.items then
|
if task.items then
|
||||||
local sourceItems = getContainerItems(task.source)
|
local sourceItems = getContainerItems(task.source)
|
||||||
local itemCounts = {}
|
local itemCounts = {}
|
||||||
@@ -330,8 +330,8 @@ local function executeTransfer(task)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for itemName, minCount in pairs(task.items) do
|
for itemName, minCount in pairs(task.items) do
|
||||||
|
-- Only check if minCount > 0
|
||||||
if minCount > 0 and (itemCounts[itemName] or 0) < minCount then
|
if minCount > 0 and (itemCounts[itemName] or 0) < minCount then
|
||||||
print("Not enough "..itemName.." ("..(itemCounts[itemName] or 0).." < "..minCount..")")
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -347,8 +347,13 @@ local function executeTransfer(task)
|
|||||||
if shouldTransfer then
|
if shouldTransfer then
|
||||||
local count = item.count
|
local count = item.count
|
||||||
if task.items and task.items[item.name] then
|
if task.items and task.items[item.name] then
|
||||||
|
-- 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])
|
count = math.min(count, task.items[item.name])
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if source.pushItems(turtleName, slot, count) > 0 then
|
if source.pushItems(turtleName, slot, count) > 0 then
|
||||||
pulled = true
|
pulled = true
|
||||||
@@ -530,10 +535,12 @@ local function processCommand(cmd)
|
|||||||
print(" Items format:")
|
print(" Items format:")
|
||||||
print(" Simple: item1[:minCount] item2[:minCount] ...")
|
print(" Simple: item1[:minCount] item2[:minCount] ...")
|
||||||
print(" JSON-like: {\"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("addfluid <source> <destination> [fluids] - Add fluid transfer task")
|
||||||
print(" Fluids format:")
|
print(" Fluids format:")
|
||||||
print(" Simple: fluid1[:minAmount] fluid2[:minAmount] ...")
|
print(" Simple: fluid1[:minAmount] fluid2[:minAmount] ...")
|
||||||
print(" JSON-like: {\"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("list - List all tasks")
|
||||||
print("remove <index> - Remove task")
|
print("remove <index> - Remove task")
|
||||||
print("setname <name> - Set turtle peripheral name")
|
print("setname <name> - Set turtle peripheral name")
|
||||||
@@ -548,7 +555,7 @@ end
|
|||||||
|
|
||||||
-- Initialize
|
-- Initialize
|
||||||
loadConfig()
|
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)
|
print("Current turtle name: "..turtleName)
|
||||||
|
|
||||||
-- Main loop
|
-- Main loop
|
||||||
|
|||||||
Reference in New Issue
Block a user