cartographer/autofill.lua

38 lines
1.1 KiB
Lua
Raw Normal View History

2020-06-11 02:54:00 +02:00
local chunk, scanner, maps = ...;
2020-06-11 02:49:10 +02:00
-- 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);