From f1181d956a5eeec3161075321688e7113beedb1a Mon Sep 17 00:00:00 2001 From: kno10 Date: Sun, 29 Dec 2024 00:00:46 +0100 Subject: [PATCH] Store mapgen version (#4762) Store the version used to initialize the map in the map_env.txt file. - if a version is stored in the map_env.txt file, it is used. - if the map is new, the current game version is used. - if the map is old, 0.87 is assumed for compatibility. Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4762 Reviewed-by: the-real-herowl Co-authored-by: kno10 Co-committed-by: kno10 --- mods/CORE/mcl_init/init.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mods/CORE/mcl_init/init.lua b/mods/CORE/mcl_init/init.lua index 3a0f1c4e5..a2f56365e 100644 --- a/mods/CORE/mcl_init/init.lua +++ b/mods/CORE/mcl_init/init.lua @@ -3,6 +3,27 @@ mcl_vars = {} minetest.log("action", "World seed = " .. minetest.get_mapgen_setting("seed")) +-- Get a version number for map generation. +local map_version = tonumber(core.get_mapgen_setting("vl_world_version") or "") +if not map_version then + -- Try to read gametime *before* initialization + -- Primarily to detect when an old world is loaded. + local start_time = tonumber(Settings(core.get_worldpath() .. "/env_meta.txt"):get("game_time")) or 0 + if start_time > 0 then -- old world, assume "0.87 or earlier" + map_version = 0.87 -- starting in 0.88, the version should be stored. + else + local game_version = Settings(core.get_game_info().path .. "/game.conf"):get("version") + map_version = game_version and tostring(game_version:match("(%d+%.%d+)")) + if not map_version then + core.log("warning", "Could not obtain a game version. Fallback to 0.87. "..dump(game_version)) + map_version = 0.87 + end + end + core.set_mapgen_setting("vl_world_version", map_version, true) +end +mcl_vars.map_version = map_version -- make available +core.log("action", "Voxelibre mapgen version = "..map_version) + mcl_vars.redstone_tick = 0.1 -- GUI / inventory menu settings