View difference between Paste ID: PtUwWwhC and CS4Vjy8z
SHOW: | | - or go back to the newest paste.
1
-- Conveyor
2
-- by SukaiPoppuGo
3
-- require mod Plethora
4
-- Usage:
5
-- Conveyor <from:string> <to:string>
6
--
7
-- Ex:
8
-- Conveyor south north
9
10
local from, to = ...
11
local delay = 20
12
13
os.setComputerLabel("Conveyor")
14
15
local inv = {}
16
17
local function hasMethod(name,method)
18
    for _,m in pairs(peripheral.getMethods(name)) do
19
        if m == method then
20
            return true
21
        end
22
    end
23
    return false
24
end
25
26
for _,name in pairs(peripheral.getNames()) do
27
    if hasMethod(name, "pushItems") then
28
        table.insert(inv, peripheral.wrap(name))
29
    end
30
end
31
32
local function suck(container)
33
    local slot = 1
34
    while true do
35
        print(string.format("Suck slot %s from %s", slot, from))
36
        if not pcall(container.pullItems, from, slot) then
37
            return
38
        end
39
        slot = slot+1
40
    end
41
end
42
43
local function dump(container)
44
    for slot, item in pairs(container.list()) do
45
        print(string.format("Dump slot %s to %s", slot, to))
46
        if not container.pushItems(to, slot) then
47
            print(string.format("Fail to dump slot %s to %s", slot, to))
48
            return
49
        end
50
    end
51
end
52
53-
    sleep(5)
53+
54
    for _, container in pairs(inv) do
55
        dump(container)
56
        sleep()
57
        suck(container)
58
        sleep()
59
        dump(container)
60
        sleep()
61
    end
62
    print("pause")
63
    sleep(delay)
64
end