· 4 years ago · Jul 26, 2021, 05:38 AM
1--[[ API check
2if fs.exists("event") == false then shell.run("pastebin get UKPy4iiE event") end
3if os.loadAPI("event") == false then error("Failed to load event API") end
4
5if fs.exists("data") == false then shell.run("pastebin get LnvzL7ur data") end
6if os.loadAPI("data") == false then error("Failed to load data API") end
7
8if fs.exists("utils") == false then shell.run("pastebin get dyvydHtK utils") end
9if os.loadAPI("utils") == false then error("Failed to load utils API") end
10]]
11
12-- initialization
13peripheral.wrap("back")
14peripheral.wrap("monitor_7")
15peripheral.wrap("opernperipheral_bridge_0")
16peripheral.wrap("down")
17tblLookup = {}
18local page = 1
19
20--lookup table init, used later for search bar
21for i = 0, 190 do
22 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
23 local data = c.getStoredItems()
24 -- local data2 = c.getMaxStoredItems()
25 -- print(data["display_name"])
26 tblLookup[i] = data["display_name"]
27 -- print(data["qty"].." / "..data2)
28end
29
30--functions
31function centerWrite(text)
32 local width, height = term.getSize()
33 local x, y = term.getCursorPos()
34 term.setCursorPos(math.ceil((width / 2) - (text:len() / 2)), y)
35 term.write(text)
36end
37
38function changePage()
39 os.pullEvent("key")
40 if key == keys.right then
41 term.clear()
42 page = page + 1
43 if page >= 23 then
44 page = 22
45 end
46 elseif key == keys.left then
47 term.clear()
48 page = page - 1
49 if page <= 0 then
50 page = 1
51 end
52 else
53 page = page
54 end
55end
56
57--pagination
58if page == 1 then
59 centerWrite("Page "..page.." of 22")
60 for i = 0, 7 do
61 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
62 local data = c.getStoredItems()
63 local data2 = c.getMaxStoredItems()
64 print(data["display_name"])
65 print(data["qty"].." / "..data2)
66 end
67 changePage()
68
69elseif page == 2 then
70 centerWrite("Page "..page.." of 22")
71 for i = 8, 15 do
72 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
73 local data = c.getStoredItems()
74 local data2 = c.getMaxStoredItems()
75 print(data["display_name"])
76 print(data["qty"].." / "..data2)
77 end
78 changePage()
79
80elseif page == 3 then
81 centerWrite("Page "..page.." of 22")
82 for i = 16, 23 do
83 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
84 local data = c.getStoredItems()
85 local data2 = c.getMaxStoredItems()
86 print(data["display_name"])
87 print(data["qty"].." / "..data2)
88 end
89 changePage()
90
91elseif page == 4 then
92 centerWrite("Page "..page.." of 22")
93 for i = 24, 31 do
94 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
95 local data = c.getStoredItems()
96 local data2 = c.getMaxStoredItems()
97 print(data["display_name"])
98 print(data["qty"].." / "..data2)
99 end
100 changePage()
101
102elseif page == 5 then
103 centerWrite("Page "..page.." of 22")
104 for i = 32, 39 do
105 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
106 local data = c.getStoredItems()
107 local data2 = c.getMaxStoredItems()
108 print(data["display_name"])
109 print(data["qty"].." / "..data2)
110 end
111 changePage()
112
113elseif page == 6 then
114 centerWrite("Page "..page.." of 22")
115 for i = 40, 47 do
116 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
117 local data = c.getStoredItems()
118 local data2 = c.getMaxStoredItems()
119 print(data["display_name"])
120 print(data["qty"].." / "..data2)
121 end
122 changePage()
123
124elseif page == 7 then
125 centerWrite("Page "..page.." of 22")
126 for i = 48, 55 do
127 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
128 local data = c.getStoredItems()
129 local data2 = c.getMaxStoredItems()
130 print(data["display_name"])
131 print(data["qty"].." / "..data2)
132 end
133 changePage()
134
135elseif page == 8 then
136 centerWrite("Page "..page.." of 22")
137 for i = 56, 63 do
138 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
139 local data = c.getStoredItems()
140 local data2 = c.getMaxStoredItems()
141 print(data["display_name"])
142 print(data["qty"].." / "..data2)
143 end
144 changePage()
145
146elseif page == 9 then
147 centerWrite("Page "..page.." of 22")
148 for i = 64, 71 do
149 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
150 local data = c.getStoredItems()
151 local data2 = c.getMaxStoredItems()
152 print(data["display_name"])
153 print(data["qty"].." / "..data2)
154 end
155 changePage()
156
157elseif page == 10 then
158 centerWrite("Page "..page.." of 22")
159 for i = 72, 79 do
160 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
161 local data = c.getStoredItems()
162 local data2 = c.getMaxStoredItems()
163 print(data["display_name"])
164 print(data["qty"].." / "..data2)
165 end
166 changePage()
167
168elseif page == 11 then
169 centerWrite("Page "..page.." of 22")
170 for i = 80, 87 do
171 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
172 local data = c.getStoredItems()
173 local data2 = c.getMaxStoredItems()
174 print(data["display_name"])
175 print(data["qty"].." / "..data2)
176 end
177 changePage()
178
179elseif page == 12 then
180 centerWrite("Page "..page.." of 22")
181 for i = 88, 95 do
182 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
183 local data = c.getStoredItems()
184 local data2 = c.getMaxStoredItems()
185 print(data["display_name"])
186 print(data["qty"].." / "..data2)
187 end
188 changePage()
189
190elseif page == 13 then
191 centerWrite("Page "..page.." of 22")
192 for i = 96, 103 do
193 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
194 local data = c.getStoredItems()
195 local data2 = c.getMaxStoredItems()
196 print(data["display_name"])
197 print(data["qty"].." / "..data2)
198 end
199 changePage()
200
201elseif page == 14 then
202 centerWrite("Page "..page.." of 22")
203 for i = 104, 111 do
204 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
205 local data = c.getStoredItems()
206 local data2 = c.getMaxStoredItems()
207 print(data["display_name"])
208 print(data["qty"].." / "..data2)
209 end
210 changePage()
211
212elseif page == 15 then
213 centerWrite("Page "..page.." of 22")
214 for i = 112, 119 do
215 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
216 local data = c.getStoredItems()
217 local data2 = c.getMaxStoredItems()
218 print(data["display_name"])
219 print(data["qty"].." / "..data2)
220 end
221 changePage()
222
223elseif page == 16 then
224 centerWrite("Page "..page.." of 22")
225 for i = 120, 127 do
226 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
227 local data = c.getStoredItems()
228 local data2 = c.getMaxStoredItems()
229 print(data["display_name"])
230 print(data["qty"].." / "..data2)
231 end
232 changePage()
233
234elseif page == 17 then
235 centerWrite("Page "..page.." of 22")
236 for i = 128, 135 do
237 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
238 local data = c.getStoredItems()
239 local data2 = c.getMaxStoredItems()
240 print(data["display_name"])
241 print(data["qty"].." / "..data2)
242 end
243 changePage()
244
245elseif page == 18 then
246 centerWrite("Page "..page.." of 22")
247 for i = 136, 143 do
248 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
249 local data = c.getStoredItems()
250 local data2 = c.getMaxStoredItems()
251 print(data["display_name"])
252 print(data["qty"].." / "..data2)
253 end
254 changePage()
255
256elseif page == 19 then
257 centerWrite("Page "..page.." of 22")
258 for i = 144, 151 do
259 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
260 local data = c.getStoredItems()
261 local data2 = c.getMaxStoredItems()
262 print(data["display_name"])
263 print(data["qty"].." / "..data2)
264 end
265 changePage()
266
267elseif page == 20 then
268 centerWrite("Page "..page.." of 22")
269 for i = 152, 159 do
270 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
271 local data = c.getStoredItems()
272 local data2 = c.getMaxStoredItems()
273 print(data["display_name"])
274 print(data["qty"].." / "..data2)
275 end
276 changePage()
277
278elseif page == 21 then
279 centerWrite("Page "..page.." of 22")
280 for i = 160, 167 do
281 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
282 local data = c.getStoredItems()
283 local data2 = c.getMaxStoredItems()
284 print(data["display_name"])
285 print(data["qty"].." / "..data2)
286 end
287 changePage()
288
289elseif page == 21 then
290 centerWrite("Page "..page.." of 22")
291 for i = 168, 175 do
292 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
293 local data = c.getStoredItems()
294 local data2 = c.getMaxStoredItems()
295 print(data["display_name"])
296 print(data["qty"].." / "..data2)
297 end
298 changePage()
299
300elseif page == 21 then
301 centerWrite("Page "..page.." of 22")
302 for i = 176, 183 do
303 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
304 local data = c.getStoredItems()
305 local data2 = c.getMaxStoredItems()
306 print(data["display_name"])
307 print(data["qty"].." / "..data2)
308 end
309 changePage()
310
311elseif page == 22 then
312 centerWrite("Page "..page.." of 22")
313 for i = 184, 190 do -- remainder 1, can add 1 to this before needing a new page
314 local c = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_"..tostring(i))
315 local data = c.getStoredItems()
316 local data2 = c.getMaxStoredItems()
317 print(data["display_name"])
318 print(data["qty"].." / "..data2)
319 end
320 changePage()
321end
322--can display about 8 results, dedicate 1 line to page number and another to the search bar and there will be no lines left
323
324--[[ stolen code from terminal glasses
325t = peripheral.wrap(tile_thermalexpansion_cache_resonant_name_0)
326capacity = t.getMaxEnergyStored("")
327amount = t.getEnergyStored("")
328
329
330
331-- working code
332cache = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_0")
333local data = cache.getStoredItems()
334local data2 = cache.getMaxStoredItems()
335print(data["display_name"])
336print(data["qty"].." / "..data2)
337
338--working code multiple modems
339cache = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_1")
340cache2 = peripheral.wrap("tile_thermalexpansion_cache_resonant_name_2")
341local cdata = cache.getStoredItems()
342local cdata2 = cache.getMaxStoredItems()
343local c2data = cache2.getStoredItems()
344local c2data2 = cache2.getMaxStoredItems()
345print(cdata["display_name"])
346print(cdata["qty"].." / "..cdata2)
347print(c2data["display_name"])
348print(c2data["qty"].." / "..c2data2)
349
350-- pervious working code
351local c = {}
352for i = 0, 190 do
353 c["cache"..tostring(i)] = "tile_thermalexpansion_cache_resonant_name_"..tostring(i)
354 peripheral.wrap(c["cache"..tostring(i)])
355end
356
357
358
359
360
361--searchbar
362Logical Process
3631. No search query, computer shows all results
3642. user inputs search query
3653. computer HIDES irrelevant results
3664. computer SHOWS relevant results
367
368--pagination
369page = 1
370if page == 1 then
371for i = 0, x do
372(show results that fit on one page)
373end
374os.pullEvent("key")
375if key == keys.right then
376page = page + 1
377elseif key == keys.left then
378page = page - 1
379if page <= 0 then page = 1
380]]
381