Cleanup
This commit is contained in:
@@ -17,15 +17,16 @@
|
||||
-- 13-16: Furnace Outputs for 2 to 4 furni.lua arrays
|
||||
|
||||
-- Only user option, slot 4, what to use it for?
|
||||
|
||||
local useSlot4 = nil
|
||||
|
||||
-- Begin main program code
|
||||
-- Find modem with -only- turtles attached (these should be our furni/furniController arrays)
|
||||
local devModem = ""
|
||||
for nDev,modem in ipairs({peripheral.find("modem")}) do
|
||||
for _, modem in ipairs({peripheral.find("modem")}) do
|
||||
if #modem.getNamesRemote() > 1 then -- We're only looking for 2 or more devices on a network segment, ignore anything less
|
||||
nTurtles=0
|
||||
for nDev,dev in ipairs(modem.getNamesRemote()) do
|
||||
local nTurtles = 0
|
||||
for _, dev in ipairs(modem.getNamesRemote()) do
|
||||
if modem.getTypeRemote(dev) == "turtle" then nTurtles = nTurtles + 1 end
|
||||
end
|
||||
if nTurtles == #modem.getNamesRemote() then
|
||||
@@ -34,14 +35,16 @@ for nDev,modem in ipairs({peripheral.find("modem")}) do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if devModem ~= "" then
|
||||
print("Found turtle-only modem, detected", #devModem.getNamesRemote(), "turtles", (#devModem.getNamesRemote() > 4 and "(Max 4 will be mapped)" or "(All will be mapped)"))
|
||||
else
|
||||
print("Did not find a modem with only turtles connected. Please check your networking cables/modems and devices, then try again.")
|
||||
return -- We don't have a modem, halt
|
||||
end
|
||||
|
||||
local devTurtles = {}
|
||||
for nDev,dev in ipairs(devModem.getNamesRemote()) do
|
||||
for _, dev in ipairs(devModem.getNamesRemote()) do
|
||||
if #devTurtles >= 4 then break end
|
||||
devTurtles[#devTurtles+1] = peripheral.wrap(dev)
|
||||
print("Mapping", devTurtles[#devTurtles].getLabel(), "("..dev..")", "as device", #devTurtles)
|
||||
@@ -57,7 +60,7 @@ for nDev,dev in ipairs(devModem.getNamesRemote()) do
|
||||
end
|
||||
end
|
||||
|
||||
local turtle.list = function () -- Supplement a local .list()-like function
|
||||
local function listInventory() -- Supplement a local .list()-like function
|
||||
local tList = {}
|
||||
for i = 1, 16 do
|
||||
local slotData = turtle.getItemDetail(i) -- DWGFJTLR
|
||||
@@ -69,13 +72,12 @@ local turtle.list = function () -- Supplement a local .list()-like function
|
||||
return tList
|
||||
end
|
||||
|
||||
function manageLocalResources()
|
||||
local function manageLocalResources()
|
||||
--print("Input found")
|
||||
local itemCount = turtle.getItemCount(1) / #devTurtles
|
||||
if itemCount < 1 then itemCount = 1 end -- Patch for single items fed into master slot
|
||||
if turtle.getItemCount(1) > 0 then -- Input
|
||||
for nDev,dev in ipairs(devTurtles) do
|
||||
local devList=dev.list()
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.select(1) and ((turtle.compareTo(dev.inputSlot) and turtle.getItemSpace(dev.inputSlot) > 0) or turtle.getItemCount(dev.inputSlot) == 0) then -- Move Input
|
||||
turtle.transferTo(dev.inputSlot, itemCount)
|
||||
end
|
||||
@@ -85,20 +87,17 @@ function manageLocalResources()
|
||||
end
|
||||
end
|
||||
if turtle.select(2) and turtle.getSelectedSlot() == 2 then -- Fuel
|
||||
for nDev,dev in ipairs(devTurtles) do
|
||||
local devList=dev.list()
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.compareTo(dev.fuelSlot) or turtle.getItemCount(dev.fuelSlot) == 0 then turtle.transferTo(dev.fuelSlot,64) end -- Move fuel into slot
|
||||
end
|
||||
end
|
||||
if useSlot4 == "fuel" and turtle.select(4) and turtle.getSelectedSlot() == 4 then -- Fuel
|
||||
for nDev,dev in ipairs(devTurtles) do
|
||||
local devList=dev.list()
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.compareTo(dev.fuelSlot) or turtle.getItemCount(dev.fuelSlot) == 0 then turtle.transferTo(dev.fuelSlot,64) end -- Move fuel into slot
|
||||
end
|
||||
end -- Slot 4 fuel
|
||||
|
||||
for nDev,dev in ipairs(devTurtles) do
|
||||
local devList=dev.list()
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
if turtle.getItemCount(3) == 0 and turtle.getItemCount(dev.outputSlot) > 0 then
|
||||
turtle.select(dev.outputSlot)
|
||||
turtle.transferTo(3, 64)
|
||||
@@ -119,9 +118,9 @@ function manageLocalResources()
|
||||
end
|
||||
end
|
||||
|
||||
function manageRemoteResources()
|
||||
local localList=turtle.list()
|
||||
for nDev,dev in ipairs(devTurtles) do
|
||||
local function manageRemoteResources()
|
||||
local localList = listInventory()
|
||||
for _, dev in ipairs(devTurtles) do
|
||||
local devList = dev.list()
|
||||
--print(textutils.serialize(devList))
|
||||
if devList[2] == nil then
|
||||
@@ -162,13 +161,12 @@ function manageRemoteResources()
|
||||
end
|
||||
end
|
||||
|
||||
local lastList={}
|
||||
while true do -- Main Loop
|
||||
local turtleList=turtle.list()
|
||||
local turtleList = listInventory()
|
||||
if turtleList[1] ~= nil or turtleList[13] ~= nil or turtleList[14] ~= nil or turtleList[15] ~= nil or turtleList[16] ~= nil or ((useSlot4 == "input" or useSlot4 == "fuel") and turtleList[4] ~= nil) then
|
||||
manageLocalResources()
|
||||
end
|
||||
manageRemoteResources()
|
||||
turtle.setStatus("sleeping")
|
||||
os.sleep(1)
|
||||
sleep(1)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user