cartographer/autofill.lua
Hugues Ross ca910ad29d Documentation pass, part 1
- Also added more optional parameters to the gui api
2020-06-13 07:41:56 -04:00

42 lines
1.3 KiB
Lua

-- Arguments
-- chunk: The chunk coordinate conversion API
-- scanner: The map scanning API
-- maps: The map API
local chunk, scanner, maps = ...;
-- Periodically-called function to fill in maps and queue chunks for manual
-- scanning
local function fill_loop()
-- Fill in all player-held maps
for _,p in ipairs(minetest.get_connected_players()) do
local inventory = p:get_inventory();
local pos = p:get_pos();
if pos.y > -10 then
for i = 1,inventory:get_size("main") do
local stack = inventory:get_stack("main", i);
local map = maps.get(stack:get_meta():get_int("cartographer:map_id"));
if map then
map:fill_local(pos.x, pos.z);
end
end
for i = -2,2 do
for j = -2,2 do
local adjusted_pos = {
x = pos.x + chunk.from(i),
y = pos.y,
z = pos.z + chunk.from(j),
}
scanner.queue_region(adjusted_pos);
end
end
end
end
for _ = 1,10 do
scanner.scan_regions();
end
minetest.after(5, fill_loop);
end
minetest.after(5, fill_loop);