summaryrefslogtreecommitdiff
path: root/storage_old.lua
blob: 17751229154065c80a9daeb67c2ca63e3b10320c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
local names = {
["minecraft:ironchest_diamond_10237"] = "junk2",
["minecraft:ironchest_diamond_10239"] = "junk1",
["minecraft:ironchest_iron_2754"] = "computers",
}
print("Searching...")

local function search_for(term)
    local out = {}
    for phname,phlabel in pairs(names) do
        local ph = peripheral.wrap(phname)
        local maxslots = ph.size()
        for slx = 1,maxslots do
            local it = ph.getItemMeta(slx)
            if it then
                for _,name in ipairs{it.displayName,it.rawName,it.name} do
                    if name and name:lower():find(term) then
                        table.insert(out,{
                            it=it,
                            phname=phname,
                            ph=ph,
                            phlabel=phlabel,
                            slot=slx
                        })
                        --print(it.displayName .. ":" .. it.count .. " in " .. phlabel .. " slot " .. slx)
                        break
                    end
                end
            end
        end 
    end
    return out
end

function niceslot(slot)
    -- row, column
    return math.floor(slot/9)+1, slot%9
end


rows = {}
for i,res in ipairs(search_for(arg[1])) do
    local row,col = niceslot(res.slot)
    
    
    rows[i] = { res.it.displayName,
                "x" .. res.it.count,
                tostring(res.phlabel),
                row..","..col.." ("..res.slot..")", }
end
textutils.pagedTabulate(colors.red, {"name","count","chest","slot"},
                        colors.green, table.unpack(rows))