-
Notifications
You must be signed in to change notification settings - Fork 2
/
giant_storage.lua
86 lines (70 loc) · 1.89 KB
/
giant_storage.lua
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local component = require("component")
local sides = require("sides")
local serialization = require("serialization")
local function getSum(device)
local unit=0
local cnt=0
local allunit=0
local sz=device.getInventorySize(sides.north)
-- faster enum
local x=device.getAllStacks(sides.north)
while true do
local y=x()
if(y==nil) then
break
end
if(y.size~=nil) then
cnt=cnt+y.size
unit=unit+1
end
end
allunit=sz
sz=device.getInventorySize(sides.south)
-- faster enum
x=device.getAllStacks(sides.south)
while true do
local y=x()
if(y==nil) then
break
end
if(y.size~=nil) then
cnt=cnt+y.size
unit=unit+1
end
end
allunit=allunit+sz
return cnt,unit,allunit
end
while true do
local lst=component.list("inventory_controller")
local sumunit=0
local totalunit=0
local sum=0
local idx=1
while true do
local addr=lst()
if(addr==nil) then
break
end
print("Counting " .. idx)
local val,unit,allunit=getSum(component.proxy(addr))
print("ChestGroup " .. idx .. " has " .. val .. " items")
sum=sum+val
sumunit=sumunit+unit
totalunit=totalunit+allunit
idx=idx+1
end
local str="Total " .. sum .. " items of " .. totalunit*64 .. " (" .. sum/totalunit/64*100 .. "%). " ..
sumunit .. " of " .. totalunit .. " units used (" .. sumunit/totalunit*100 .. "%) "
print("Total " .. sum .. " items")
local tb={}
tb.item=sum
tb.maxitem=totalunit*64
tb.unit=sumunit
tb.maxunit=totalunit
print(str)
component.modem.broadcast(10010,str)
component.modem.broadcast(10011,serialization.serialize(tb))
print("Waiting for next loop...")
os.sleep(5)
end