-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-blocks.lua
48 lines (43 loc) · 1.11 KB
/
find-blocks.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
--[[
Block finder, by fatboychummy
Usage: find-blocks.lua <block> [block] [block] ...
Example: find-blocks.lua minecraft:chest minecraft:ender_chest
This program will scan the area around the computer for specific blocks, and
print their locations (if found) to the screen.
]]
local _blocks = table.pack(...)
local blocks = {}
for i = 1, _blocks.n do
blocks[_blocks[i]] = true
end
local cached_scan
local function scan()
local result = peripheral.call("back", "scan", 8)
if result then
cached_scan = result
end
return cached_scan
end
local function find_blocks()
local data = scan()
local found_blocks = {}
for _, block in ipairs(data) do
if blocks[block.name] then
table.insert(found_blocks, block)
end
end
return found_blocks
end
while true do
local positions = find_blocks()
term.setCursorPos(1, 1)
term.clear()
print(("Tracking %d blocks:"):format(#positions))
table.sort(positions, function(a, b) return a.name < b.name end)
for _, block in pairs(positions) do
if blocks[block.name] then
print(block.name, block.x, block.y, block.z)
end
end
sleep(5)
end