Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chest = peripheral.wrap("back")
- local oreExt = peripheral.wrap("extractor_6") -- ore extractor
- local dustExt = peripheral.wrap("extractor_7") -- dust extractor
- local size = chest.getInventorySize()
- local oresDir = "south"
- local dustsDir = "north"
- local redOre = "left"
- local redDust = "right"
- local sentOres = 0
- local sentDusts = 0
- local oArray = {"15:0", --iron ore
- "30888:17", --iron solution
- "14:0", --gold
- "30888:18"}
- local dArray = {"30888:1", --iron dust
- "30888:9", --iron slurry
- "30888:2", --gold dust
- "30888:10"}
- print("size is: " .. size)
- --see if item is extractable
- function isOre(ore)
- for k,v in pairs(oArray) do
- if (ore == v) then
- return true
- end
- end
- return false
- end
- function isDust(dust)
- for x,y in pairs(dArray) do
- if (dust == y) then
- return true
- end
- end
- return false
- end
- --isOre(15)
- --loop throught the inventory
- function sendStuff()
- sentOres = 0
- sentDusts = 0
- 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"])
- --print (combID)
- --print (type(combID))
- if (isOre(combID)) then
- --print(id["name"])
- sentOres = sentOres + chest.pushItem(oresDir,i,64)
- if (sentOres > 0) then
- rs.setOutput(redOre, true)
- end
- elseif (isDust(combID)) then
- --print(id["name"])
- sentDusts = sentOres + chest.pushItem(dustsDir,i,64)
- if (sentDusts > 0) then
- rs.setOutput(redDust, true)
- end
- end
- end
- end
- print (tostring(sentOres) .. "and" .. tostring(sentDusts))
- end
- function pullOres(slot)
- oreExt.pushItem(dustsDir, slot, 64)
- end
- function pullDusts(slot)
- dustExt.pushItem(oresDir, slot, 64)
- end
- function oreSlot(nr)
- if (oreExt.getStackInSlot(nr) ~= nil) then
- return false
- else
- return true
- end
- end
- function dustSlot(nr)
- if (dustExt.getStackInSlot(nr) ~= nil) then
- return false
- else
- return true
- end
- end
- function dustQ(nr)
- local var = dustExt.getStackInSlot(nr)
- if (var ~= nil) then
- if (var["qty"] > 62) then
- return true
- end
- else
- return false
- end
- return false
- end
- function oreQ(nr)
- local var = oreExt.getStackInSlot(nr)
- if (var ~= nil) then
- if (var["qty"] > 62) then
- return true
- else
- return false
- end
- end
- return false
- end
- while true do
- if (oreSlot(1) and oreSlot(7)) then
- rs.setOutput(redOre, false)
- sendStuff()
- print("1")
- --pullOres(2)
- --pullOres(8)
- --elseif (oreSlot(1) or oreSlot(7)) then
- --sendStuff()
- --pullOres(2)
- --print("2")
- --pullOres(8)
- end
- if (oreQ(2)) then
- --rs.setOutput("back", false)
- pullOres(2)
- print("3")
- --rs.setOutput("back", true)
- elseif (oreQ(8)) then
- pullOres(8)
- print("4")
- end
- if (dustSlot(3) and dustSlot(5)) then
- rs.setOutput(redDust, false)
- sendStuff()
- print("5")
- --elseif (dustSlot(3) or dustSlot(5)) then
- --sendStuff()
- --pullDusts(4)
- --pulldusts(6)
- --print("6")
- end
- if (dustQ(4)) then
- pullDusts(4)
- print("7")
- elseif (dustQ(6)) then
- pulldusts(6)
- print("8")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement