View difference between Paste ID: dgt4Ehcb and WbYDdHEn
SHOW: | | - or go back to the newest paste.
1
-- Declare variables
2
-- The chest needs to be to the right of the computer
3
local enderChest = peripheral.wrap("right")
4
-- The chest needs to be on top of the computer
5
local enderTank = peripheral.wrap("top")
6
7
local chest = 0
8
9
local tank = 0
10
11
local colors = {"white", "red", "blue", "yellow", "green", "black", "cyan", "magenta", "pink", "orange", "lightblue", "lime", "gray", "lightgray", "purple", "brown"}
12
13
-- The % sign is called a modulo operator
14
function getChestFromPin(n)
15
    local third = n % 16
16
    n = n / 16
17
    n = math.floor(n);
18
    local second = n % 16
19
    n = n / 16
20
    n = math.floor(n);
21
    local first = n % 16
22
    return {colors[(first + 1)], colors[(second + 1)], colors[(third + 1)]}
23
end
24
25
-- This functions prints on the screen which chest color combos have items in them
26
function addPinToList(n, id)
27
    if id == "chest" then
28
        local chest = getChestFromPin(n)
29
        print("Items found in ["..chest[1]..", "..chest[2]..", "..chest[3].."]")
30
    elseif id == "tank" then
31
        local tank = getChestFromPin(n)
32
        local contents = enderTank.getTankInfo("")
33
        print(contents[1].name.." found in ["..tank[1]..", "..tank[2]..", "..tank[3].."]")
34
        contents = nil
35
    end
36
    return "Added pin to list"
37
end
38
39
-- Checks for existence of contents in ender tank
40
function tank()
41
    -- 4096 is the number of possible color combinations (16x16x16)
42
    for pin = 1, 4096, 1 do
43
        -- Call function based on current iteration's color combination
44
        local chest = getChestFromPin(pin)
45
    enderTank.setColorNames(chest[1], chest[2], chest[3])
46
        -- Checks for presence of any existing items in the chest of the current color combination
47
        local contents = enderTank.getTankInfo("")
48
        if contents[1].name ~= nil then
49
            addPinToList(pin, "tank")
50
        end
51
    end
52
    -- Print message once all iterations are complete
53
    print("Enter 'exit' to return to main menu.")
54
    input = read()
55
    if input == "exit" then
56
        main()
57
    end
58
    return "Scanned tank."
59
end
60
61
-- Checks for existence of contents in ender chest
62
function chest()
63
    -- 4096 is the number of possible color combinations (16x16x16)
64
    for pin = 1, 4096, 1 do
65
        -- Call function based on current iteration's color combination
66
        local chest = getChestFromPin(pin)
67
    enderChest.setColorNames(chest[1], chest[2], chest[3])
68
        -- Checks for presence of any existing items in the chest of the current color combination
69
        local contents = enderChest.getAllStacks()
70
        if contents[1] ~= nil then
71
            addPinToList(pin, "chest")
72
        end
73
    end
74
    -- Print message once all iterations are complete
75
    print("Enter 'exit' to return to main menu.")
76
    input = read()
77
    if input == "exit" then
78
        main()
79
    end
80
    return "Scanned chest."
81
end
82
83
-- Welcome message, tells user how to use the program and accept's user's prompt
84
function main()
85
    term.clear()
86
    term.setCursorPos(1, 1)
87
88
    print("Enter 'chest' (right) or 'tank' (top) to begin.")
89
90
    input = read()
91
92
    if input == "chest" then
93
        chest()
94
    elseif input == "tank" then
95
        tank()
96
    end
97
end
98
99
main()