Post your mapgen questions here (modding or engine)

FaceDeer
Member
Posts: 506
Joined: Sat Aug 29, 2015 19:01
GitHub: FaceDeer

Re: Post your mapgen questions here (modding or engine)

by FaceDeer » Post

Extex wrote:How would I make a mapgen that is entirely large caves like at -700 in Minetest game
All the way up and all the way down
I'd start with a singlenode mapgen that fills the universe with stone, and then use a lua mapgen to carve out the caverns. You can find the noise parameters used by the existing mapgens in the root minetest.conf.example file, look for mgv5_np_cavern, mgv7_np_cavern and carpathian_np_cavern. Wherever the noise value is above the corresponding cavern_threshold value the stone gets replaced with air.

If you want the small twisting connecting tunnels too, I'm not sure how to recreate those off the top of my head but they use a combination of two noise fields, np_cave1 and np_cave2. intersecting might be a good mod to look at for how to make tunnels out of noises, I don't know if this is exactly how the default mapgens do it but what this mod produces looks similar at a glance.

If you'd like to populate your underground game with farmable fungi for food and wood, you may find some useful bits to scavenge out of the DF Caverns mod. If I may self-promote slightly. :) You might also want to use the "subterrane" mod that dfcaverns uses for its caves, which is intended as a utility mod for creating large caverns with decor. Probably overkill if you just want hollow spaces without full-blown biomes and stuff though.

User avatar
duane
Member
Posts: 1715
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r
Location: Oklahoma City
Contact:

Re: Post your mapgen questions here (modding or engine)

by duane » Post

Extex wrote:How would I make a mapgen that is entirely large caves like at -700 in Minetest game
All the way up and all the way down
You know, of course, that the easiest way to do this would just be to define the spawn as some big cave, 20km down or so. That way you don't have to use a slow, lua mapgen. Anyone who manages to climb/dig 20km to the surface probably deserves to get there. Or you could erase all the biomes and make the surface just as barren as any cave. : )
Believe in people and you don't need to believe anything else.

User avatar
Extex
Member
Posts: 244
Joined: Wed Mar 14, 2018 23:14
GitHub: Extex101
In-game: Extex

Re: Post your mapgen questions here (modding or engine)

by Extex » Post

OK sounds simple enough for me to do.
XD but the more I think about it the more complicated it becomes...
How would I fill the entire world with one node?
And how do I fill the noise parameters with air?
Creator of jelys_pizzaria and motorbike, and player of persistent kingdoms. RIP

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Post your mapgen questions here (modding or engine)

by sirrobzeroone » Post

Extex, Try this simple mapgen from Burli - its back on page 4 or 5 of this thread - helped me get my head around simple 2d noise mapgen:
viewtopic.php?f=47&t=15272&start=100#p235607

then this example from Paramat on 3d noise usage:
paramat wrote: Due to this cleverness the mod is not suitable as a simple introduction to Lua mapgen coding, for that see viewtopic.php?f=18&t=19836


single node is inbuilt into minetest, you can override/use it using this in your lua code right near the top

Code: Select all

minetest.set_mapgen_params({mgname = "singlenode"})
This whole thread has some really useful info init so definitely worth a read from page1 to here.

User avatar
Extex
Member
Posts: 244
Joined: Wed Mar 14, 2018 23:14
GitHub: Extex101
In-game: Extex

Re: Post your mapgen questions here (modding or engine)

by Extex » Post

OK I tried inverting the example you gave me
Air to stone
Stone to air
Using the parameters for caverns
But it doesn't come out 3-dimensional just has an endless Abyss
Any tips?
Creator of jelys_pizzaria and motorbike, and player of persistent kingdoms. RIP

User avatar
duane
Member
Posts: 1715
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r
Location: Oklahoma City
Contact:

Re: Post your mapgen questions here (modding or engine)

by duane » Post

Believe in people and you don't need to believe anything else.

ShadMOrdre
Member
Posts: 1118
Joined: Mon Dec 29, 2014 08:07
Location: USA

Re: Post your mapgen questions here (modding or engine)

by ShadMOrdre » Post

duane,

Thanks for pointing out those resources. I've been looking a basic mapgen, and I think burli's might make a good basic start.

Somewhere in those threads, someone mentioned an idea to make an on_generated wrapper function. I get the impression that Kilarin does something similar to this for Realms. I haven't looked at his code, yet. But I am wondering, can an on_generated function wrapper be coded in such a way so as to allow the calls to be queued and sorted. I'd like to be able to specify the order in which the calls actually get processed, or combine them in a way that the code is essentially added to an ordered queue.

The ordering is important to ensure that on_gen calls setting up biome data would get called before on_gen calls setting up ore or decoration data, if that makes sense.

Ideally, an order of operations would be:
Generate Terrain
Erode Terrain
Apply Biomes
Generate Ores
Carve Rivers / Place Lakes
Add Decorations
Add Towns / Villages / Other schematics
All other on_gen calls, sorted in a meaningful, non conflicting way. Order here is really determined by the actions being done, and are as needed.

Shad

User avatar
duane
Member
Posts: 1715
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r
Location: Oklahoma City
Contact:

Get the Minimum of a Chunk

by duane » Post

I want to get the minimal and maximal position of a mapchunk.
This should work:

Code: Select all

local pos = vector.new(x, y, z)
local chunksize = tonumber(minetest.settings:get("chunksize") or 5)
local chunk_offset = math.floor(chunksize / 2) * 16;
local csize = { x=chunksize * 16, y=chunksize * 16, z=chunksize * 16 }
local chunk = vector.floor(vector.divide(vector.add(pos, chunk_offset), csize))
local minp = vector.add(vector.multiply(chunk, 80), -chunk_offset)
local maxp = vector.add(minp, chunksize - 1)
This is not the most efficient way, but since you only have to do this once for an entire chunk, it shouldn't matter.
Believe in people and you don't need to believe anything else.

User avatar
TalkLounge
Member
Posts: 324
Joined: Sun Mar 26, 2017 12:42
GitHub: TalkLounge
In-game: TalkLounge
Location: Germany

Re: Post your mapgen questions here (modding or engine)

by TalkLounge » Post

Thank you very much, duane. I very appreciate it.

And your code is nearly correct, except this, but I found the fallacy. Should be:

Code: Select all

local maxp = vector.add(minp, (chunksize * 16) - 1)
So this function works very well

Code: Select all

local function mapgen_min_max(pos)
	pos = vector.round(pos)
	local chunksize = tonumber(type(minetest.settings) ~= "nil" and minetest.settings:get("chunksize") or minetest.setting_get("chunksize")) or 5
	local chunk_offset = math.floor(chunksize / 2) * 16
	local csize = {x = chunksize * 16, y = chunksize * 16, z = chunksize * 16}
	local chunk = vector.floor(vector.divide(vector.add(pos, chunk_offset), csize))
	local minp = vector.add(vector.multiply(chunk, 80), -chunk_offset)
	local maxp = vector.add(minp, (chunksize * 16) - 1)
	return minp, maxp
end
Updated my exschem mod. Credits are given. Thanks duane.
Subgames Server: Sky World Subgames German Survival Server: Wildes Land 2 E-Mail: talklounge@yahoo.de

User avatar
Kilarin
Member
Posts: 894
Joined: Mon Mar 10, 2014 00:36
GitHub: Kilarin

Re: Post your mapgen questions here (modding or engine)

by Kilarin » Post

the api says about biomes heat and humidity points:
-- Heat and humidity have average values of 50, vary mostly between
-- 0 and 100 but can exceed these values.
Does anyone know by about how much it exceeds it? Just trying to figure out how much extra coverage the biomes on the outer edges of the 0-1 voronoi diagram get.

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your mapgen questions here (modding or engine)

by paramat » Post

Extex wrote:How would I make a mapgen that is entirely large caves like at -700 in Minetest game
All the way up and all the way down
it's a good idea to avoid using a lua mod for performance and server lag reasons.
Singlenode can fill a world with stone, but does not have any cave creation code.
So the best way is to use mapgen settings to modify a core mapgen that has cave generation.

The core mapgens with massive caverns are: v5, v7, valleys, carpathian.
The fastest mapgen is the one with fewest 3D noises, this will be v7 with mountains and rivers disabled, it will then have no 3D noises used.

Modify the 'mgv7_np_terrain_base' and 'mgv7_np_terrain_alt' noise parameters to set all terrain surface to y = 32000, this will fill the world with stone.
Set 'mgv7_large_cave_depth', 'mgv7_lava_depth' and 'mgv7_cavern_limit' to 32000 to have the mid-size caves, lava caves and massive caverns throughout the world.
Importantly, 'static_spawnpoint' must be set to some reasonable point, like 0,0,0, otherwise a crash occurs (due to spawning code, i need to fix this). Of course, you will spawn buried in stone.

So select v7 and use these settings in .conf (or set them in 'all settings') when creating a new world (tested):

Code: Select all

static_spawnpoint = 0,0,0
mgv7_spflags = nomountains,noridges,nofloatlands,caverns
mgv7_large_cave_depth = 32000
mgv7_lava_depth = 32000
mgv7_cavern_limit = 32000
mgv7_np_terrain_base = {
    offset      = 32000,
    scale       = 0,
    spread      = (600, 600, 600),
    seed        = 82341,
    octaves     = 5,
    persistence = 0.6,
    lacunarity  = 2.0,
    flags       = eased
}
mgv7_np_terrain_alt = {
    offset      = 32000,
    scale       = 0,
    spread      = (600, 600, 600),
    seed        = 5934,
    octaves     = 5,
    persistence = 0.6,
    lacunarity  = 2.0,
    flags       = eased
}

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your mapgen questions here (modding or engine)

by paramat » Post

Kilarin wrote:the api says about biomes heat and humidity points:
-- Heat and humidity have average values of 50, vary mostly between
-- 0 and 100 but can exceed these values.
Does anyone know by about how much it exceeds it? Just trying to figure out how much extra coverage the biomes on the outer edges of the 0-1 voronoi diagram get.
The default noise parameters for heat and humidity are 3 'octaves', 0.5 'persistence'.
The first octave outputs a raw value of -1 to 1, and each additional octave is 0.5 as large as the previous.
So the maximum value of the raw noise is 1 + 1 * 0.5 + 1 * 0.5 * 0.5 = 1.75. Variation is -1.75 to 1.75.
Multiply by 'scale' (50) to get the actual variation: -87.5 to 87.5.
This variation is either side of 'offset' (50), so the range of output is 50 - 87.5 to 50 + 87.5, -37.5 to 137.5.

But remember, the more extreme values occur more rarely.

User avatar
Kilarin
Member
Posts: 894
Joined: Mon Mar 10, 2014 00:36
GitHub: Kilarin

Re: Post your mapgen questions here (modding or engine)

by Kilarin » Post

So -37.5 to 137.5, and since it goes negative as well as positive, its an equal distribution around the diagram. heat/humidity points who's voronoi region (is that the correct term?) do not touch the edge of the diagram are the only ones that don't get extended.

thank you, and thank you for the very nice and detailed explanation on calculating noise range.

Is there a preferred/favorite tool for viewing voronoi distributions? I'm playing around with this one right now: http://alexbeutel.com/webgl/voronoi.html

To see the default game distribution (ignoring the overage discussed above) use the values width=1000, height=1000, cone=1000
{"sites":[0,730, 0,400, 250,700, 200,350, 500,350, 450,700, 600,680, 920,160, 600,0, 400, 0, 890,420, 860,650],"queries":[]}

But THIS one may be better? http://www.raymondhill.net/voronoi/rhill-voronoi.html
Last edited by Kilarin on Sun Jul 28, 2019 22:30, edited 1 time in total.

User avatar
Skamiz Kazzarch
Member
Posts: 613
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: Post your mapgen questions here (modding or engine)

by Skamiz Kazzarch » Post

This:
viewtopic.php?f=14&t=20101
might be quite interesting for you.

User avatar
Kilarin
Member
Posts: 894
Joined: Mon Mar 10, 2014 00:36
GitHub: Kilarin

Re: Post your mapgen questions here (modding or engine)

by Kilarin » Post

YES!!! thank you!

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Post your mapgen questions here (modding or engine)

by sirrobzeroone » Post

I'm not even sure what Im asking here so if this comes across as a bit jumbled I apologies.

I have a full custom map gen working using single node and it currently populates with stone, water, sand, grass, air and lava.

I've been reading over the biome API and if I understand correctly it uses essentially 2 random 2d noise maps, one for heat and one for humidity and a voronoi diagram to assign biomes to a map.

Assuming I've wrapped my head around that correctly, wouldn't this mean biomes are placed fairly randomly? I could end up with snow next to desert (barring rarity etc as per voronoi diagram). Is there anyway to produce a more natural environment? eg colder as you go higher into the mountains, different environment on the coastal area's etc. I could probably manipulate the noise maps for heat and humidity and then use the standard biome api to get the desired effect (assuming I can add some form of weighting by height) or am I better just going from scratch and ignoring the biome api completely?

I'd imagine there maybe performance advantages to using the biome api as I would guess it's tied into the underlying C code.

If I do use the biome API am I reading right that I'd just generate my terrain using stone, air, water and the biome api will populate in the correct elements depending on how they have been configured?

Thanks again for any help

User avatar
duane
Member
Posts: 1715
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r
Location: Oklahoma City
Contact:

Re: Post your mapgen questions here (modding or engine)

by duane » Post

sirrobzeroone wrote:Assuming I've wrapped my head around that correctly, wouldn't this mean biomes are placed fairly randomly? I could end up with snow next to desert (barring rarity etc as per voronoi diagram).
They're random in the sense that there's no logic behind them -- what you get in any given area could be any biome that matches the altitude limits. However, since they're based on perlin noise, you won't generally get immediate transitions from very hot to very cold. Changes will be more gradual.
Is there anyway to produce a more natural environment? eg colder as you go higher into the mountains, different environment on the coastal area's etc.
Absolutely. My experimental mapgen makes the temperature vary in a predictable manner as you go north and south, and the temperature goes down as you gain altitude, adding snow caps to mountains. (You can do something similar by limiting the warmer biomes to lower altitudes, with the y_max setting.)
I could probably manipulate the noise maps for heat and humidity and then use the standard biome api to get the desired effect (assuming I can add some form of weighting by height) or am I better just going from scratch and ignoring the biome api completely?

I'd imagine there maybe performance advantages to using the biome api as I would guess it's tied into the underlying C code.

If I do use the biome API am I reading right that I'd just generate my terrain using stone, air, water and the biome api will populate in the correct elements depending on how they have been configured?
You can't use the game's biome/decoration code with a lua mapgen. All of the game's decorating gets done before your lua gets executed, so if you want to program in lua, you have to at least partly duplicate the biome code. Realms is a good example of this.

However, it's not all that difficult to make your mapgen in C, basing it on the existing mapgens. (Flat is a good place to start.) Then you get to use the builtin biome/decoration code for free. At that point, your only problem is distributing your mapgen. Lua mods are easy for people to install. If your mapgen is in C, someone will have to compile the game with it, but if it's a good mapgen, you might get it added to the official game.
Believe in people and you don't need to believe anything else.

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your mapgen questions here (modding or engine)

by paramat » Post

In the core 'singlenode' mapgen the Biome API doesn't even get used, so everything must be coded in a Lua mapgen.

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Post your mapgen questions here (modding or engine)

by sirrobzeroone » Post

Ahh thanks paramat that clears that up...from scratch it is.

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Post your mapgen questions here (modding or engine)

by sirrobzeroone » Post

So I'm a little stuck, I've essentially got a nice little volcanic island, lava tube, some grass and sand etc (see below), scales up and down between 160>>31000 size map fine with the peak at about 7500meters when map size is at 31000 (took some jiggling and alignments not 100% perfect at all sizes). I'm using an overlay of custom logarithmic decay noise for the volcano (chopped near the top) and a S shaped curve for the beach down to the ocean floor, both are octogons in nature so I don't need to generate and store full image map just a 2d profile along 2 of the axis's. Not sure thats the most effecient way to do it but I wanted control on volcano shape etc...anyways on with were Im stuck.

However I'm a little unsure how to go about making surface soil a certain depth, so for example is there an example somewhere that shows how to make soil say depth=4 deep then stone. I'm guessing for ores etc I can use abms. rivers likewise I'm bit stumped on as I'm not sure how to make essentially spiderweb shaped noise? Are there known settings for that? I tried digging through valleys and carthagian but it's just a little to jumbled together and difficult to isolate out specific code chunks to learn from. Also how do I turn the blasted clouds off without touching the conf file or at least move them around relative to volcano size.....

island map size 300x300 below
Image

Thanks for the help again :)
Attachments
screenshot_20190812_190751.png
screenshot_20190812_190751.png (861.68 KiB) Viewed 1024 times

User avatar
sirrobzeroone
Member
Posts: 593
Joined: Mon Jul 16, 2018 07:56
GitHub: sirrobzeroone
Contact:

Re: Post your mapgen questions here (modding or engine)

by sirrobzeroone » Post

Just found this from yourself paramat so ill have a look at this re my rivers question..always the way find it after you post a question

viewtopic.php?f=11&t=9210
https://github.com/paramat/riverdev

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your mapgen questions here (modding or engine)

by paramat » Post

Don't use ABMs for mapgen, ABMs are very intensive, avoid if at all possible.

There's an API called 'minetest.generate_ores()' that will generate registered ores in the Lua voxelmanip, you should use that for performance.
There's similar API for placing registered decorations into a LVM.
See https://github.com/paramat/planets/blob ... t.lua#L419
These are parts of the Biome API usable in a Lua mapgen running in singlenode mapgen. However you must place the biome surface nodes (dirt, grass, sand etc.) in Lua.

I'm not sure how to produce a 'spiderweb' type pattern (assuming you mean a random lattice).
In my latest core mapgen experiment i am using 2 superimposed patterns, each pattern being the standard mgv7 river generation: Place river where math.abs(2Dnoise) < 0.05 (this number defines river width).
Superimposing 2 patterns creates more of a network, see map here https://github.com/minetest/minetest/pu ... -249410152

Your mapgen looks good.

User avatar
Wuzzy
Member
Posts: 4786
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy
Contact:

Re: Post your mapgen questions here (modding or engine)

by Wuzzy » Post

How do I replicate the v6 heat/humidity noises?
So that I can grab the correct value with get_2d, like with any other perlin noise.

I've been trying all day now by replicating the code from the engine and using minetest.get_mapgen_noiseparams, but to no avail. It seems I always get the wrong heat/humidity values.

Here's a mod I have written:

Code: Select all

local S = minetest.get_translator("debug_biomeinfo")

local mg_name = minetest.get_mapgen_setting("mg_name")
local seed = tonumber(minetest.get_mapgen_setting("seed")) or 0
local chunksize = tonumber(minetest.get_mapgen_setting("chunksize")) or 5
local MAP_BLOCKSIZE = 16
local csize = chunksize * MAP_BLOCKSIZE

local debug_biomeinfo = {}
debug_biomeinfo.playerhuds = {}
debug_biomeinfo.settings = {}
debug_biomeinfo.settings.hud_pos = { x = 0.5, y = 0 }
debug_biomeinfo.settings.hud_offset = { x = 0, y = 15 }
debug_biomeinfo.settings.hud_alignment = { x = 0, y = 0 }

local set = tonumber(minetest.settings:get("debug_biomeinfo_hud_pos_x"))
if set then debug_biomeinfo.settings.hud_pos.x = set end
set = tonumber(minetest.settings:get("debug_biomeinfo_hud_pos_y"))
if set then debug_biomeinfo.settings.hud_pos.y = set end
set = tonumber(minetest.settings:get("debug_biomeinfo_hud_offset_x"))
if set then debug_biomeinfo.settings.hud_offset.x = set end
set = tonumber(minetest.settings:get("debug_biomeinfo_hud_offset_y"))
if set then debug_biomeinfo.settings.hud_offset.y = set end
set = minetest.settings:get("debug_biomeinfo_hud_alignment")
if set == "left" then
	debug_biomeinfo.settings.hud_alignment.x = 1
elseif set == "center" then
	debug_biomeinfo.settings.hud_alignment.x = 0
elseif set == "right" then
	debug_biomeinfo.settings.hud_alignment.x = -1
end

local o_lines = 6 -- Number of lines in HUD

-- Checks whether a certain debug_biomeinfo tool is “active” and ready for use
function debug_biomeinfo.tool_active(player, item)
	-- Requirement: player carries the tool in the hotbar
	local inv = player:get_inventory()
	local hotbar = player:hud_get_hotbar_itemcount()
	for i=1, hotbar do
		if inv:get_stack("main", i):get_name() == item then
			return true
		end
	end
	return false
end

function debug_biomeinfo.init_hud(player)
	local name = player:get_player_name()
	debug_biomeinfo.playerhuds[name] = {}
	for i=1, o_lines do
		debug_biomeinfo.playerhuds[name]["o_line"..i] = player:hud_add({
			hud_elem_type = "text",
			text = "",
			position = debug_biomeinfo.settings.hud_pos,
			offset = { x = debug_biomeinfo.settings.hud_offset.x, y = debug_biomeinfo.settings.hud_offset.y + 20*(i-1) },
			alignment = debug_biomeinfo.settings.hud_alignment,
			number = 0xFFFFFF,
			scale = { x = 100, y = 20 },
		})
	end
end

local mgv6_perlin_biome, mgv6_perlin_humidity

local MGV6_FREQ_HOT = 0.4
local MGV6_FREQ_SNOW = -0.4
local MGV6_FREQ_TAIGA = 0.5
local MGV6_FREQ_JUNGLE = 0.5
local BT_NORMAL = "Normal"
local BT_TUNDRA = "Tundra"
local BT_TAIGA = "Taiga"
local BT_DESERT = "Desert"
local BT_JUNGLE = "Jungle"
local v6_flags_str = minetest.get_mapgen_setting("mgv6_spflags")
if v6_flags_str == nil then
	v6_flags_str = ""
end
local v6_flags = string.split(v6_flags_str)
local v6_use_snow_biomes = true
local v6_use_jungles = true
-- TODO: Implement biome blend.
-- Currently we ignore biome blend in our calculations.
local v6_use_biome_blend = false
for f=1, #v6_flags do
	local flag = v6_flags[f]:trim()
	if flag == "nojungles" then
		v6_use_jungles = false
	end
	if flag == "jungles" then
		v6_use_jungles = true
	end
	if flag == "nobiomeblend" then
		v6_use_biome_blend = false
	end
	if flag == "biomeblend" then
-- TODO
--		v6_use_biome_blend = true
	end
	if flag == "nosnowbiomes" then
		v6_use_snow_biomes = false
	end
	if flag == "snowbiomes" then
		v6_use_snow_biomes = true
	end
end
local v6_freq_desert = tonumber(minetest.get_mapgen_setting("mgv6_freq_desert") or 0.45)

local NOISE_MAGIC_X = 1619
local NOISE_MAGIC_Y = 31337
local NOISE_MAGIC_Z = 52591
local NOISE_MAGIC_SEED = 1013
local noise2d = function(x, y, seed)
	-- TODO: implement noise2d function for biome blend
	return 0
--[[
	local n = (NOISE_MAGIC_X * x + NOISE_MAGIC_Y * y
	+ NOISE_MAGIC_SEED * seed) & 0x7fffffff;
	n = (n >> 13) ^ n;
	n = (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff;
	return 1.0 - n / 0x40000000;
]]
end

function debug_biomeinfo.guess_v6_biome(biomepos)
	if not mgv6_perlin_biome or not mgv6_perlin_humidity then
		return "???"
	end
	local d = mgv6_perlin_biome:get_2d(biomepos)
	local h = mgv6_perlin_humidity:get_2d(biomepos)

	if (v6_use_snow_biomes) then
		local blend
		if v6_use_biome_blend then
			blend = noise2d(biomepos.x, biomepos.y, seed) / 40
		else
			blend = 0
		end

		if (d > MGV6_FREQ_HOT + blend) then
			if (h > MGV6_FREQ_JUNGLE + blend) then
				return "BT_JUNGLE (1)"
			end
			return "BT_DESERT (2)"
		end
		if (d < MGV6_FREQ_SNOW + blend) then
			if (h > MGV6_FREQ_TAIGA + blend) then
				return "BT_TAIGA (3)"
			end
			return "BT_TUNDRA (4)"
		end
		return "BT_NORMAL (5)"
	end

	if (d > v6_freq_desert) then
		return "BT_DESERT (6)"
	end

	if ((v6_use_biome_blend) and (d > v6_freq_desert - 0.10) and
			((noise2d(biomepos.x, biomepos.y, seed) + 1.0) > (v6_freq_desert - d) * 20.0)) then
		return "BT_DESERT (7)"
	end

	if ((v6_use_jungles) and (h > 0.75)) then
		return "BT_JUNGLE (8)"
	end

	return "BT_NORMAL (9)"
end

function debug_biomeinfo.update_hud_displays(player)
	if mg_name == "v6" then
		if not mgv6_perlin_biome then
			local np_biome = minetest.get_mapgen_setting_noiseparams("mgv6_np_biome")
			np_biome.spread.x = np_biome.spread.x * (csize + 2 * MAP_BLOCKSIZE)
			np_biome.spread.y = np_biome.spread.y * (csize + 2 * MAP_BLOCKSIZE)
			if np_biome then
				mgv6_perlin_biome = minetest.get_perlin(np_biome)
			end
		end
		if not mgv6_perlin_humidity then
			local np_humidity = minetest.get_mapgen_setting_noiseparams("mgv6_np_humidity")
			np_humidity.spread.x = np_humidity.spread.x * (csize + 2 * MAP_BLOCKSIZE)
			np_humidity.spread.y = np_humidity.spread.y * (csize + 2 * MAP_BLOCKSIZE)
			if np_humidity then
				mgv6_perlin_humidity = minetest.get_perlin(np_humidity)
			end
		end
	end
	local name = player:get_player_name()
	local has_debug_biomeinfo = true

	local str_temp, str_humi, str_biome, str_temp_v6, str_humi_v6, str_biome_v6 = "", "", "", "", "", ""
	local pos = player:get_pos()
	if has_debug_biomeinfo then
		do
			local temp = minetest.get_heat(pos)
			if temp == nil then
				temp = "???"
			end
			str_temp = S("Temperature: @1", tostring(temp))
			local humi = minetest.get_humidity(pos)
			if humi == nil then
				humi = "???"
			end
			str_humi = S("Humidity: @1", tostring(humi))
			local bdata = minetest.get_biome_data(pos)
			local bname, bid
			if bdata == nil then
				str_biome = S("Biome: ???")
			else
				bname = minetest.get_biome_name(bdata.biome)
				bid = bdata.biome
				str_biome = S("Biome: @1 (@2)", bname, tostring(bid))
			end
		end
		do
			local biomepos = { x = pos.x, y = pos.z }
			local temp, humi = "???", "???"
			if mgv6_perlin_biome then
				temp = mgv6_perlin_biome:get_2d(biomepos)
			end
			if mgv6_perlin_humidity then
				humi = mgv6_perlin_humidity:get_2d(biomepos)
			end
			str_temp_v6 = S("Temperature (v6): @1", temp)
			str_humi_v6 = S("Humidity (v6): @1", humi)
			str_biome_v6 = S("Biome (v6): @1", debug_biomeinfo.guess_v6_biome(biomepos))
		end
	end

	local strs = { str_temp, str_humi, str_biome, str_temp_v6, str_humi_v6, str_biome_v6 }
	local line = 1
	for i=1, o_lines do
		if strs[i] ~= "" then
			player:hud_change(debug_biomeinfo.playerhuds[name]["o_line"..line], "text", strs[i])
			line = line + 1
		end
	end
	for l=line, o_lines do
		player:hud_change(debug_biomeinfo.playerhuds[name]["o_line"..l], "text", "")
	end
end

minetest.register_on_newplayer(debug_biomeinfo.init_hud)
minetest.register_on_joinplayer(debug_biomeinfo.init_hud)

minetest.register_on_leaveplayer(function(player)
	debug_biomeinfo.playerhuds[player:get_player_name()] = nil
end)

local updatetimer = 0
minetest.register_globalstep(function(dtime)
	updatetimer = updatetimer + dtime
	if updatetimer > 0.1 then
		local players = minetest.get_connected_players()
		for i=1, #players do
			debug_biomeinfo.update_hud_displays(players[i])
		end
		updatetimer = updatetimer - dtime
	end
end)
This mod is supposed to display the heat/humidity/biome of the current player position.

It displays correct values for non-v6 mapgens, but for v6, it fails.
I'm guessing I got the scale of the noise wrong, or I forgot another calculation.

User avatar
duane
Member
Posts: 1715
Joined: Wed Aug 19, 2015 19:11
GitHub: duane-r
Location: Oklahoma City
Contact:

Re: Post your mapgen questions here (modding or engine)

by duane » Post

Wuzzy wrote:How do I replicate the v6 heat/humidity noises?
I don't suppose it has anything to do with the map seed? I figured out that the game was giving lua and C different seed values when you enter an alphabetic seed.
Believe in people and you don't need to believe anything else.

User avatar
paramat
Developer
Posts: 3700
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your mapgen questions here (modding or engine)

by paramat » Post

Mgv6 'biome' noise has a sneaky offset built into it, x is offset by 0.6 * spread, z by 0.2 * spread:
https://github.com/minetest/minetest/bl ... 6.cpp#L661
For the default noise parameters this means 150 node offset for x, 50 node offset for z.
My Meru mod reproduces mgv6 'biome' noise, the perlinmap minpoint is shifted relative to mapchunk minp:
https://github.com/paramat/meru/blob/0a ... t.lua#L143
'humidity' noise has no offset.

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests