Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Conveyor
- -- by SukaiPoppuGo
- -- require mod Plethora
- -- Usage:
- -- Conveyor <from:string> <to:string>
- --
- -- Ex:
- -- Conveyor south north
- local from, to = ...
- local delay = 20
- os.setComputerLabel("Conveyor")
- local inv = {}
- local function hasMethod(name,method)
- for _,m in pairs(peripheral.getMethods(name)) do
- if m == method then
- return true
- end
- end
- return false
- end
- for _,name in pairs(peripheral.getNames()) do
- if hasMethod(name, "pushItems") then
- table.insert(inv, peripheral.wrap(name))
- end
- end
- local function suck(container)
- local slot = 1
- while true do
- print(string.format("Suck slot %s from %s", slot, from))
- if not pcall(container.pullItems, from, slot) then
- return
- end
- slot = slot+1
- end
- end
- local function dump(container)
- for slot, item in pairs(container.list()) do
- print(string.format("Dump slot %s to %s", slot, to))
- if not container.pushItems(to, slot) then
- print(string.format("Fail to dump slot %s to %s", slot, to))
- return
- end
- end
- end
- while true do
- for _, container in pairs(inv) do
- dump(container)
- sleep()
- suck(container)
- sleep()
- dump(container)
- sleep()
- end
- print("pause")
- sleep(delay)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement