Any way to tell if a world is newly generated?

Post Reply
User avatar
Mantar
Member
Posts: 592
Joined: Thu Oct 05, 2017 18:46
Contact:

Any way to tell if a world is newly generated?

by Mantar » Post

I've got some new biomes that Dokimi sent for Exile, (thanks to Yad for doing the heavy lifting) but if enabled on an existing world, you get some funky edges between the previously generated map blocks and the new ones. I'd like to auto-disable them on existing worlds, and enable them for new worlds with an option selected.

Here comes the trouble: I can read and/or store the world-specific choice before mapgen happens with minetest.get/set_mapgen_settings, but to make the proper determination I need to be able to tell if the world is new or not during the initialization phase, and get_day_count/get_gametime return nil at this point. If I wait until after mapgen is complete to enable the new biomes, I can tell how long the world has existed, but I'm back at the start with broken terrain.

I need to be able to detect this because as soon as the user enables the new biomes in the settings menu, it'll be global and affect every world loaded from then on, unless I can spot the old worlds and disable it before loading.

The manual workaround would be to tell users to turn the global off and then load every world they have so that the "off" setting would get saved in each one, then turn it on for new worlds, but that's asking a lot of users and feels like making the user have to work just to sweep a bug under the rug.

It'd be nice if game authors could add a custom checkbox to the mapgen screen when making a new world. Maybe infotext, too -- it'd be nice if Exile could warn the player there that Carpathian mapgen is harder than Valleys before generating a world.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

User avatar
orwell
Member
Posts: 958
Joined: Wed Jun 24, 2015 18:45
GitHub: orwell96
IRC: orwell96_mt
In-game: orwell
Location: Raxacoricofallapatorius

Re: Any way to tell if a world is newly generated?

by orwell » Post

One thing that may be worth trying: At the point where you want to set_mapgen_settings(), check for the existence of certain files (map_meta.txt, env_meta.txt, map.sqlite) in the world directory. Maybe those files do not exist yet during the first start of a world.

Otherwise I am out of ideas as well.
Lua is great!
List of my mods
I like singing. I like dancing. I like ... niyummm...

User avatar
Mantar
Member
Posts: 592
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: Any way to tell if a world is newly generated?

by Mantar » Post

Map_meta.txt is created immediately, but env_meta.txt and map.sqlite do not exist on the first run of a world, so that will work! Kind of a kludge, but sometimes you gotta code what you gotta code.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Any way to tell if a world is newly generated?

by Linuxdirk » Post

Mantar wrote:
Wed Jan 12, 2022 19:51
I need to be able to detect this because as soon as the user enables the new biomes in the settings menu, it'll be global and affect every world loaded from then on, unless I can spot the old worlds and disable it before loading.
It should not need global settings that affect all worlds regardless of the mod being enabled or not. This is utterly bad design and should be altered in a way that it does not affect all worlds. Like mod-specific settings or even world-specific configuration.

User avatar
rubenwardy
Moderator
Posts: 6978
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Any way to tell if a world is newly generated?

by rubenwardy » Post

gametime is the number of seconds since the world was created. This is in real life seconds, and is independent of time speed. When the world starts up, you should check gametime and if it's less than a few seconds it's a new world

Something like this:

Code: Select all

local storage = minetest.get_mod_storage()
if minetest.get_gametime() < 10 then
	storage:set("enable_new_biomes", "true")
end

local enable_new_biomes = minetest.is_yes(storage:get("enable_new_biomes"))
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

User avatar
sorcerykid
Member
Posts: 1847
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: Any way to tell if a world is newly generated?

by sorcerykid » Post

I think the question comes up, are you wanting to check if it's a new world or a new map? If it is actually the latter, then simply looking for an existing map database is the cleanest way to go, because that file is not created until the map generator runs (which in most cases doesn't happen until a player enters the game). Consider: It's entirely possible for someone to have an existing world in which they want to reset the entire map by deleting the map database. This would account for such a scenario.

User avatar
Mantar
Member
Posts: 592
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: Any way to tell if a world is newly generated?

by Mantar » Post

Ruben: As I mentioned in the original post, get_gametime returned nil during the initialization phase. If I wait until the world loads to enable the new biomes, then mapgen may produce busted terrain again.

That's a good point, sorcerykid, I hadn't thought of the possibility of someone erasing the map but keeping everything else. I should perhaps check map.sqlite instead of env_meta.txt which I'm currently doing.

Linuxdirk: It's a game-specific setting, which is applied globally to all worlds subsequently generated. I have cobbled in a world-specific setting using the get/set_mapgen_setting hack that reads the game setting when a world is first created. It's an ugly pile of hacks, but the minetest settings infrastructure is kind of a hot mess. There is no official method to have a world-specific setting -- the PR to add one has been held back for a couple of years because the UI hasn't been figured out. (But if you ask me that rule applied evenly should mean ripping out the current settings UI, because it's pretty bad as is)
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

Post Reply

Who is online

Users browsing this forum: Andrey01 and 11 guests