-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan.lua
More file actions
42 lines (34 loc) · 925 Bytes
/
scan.lua
File metadata and controls
42 lines (34 loc) · 925 Bytes
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
local SCAN_FOR = {"ore"}
local scanner = peripheral.find("geoScanner")
if not scanner then
error("must place geoScanner next to computer", 0)
end
local blocks = scanner.scan(8)
if not blocks then
error("geoScanner scan returns nil", 0)
end
local result = io.open("result","w")
function result:print(...)
self:write(table.concat({...},",\t"),"\n")
end
local ore_count = {}
for _,block in pairs(blocks) do
for _,needle in pairs(SCAN_FOR) do
if block.name:find(needle) then
if not ore_count[block.name] then
ore_count[block.name] = 0
end
ore_count[block.name] = ore_count[block.name] + 1
end
end
end
local sort_table = {}
for k,v in pairs(ore_count) do
sort_table[#sort_table+1] = {k,v}
end
table.sort(sort_table, function(a,b) return a[2] > b[2] end)
for _,kv in pairs(sort_table) do
result:print(tostring(kv[2]).."x\t"..kv[1])
end
result:close()
shell.run("edit result")