summaryrefslogtreecommitdiff
path: root/storage.lua
blob: 87b87431603bc516c4ed28adaa51cd2f1ede0c1d (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
--local M = peripheral.find"monitor"

local ok,chestnames = pcall(require,"chestnames")
if not ok then chestnames = {} end
chestnames = chestnames or {}
setmetatable(chestnames, {__index=function(t,k) return k end})


local sides = {}
for _,s in ipairs(redstone.getSides()) do sides[s] = true end 

local chest_types = {
	"minecraft:ironchest_diamond",
	"minecraft:ironchest_iron",
}

local function scan()
	local chests = {}
	for _,ty in ipairs(chest_types) do
		-- don't want sides, only ones over a network
		local tc = { peripheral.find(ty,function(n,p) return not sides[n] end) }
		for _,chest in ipairs(tc) do
			local name = peripheral.getName(chest)
			chests[name] = {
				content = chest.list(),
				size = chest.size(),
				pphl = chest,
			}
		end
	end
	return chests
end

local function search(query)
	local chests = scan()
	for chname,chest in pairs(chests) do
		for slot=1,chest.size do
			local it = chest.content[slot]
			if it and it.name:lower():find(query) then
				print(it.name,"x"..it.count,chestnames[chname])
			end
		end
	end
end

search(arg[1])