From 84de29259e27e7b0991051ca955e282119874774 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Wed, 5 Jul 2017 00:05:54 -0600 Subject: [PATCH] Mapgen defaults for fresh installs A fresh install that had never had its mapgen flags tinkered with would return nil when requesting them, which would normally mean "go with the defaults." This mod overrides those defaults, so a fallback is needed. --- init.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/init.lua b/init.lua index e0c32ad..08d02a6 100644 --- a/init.lua +++ b/init.lua @@ -18,27 +18,43 @@ dofile(modpath.."/player_spawn.lua") subterrane.disable_mapgen_caverns = function() local mg_name = minetest.get_mapgen_setting("mg_name") local flags_name - if mg_name == "v7" then flags_name = "mgv7_spflags" - elseif mg_name == "v5" then flags_name = "mgv5_spflags" + local default_flags + + if mg_name == "v7" then + flags_name = "mgv7_spflags" + default_flags = "mountains,ridges,nofloatlands" + elseif mg_name == "v5" then + flags_name = "mgv5_spflags" + default_flags = "" else return end + local function split(source, delimiters) local elements = {} local pattern = '([^'..delimiters..']+)' string.gsub(source, pattern, function(value) elements[#elements + 1] = value; end); return elements end - local flags = split(minetest.get_mapgen_setting(flags_name), ", ") + + local flags_setting = minetest.get_mapgen_setting(flags_name) or default_flags local new_flags = {} + local flags = split(flags_setting, ", ") + local nocaverns_present = false for _, flag in pairs(flags) do if flag ~= "caverns" then table.insert(new_flags, flag) end + if flag == "nocaverns" then + nocaverns_present = true + end + end + if not nocaverns_present then + table.insert(new_flags, "nocaverns") end - table.insert(new_flags, "nocaverns") minetest.set_mapgen_setting(flags_name, table.concat(new_flags, ","), true) end + subterrane.disable_mapgen_caverns() -- defaulting to disabling them, for now. Need to assess how to integrate this feature into subterrane better. local c_lava = minetest.get_content_id("default:lava_source")