111 lines
3.2 KiB
Lua
111 lines
3.2 KiB
Lua
function cartographer.create_map(x, z, w, h, filled, detail)
|
|
local id = _cartographer.next_map_id;
|
|
|
|
local map = {
|
|
id = id,
|
|
x = x,
|
|
z = z,
|
|
w = w,
|
|
h = h,
|
|
detail = detail,
|
|
fill = {},
|
|
};
|
|
|
|
_cartographer.maps[id] = map;
|
|
if filled then
|
|
cartographer.fill(map, x, z, w, h);
|
|
end
|
|
|
|
_cartographer.next_map_id = _cartographer.next_map_id + 1;
|
|
|
|
return id;
|
|
end
|
|
|
|
function cartographer.get_map(id)
|
|
return _cartographer.maps[id];
|
|
end
|
|
|
|
function cartographer.resize_map(id, w, h)
|
|
local map = cartographer.get_map(id);
|
|
if map ~= nil and w >= map.w and h >= map.h then
|
|
map.w = w;
|
|
map.h = h;
|
|
end
|
|
end
|
|
|
|
function cartographer.fill(map, x, z, w, h)
|
|
if map == nil then
|
|
return;
|
|
end
|
|
|
|
for i = math.max(x, map.x),math.min(x + w - 1, map.x + map.w),1 do
|
|
for j = math.max(z, map.z),math.min(z + h - 1, map.z + map.h),1 do
|
|
map.fill[(i - map.x) + ((j - map.z) * map.w)] = map.detail;
|
|
end
|
|
end
|
|
end
|
|
|
|
function cartographer.fill_local(id, x, z)
|
|
local map = cartographer.get_map(id);
|
|
|
|
if map ~= nil and x >= map.x - 2 and x <= map.x + map.w + 1 and z >= map.z - 2 and z <= map.z + map.h + 1 then
|
|
minetest.chat_send_all("[" .. tostring(x) .. ", " .. tostring(z) .. "] - [" .. tostring(map.x - 2) .. ", " .. tostring(map.z - 2) .. "], [" .. tostring(map.x + map.w + 1) .. ", " .. tostring(map.z + map.h + 1) .. "]");
|
|
cartographer.fill(map, x - 2, z - 2, 5, 5);
|
|
end
|
|
end
|
|
|
|
local timer = 0;
|
|
|
|
minetest.register_globalstep(function(dt)
|
|
timer = timer - dt;
|
|
if timer < 0 then
|
|
timer = timer + 5;
|
|
|
|
-- 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();
|
|
local player_x = tochunk(pos.x);
|
|
local player_y = tochunk(pos.z);
|
|
for i = 1,inventory:get_size("main") do
|
|
local stack = inventory:get_stack("main", i);
|
|
|
|
if stack:get_name() == "cartographer:map" then
|
|
cartographer.fill_local(stack:get_meta():get_int("cartographer:map_id"), player_x, player_y);
|
|
end
|
|
end
|
|
for i = -2,2 do
|
|
for j = -2,2 do
|
|
local adjusted_pos = {
|
|
x = tochunk(pos.x + fromchunk(i)),
|
|
y = tochunk(pos.y),
|
|
z = tochunk(pos.z + fromchunk(j)),
|
|
}
|
|
cartographer.queue_region(adjusted_pos);
|
|
end
|
|
end
|
|
end
|
|
|
|
for i = 1,10 do
|
|
cartographer.scan_regions();
|
|
end
|
|
end
|
|
end)
|
|
|
|
function cartographer.register_biome(name, texture, height)
|
|
cartographer.biome_lookup[name] = texture;
|
|
|
|
if height ~= nil and height ~= 0 then
|
|
cartographer.biome_heights[name] = height;
|
|
end
|
|
end
|
|
|
|
function cartographer.is_filled(map, x, z)
|
|
if map == nil then
|
|
return false;
|
|
end
|
|
|
|
minetest.chat_send_all(tostring(x).. ", " .. tostring(z) .. "(" .. tostring(x + (z * map.w)) .."): " .. tostring(map.fill[x + (z * map.w)]));
|
|
return map.fill[(x - map.x) + ((z - map.z) * map.w)] ~= nil;
|
|
end
|