-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add minetest.generate_biomes and minetest.generate_biome_dust #14260
Conversation
If generate_ores/decorations is called after generate_biomes, the biome map is taken into account.
980178a
to
300b57c
Compare
I've rebased and adapted my code to mapgen thread feature. For the emerge thread I have forked sfan5's testcase. |
meta: (assigned due to reviewing the original pr) |
biome->depth_filler + | ||
noise_filler_depth->result[index], 0.0f); | ||
biome->depth_filler + (noise_filler_depth ? | ||
noise_filler_depth->result[index] : 0.0f), 0.0f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the noise_filler_depth ? noise_filler_depth->result[index] : 0.0f
does not need to be done more than once and should be moved into a variable in the parent scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, will fix that too, thanks
@@ -1557,6 +1560,10 @@ int ModApiMapgen::l_generate_ores(lua_State *L) | |||
mg.vm = checkObject<LuaVoxelManip>(L, 1)->vm; | |||
mg.ndef = emerge->ndef; | |||
|
|||
auto *bgen = getBiomeGen(L); | |||
if (bgen && bgen->getType() == BIOMEGEN_ORIGINAL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the type matter here? I don't see any casts to BiomeGenOriginal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure to completely understand what BiomeGenOriginal
is, so I replicated codes from other places. Is that some "biome system type" that is useless for now but is here because other biome systems could exist? or does it have another use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a simplified sense the BiomeGen
maps positions to biomes, but currently only one class implements this.
Unless you are doing something that is using methods specific to BiomeGenOriginal
then there is no reason to perform this manual type check.
{ | ||
NO_MAP_LOCK_REQUIRED; | ||
|
||
auto *emerge = getEmergeManager(L); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, dead code I forgot to remove, will fix that
why is this Y offset here? |
https://github.com/minetest/minetest/blob/300b57c047b0fec620ef5492626bbd91b23bc32e/src/mapgen/mapgen.cpp#L822-L829 Core mapgens do generate one extra row, but AFAIK most Lua mapgens don't do this, so they need to offset 1 node down. |
It would be good to also have "the full workflow" documented in lua_api.md |
This is an implementation detail that should IMO not be exposed to Lua. It should automatically subtract the offset. |
@gaelysam would it be possible for you to reopen this, with the new rapid release schedule? |
Rebase of #11953, fixes #8329, with some additions.
What it does?
This allows to use core biome generator for Lua mapgens, by adding two functions:
minetest.generate_biomes(vm, pos1, pos2, nobj_filler_depth)
to generate biome nodes in theVoxelManip
, and updateheatmap
,humiditymap
andbiomemap
like a core mapgen would do. A latterminetest.generate_ores
orminetest.generate_decorations
will take the biomemap into account, so that biome-dependant ores/decos will be placed on the right biome (which was previously not possible in a full Lua mapgen). It must be called during mapgen (register_on_generated
callback), and the X/Z extent ofpos1
-pos2
must match mapgen chunk size, for the buffers to work correctly. It is however possible (and I even recommend it) to offsetpos1.y
by -1 node to avoid border effects.minetest.generate_biome_dust(vm, pos1, pos2)
to generate dust nodes (snow...) above ground and decorations. Nodes abovepos2
must be generated, so I also recommend, if the mapgen does not overgenerate 1 node up/down, to offsetpos2.y
by -1 node.These functions are available in both server and emerge environments, like most mapgen-related functions.
As stated in the previous PR, they create a temporary
MapgenBasic
object and callMapgenBasic::generateBiomes()
orMapgenBasic::dustTopNodes()
. Class definition is modified to allow this.Why is it interesting/needed?
I believe Lua Mapgens have a large potential for Minetest, because they are able to adapt the terrain to a game's needs in a way core mapgens can't always offer. But sadly, they are often regarded as second-class mapgens, because of their relative slowness and incompatibility with most mods. They can take months to develop, but rarely end up deployed on servers or used by gamers for anything more than experiments. My PR goes in the direction to change that.
How to use?
I have made a modified version of
lvm_example
to test this. Do not hesitate to add biome mods (Ethereal, Variety...) to see how it reacts.To test on emerge environment, I have also made a fork of sfan5's flatgen.
If you want to add it to another mapgen, the full workflow is the following:
^ This PR + lvm_example + variety
Status
This PR is ready for review.