cartographer/init.lua

77 lines
2.2 KiB
Lua
Raw Normal View History

2020-02-16 18:55:07 +01:00
local mod_storage = minetest.get_mod_storage();
-- The API object
cartographer = {
scan_queue = {},
};
_cartographer = {
CHUNK_SIZE = 16,
biome_lookup = {},
2020-02-16 18:55:07 +01:00
maps = minetest.deserialize(mod_storage:get_string("maps")) or {},
next_map_id = mod_storage:get_int("next_map_id"),
last_deaths = minetest.deserialize(mod_storage:get_string("deaths")) or {},
spawns = minetest.deserialize(mod_storage:get_string("spawns")) or {},
materials_by_name = {},
materials_by_group = {},
};
if _cartographer.next_map_id == 0 then
_cartographer.next_map_id = 1;
end
data = {
generated = minetest.deserialize(mod_storage:get_string("map")) or {},
}
local function save()
mod_storage:set_string("maps", minetest.serialize(_cartographer.maps));
mod_storage:set_int("next_map_id", _cartographer.next_map_id);
mod_storage:set_string("map", minetest.serialize(data.generated));
mod_storage:set_string("deaths", minetest.serialize(_cartographer.last_deaths));
mod_storage:set_string("spawns", minetest.serialize(_cartographer.spawns));
end
minetest.register_on_shutdown(save);
minetest.register_on_leaveplayer(save);
local function periodic_save()
save();
minetest.after(60, periodic_save);
end
minetest.after(60, periodic_save);
function tochunk(coord)
return math.floor(coord / _cartographer.CHUNK_SIZE);
end
function fromchunk(coord)
return math.floor(coord * _cartographer.CHUNK_SIZE);
end
minetest.register_on_respawnplayer(function(player)
_cartographer.last_deaths[player:get_player_name()] = player:get_pos();
end)
minetest.register_on_newplayer(function(player)
minetest.after(1, function(player)
_cartographer.spawns[player:get_player_name()] = player:get_pos();
end, player);
end)
-- The path to this mod, for including files
local modpath = minetest.get_modpath("cartographer");
-- Includes
dofile(modpath .. "/commands.lua");
dofile(modpath .. "/scanner.lua");
dofile(modpath .. "/map_api.lua");
dofile(modpath .. "/map_formspec.lua");
dofile(modpath .. "/items.lua");
dofile(modpath .. "/table.lua");
-- Setup mod/game support
if minetest.get_modpath("default") then
dofile(modpath .. "/repixture.lua");
end