Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chest = peripheral.wrap("container_chest_5")
- local oreMot = peripheral.wrap("extractor_11")
- local dustMot = peripheral.wrap("extractor_10")
- --local oreExt = peripheral.wrap("extractor_6") -- ore extractor
- local size = chest.getInventorySize()
- local oresDir = "north"
- local endDir = "west"
- local oreSig = "left"
- local dustSig = "right"
- local oresToPush = {}
- local ores = {"15:0","14:0", "2001:0"}
- if not fs.exists("/ores") then
- print ("creating ores file")
- local f = io.open("/ores", "w")
- f:write(textutils.serialize(ores))
- f:close()
- end
- function copyToDisk()
- if fs.exists("/disk") then
- local f = io.open("/disk/ores", "w")
- f:write(textutils.serialize(ores))
- f:close()
- end
- end
- print("size is: " .. size)
- function getOresFile()
- local f = io.open("/ores", "r")
- local data = f:read("*l")
- ores = textutils.unserialize(data)
- f:close()
- copyToDisk()
- end
- --see if item is extractable
- function isOre(ore)
- for k,v in pairs(ores) do
- if (ore == v) then
- return true
- end
- end
- return false
- end
- --loop throught the inventory
- function stuffToSend()
- --chest.condenseItems()
- for i=1,size do
- --print (i)
- local id = chest.getStackInSlot(i)
- if (id ~= nil) then
- local combID = tostring(id["id"])..":"..tostring(id["dmg"])
- local iName = tostring(id["name"])
- --print (combID)
- if isOre(combID) and (string.find(iName, "Ore") ~= nil or string.find(iName, "ore") ~= nil) then
- print (iName.." to tha list to push")
- local leng = table.getn(oresToPush) + 1
- oresToPush[leng] = i
- --chest.pushItem(oresDir,i,64)
- end
- end
- end
- sendStuff()
- end
- function sendStuff()
- if table.getn(oresToPush) ~= 0 then
- for k,v in pairs(oresToPush) do
- print (chest.getStackInSlot(v)["name"])
- while chest.getStackInSlot(v) ~= nil do
- chest.pushItemIntoSlot(oresDir,v,64,1)
- getResult(1)
- getResult(2)
- --os.sleep(0.5)
- print ("loop")
- end
- end
- end
- oresToPush = {}
- end
- function notDone()
- for i = 1, 9 do
- local slot = oreMot.getStackInSlot(i)
- local slot1 = dustMot.getStackInSlot(i)
- if slot ~= nil or slot1 ~= nil then
- return true
- end
- end
- return false
- end
- function slotTable(nr, rig)
- --print (rig.getStackInSlot(nr))
- return rig.getStackInSlot(nr)
- end
- function getResult(mode)
- if mode == 1 then
- --print("ore machine")
- machine = oreMot
- matSlot1 = 1
- matSlot2 = 4
- resSlot1 = 5
- resSlot2 = 2
- resSlot3 = 8
- resSlot4 = 9
- signal = oreSig
- opDir = oresDir
- else
- --print("dust machine")
- machine = dustMot
- matSlot1 = 2
- matSlot2 = 3
- resSlot1 = 7
- resSlot2 = 4
- signal = dustSig
- opDir = "south"
- end
- --check if machines have stuff to work with, if not take away Red
- if slotTable(matSlot1, machine) == nil and slotTable(matSlot2, machine) == nil then
- print (tostring(matSlot1) .. "and" .. tostring (matSlot2) .. " are empty")
- rs.setOutput(signal, false)
- else
- rs.setOutput(signal, true)
- end
- --first result material (dust/solution) gets moved
- if slotTable(resSlot1, machine) ~= nil then
- machine.pushItemIntoSlot(opDir, resSlot1, 64, resSlot1 - 3)
- end
- --move more sutff
- if slotTable(resSlot2, machine) ~= nil then
- machine.pushItemIntoSlot(opDir, resSlot2, 64, resSlot2)
- end
- if machine == oreMot then
- if slotTable(resSlot3, machine) ~= nil then
- --print ("pushing")
- machine.pushItem(endDir, resSlot3, 64)
- --else
- --print("done")
- elseif slotTable(resSlot4, machine) ~= nil then
- machine.pushItem(endDir, resSlot4, 64)
- end
- end
- end
- --run functions
- getOresFile()
- stuffToSend()
- while notDone() do
- getResult(1)
- getResult(2)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement