Page 1 of 2

[mod] Biome library [git][biome_lib]

Posted: Sun Aug 09, 2015 14:33
by VanessaE

Vanessa's plants/biome library

This library's purpose is to allow other mods to add growing things to the map in a straightforward, simple manner. It contains all the core functions needed by mods and modpacks such as More Trees, Tiny Trees, Plantlife, and others.

Spawning of plants is optionally sensitive to the amount of available light, elevation, nearness to other nodes, plant-to-plant density, water depth, and a whole host of controls.

All objects spawned or generated using this mod use Perlin noise to stay within simple biomes, rather than just letting everything just spread around the map randomly.

This library also features a basic temperature map, which should blend in nicely with SPlizard's Snow Biomes mod (the same Perlin settings are used, with the assumption that the edge of a snow biome is 0° Centigrade).

Both mapgen-based spawning and ABM-based spawning is supported. The active growing code is strictly ABM-based. L-system trees can be spawned at mapgen time via the engine's spawn_tree() function.

It is aimed primarily at mapgen v6, and does not use the biome capabilities supplied by mapgen v7 (that will change some day). As such, if used in a mapgen v7 world, it'll work just fine but the temperature and humidity maps will not match up the way you might expect.

On server-exit, biome_lib will "hang" the server for a bit so that it can play out the rest of its deferred-generation log. This process may take a couple of minutes, and is done to prevent areas being left under-populated.

This mod was formerly known as "plants_lib" and used to be included in the Plantlife Modpack.

Dependencies: default from minetest_game

Recommends: Plantlife Modpack, More Trees

Download: https://github.com/mt-mods/biome_lib/ar ... master.zip
...or browse the code: https://github.com/mt-mods/biome_lib

License: LGPL 3.0 for code, CC-by-SA 4.0 for media and everything else.

API: This mod supplies a small number of very powerful functions. They are, briefly:

Code: Select all

biome_lib:register_generate_plant()
biome_lib:spawn_on_surfaces()
biome_lib:grow_plants()
biome_lib:find_valid_wall()
biome_lib:is_node_loaded()
For a complete description of these functions as well as several of the internal variables within the mod, see API.txt, included in the distribution archive, or view it online.

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Aug 09, 2015 17:40
by Clouds
Can i replace plant_lib with this and not have any issues?

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Aug 09, 2015 17:41
by VanessaE
Only if the mods that depended on plants_lib are updated accordingly.

I've already taken care of Moretrees and Plantlife modpack, and have sent pull requests to several others, some of whom have already updated.

Any mod that used plants_lib will at minimum need its depends.txt updated to reference "biome_lib" instead. Otherwise those mods will throw unresolved-dependency errors.

Mods that have not been properly updated beyond that bare minimum will throw deprecation warnings but should still work.

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Aug 09, 2015 17:44
by Clouds
Ah thank you. Can you tell me whats the true difference between the two there than its not in the plantlife modpack?

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Aug 09, 2015 17:46
by VanessaE
The two mods are identical, save for the various functions' namespaces. Hence the deprecation warning.

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Aug 09, 2015 17:50
by Clouds
Mhmm alright then I see no reason to update since my plant_lib is not even a week old.

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Aug 09, 2015 17:54
by VanessaE
Yeah, you can leave it be for now, until you decide you need to update something that depends on the change. In that case you will remove the entire plantlife modpack, download the latest git of it, and add biome_lib as a separate mod.

Re: [mod] Biome library [git][biome_lib]

Posted: Sat Aug 15, 2015 21:27
by VanessaE
Small update: fixed a typo in deprecated function call handler.

Re: [mod] Biome library [git][biome_lib]

Posted: Sat Nov 14, 2015 14:02
by afflatus
I have been trying to figure out some way of properly integrating biome_lib with v5 / v7 mapgen. Unfortunately they use different kinds of perlin noise and I can't see any way of directly retrieving temperature / humidity for a specific node. Ultimately this means I will have to deprecate biome_lib.register_generate_plant() in favour of minetest.register_decoration() and put up with the lack of subtlety. Having jungletrees and oranges spawn next to snow / tundra biomes isn't making me happy.

Is anyone else bothered by this or am I SOMO?

Re: [mod] Biome library [git][biome_lib]

Posted: Sat Nov 14, 2015 15:15
by VanessaE
I'm bothered by that as well, but I haven't really had much time to fiddle with it.

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Nov 15, 2015 00:57
by afflatus
In which case I'll persevere.
I'm also working on a mod of woodsoils to make use of the extra dirt_with_* nodes, which could be a good excuse for me to learn how to make a PR.

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Nov 15, 2015 04:21
by duane
afflatus wrote:I have been trying to figure out some way of properly integrating biome_lib with v5 / v7 mapgen. Unfortunately they use different kinds of perlin noise and I can't see any way of directly retrieving temperature / humidity for a specific node.
You can just use the heat and humidity maps. You access those the same way you would a 2D noise array.

Code: Select all

	local heatmap = minetest.get_mapgen_object("heatmap")
	local humiditymap = minetest.get_mapgen_object("humiditymap")
It's a lot more efficient if you're doing an entire chunk at a time, of course.

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Nov 15, 2015 14:12
by afflatus
duane wrote:You can just use the heat and humidity maps. You access those the same way you would a 2D noise array.
Surely only inside an on_generate() callback?

I can't immediately see how to pass the maps to biome_lib.perlin_temperature and biome_lib.perlin_humidity.
minetest.setting_get("mg_biome_np_heat") or ("mg_biome_np_humidity") returns a noise param string, which seems more useful, but would need parsing and converting - PerlinNoise takes four args: (seed, octaves, persistence, scale), so one of the big questions is how to get the spread / scale right.

Also the noise values need to be * -1 IIUC because mapgen and biome_lib use inverse values.

I am struggling because I don't have a deep enough understanding of Perlin noise, or the mechanics of map generation. So far I have managed to come up with a hacky workaround by trial and error which produces acceptable results. Any help in getting biome_lib and mapgen to sing from the same songsheet is gratefully received!

Edit: should I be looking at the points where noise1 and noise2 are defined?

Re: [mod] Biome library [git][biome_lib]

Posted: Mon Nov 16, 2015 15:37
by duane
afflatus wrote:
duane wrote:You can just use the heat and humidity maps. You access those the same way you would a 2D noise array.
Surely only inside an on_generate() callback?
Oh. I was thinking it was only used in generating chunks.

I haven't looked at the problem very long, but wouldn't this duplicate the v7 noises?

Code: Select all

v7_temperature = PerlinNoise({offset=50, scale=50, spread={x=750,y=750,z=750}, seed=5349, octaves=3, persist=0.5, lacunarity=2.0})
v7_humidity = PerlinNoise({offset=50, scale=50, spread={x=750,y=750,z=750}, seed=842, octaves=3, persist=0.5, lacunarity=2.0})
v7_temperature_blend = PerlinNoise({offset=0, scale=1.5, spread={x=8,y=8,z=8}, seed=13, octaves=2, persist=1, lacunarity=2.0})
v7_humidity_blend = PerlinNoise({offset=0, scale=1.5, spread={x=8,y=8,z=8}, seed=90003, octaves=2, persist=1, lacunarity=2.0})
Then just use this when you need the temperature/humidity.

Code: Select all

temp = v7_temperature.get2d(pos) + v7_temperature_blend.get2d(pos)
humidity = v7_humidity.get2d(pos) + v7_humidity_blend.get2d(pos)
I may be thinking of minetest.get_perlin instead of PerlinNoise, assuming they aren't identical. Of course as soon as someone changes their perlin noises in minetest.conf, all bets are off.

Edit: Note that this is supposed to give temperature in Fahrenheit (yuck) and humidity * 100.

Re: [mod] Biome library [git][biome_lib]

Posted: Mon Nov 16, 2015 17:41
by afflatus
OK, I don't want to duplicate the noise, I want to read the actual parameters, because as you rightly say, as soon as someone changes the mapgen params it will break. I doubt it is really necessary to include the *_blend noise. So long as the spread of values over the map roughly correlates to the biomes, this will work.

I also think the values fed to temp and humidity in your example would need to be * -1 as biome_lib, like splizzard's snow mod uses inverse values. That is unless you can use negative values for 'scale'.

So I think I just need to bite the bullet and figure out a way of unpacking the values from the noise params string returned by this:

Code: Select all

local np_temp = minetest.setting_get("mg_biome_np_heat") 
local np_humid = minetest.setting_get("mg_biome_np_humidity")
See also: viewtopic.php?f=7&t=9215#p198262 for a better explanation.

Re: [mod] Biome library [git][biome_lib]

Posted: Mon Nov 23, 2015 00:00
by afflatus
I came up with this, which seems to work in mg v7

Code: Select all

local temp_table = {}
local temp_string = minetest.setting_get("mg_biome_np_heat")
temp_string:gsub("%d+%.?%d*", function(c) table.insert(temp_table,c) end)

local temperature_seeddiff = temp_table[6] or 112
local temperature_octaves = temp_table[7] or 3
local temperature_persistence = temp_table[8] or 0.5
local temperature_scale = temp_table[3] or 150

local humid_table = {}
local humid_string = minetest.setting_get("mg_biome_np_humidity")
humid_string:gsub("%d+%.?%d*", function(c) table.insert(humid_table,c) end)

local humidity_seeddiff = humid_table[6] or 9130
local humidity_octaves = humid_table[7] or 3
local humidity_persistence = humid_table[8] or 0.5
local humidity_scale = humid_table[3] or 250
Testing it may take some time ...

Re: [mod] Biome library [git][biome_lib]

Posted: Tue Nov 24, 2015 02:42
by VanessaE
That's actually a lot simpler than I expected! I look forward to your pull request if it works out. :-)

Re: [mod] Biome library [git][biome_lib]

Posted: Tue Nov 24, 2015 13:04
by afflatus
Yep, well I'm still waiting to be slapped by some gotcha. ;-)

Mapgen testing is very slow and laborious, if anyone else fancies testing this out on a new map (especially mgv6) with default settings running a fairly vanilla Minetest Game (with plantlife / moretrees natch), I'd be really interested in some feedback. :-)

Re: [mod] Biome library [git][biome_lib]

Posted: Tue Feb 02, 2016 21:28
by DoyleChris
Do i need this enabled to run moretrees.

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Jan 29, 2017 15:10
by burli
How about mgv7 support? Any progress?

Edit: I don't think so. Still palm trees on cold beaches.

Image

Re: [mod] Biome library [git][biome_lib]

Posted: Sun Jan 29, 2017 22:35
by VanessaE
I haven't been working on this mod lately, but I'm open to reasonable pull requests. It DOES work fine on mapgen v7, it just doesn't take advantage of any mgv7-specific features or climate/biome info. There is the issue of moretrees causing shadows on the map, but that's an engine bug.

Re: [mod] Biome library [git][biome_lib]

Posted: Wed Jun 06, 2018 12:23
by VanessaE
This project has been moved to Gitlab.

Re: [mod] Biome library [git][biome_lib]

Posted: Sat Jun 16, 2018 18:59
by izzyb
Is there a known issue with biome_lib running in 0.5?

UPDATE: Never mind. Still getting segfault even after removing it...

Re: [mod] Biome library [git][biome_lib]

Posted: Tue Feb 04, 2020 08:14
by RobertBuilder
Severe bug in biome_lib with minetest 5.1.0 and v7 mapgen. This bug makes technic with biome_lib and moretrees useless.

To reproduce try to find e.g a rubber tree biome or a palm tree biome with
minetest 5.1.0 + biome_lib and moretrees on a v7 map. For instance palm trees will be spawned in the snow biome. I guess rubber trees will not be spawned at all.

It seems that the used minetest.get_biome_data's heat value is roughly degrees fahrenheit and the humidity value might be relative humidity so I suggest the following fix:

In init.lua line 87 replace

Code: Select all

local function get_biome_data(pos, perlin_fertile)
	local fertility = perlin_fertile:get2d({x=pos.x, y=pos.z})

	if type(minetest.get_biome_data) == "function" then
		local data = minetest.get_biome_data(pos)
		if data then
			return fertility, data.heat / 100, data.humidity / 100
		end
	end

	local temperature = biome_lib.perlin_temperature:get2d({x=pos.x, y=pos.z})
	local humidity = biome_lib.perlin_humidity:get2d({x=pos.x+150, y=pos.z+50})

	return fertility, temperature, humidity
end
with

Code: Select all

local function get_biome_data(pos, perlin_fertile)
	local function fahrenheit_to_biome_lib_temperature(temperature)
		return ((178-temperature)/95.5 - 1.0)
	end
	local function humidity_to_biome_lib_humidity(humidity)
		return (humidity/50.0 - 1.0)
	end

	local fertility = perlin_fertile:get2d({x=pos.x, y=pos.z})

	if type(minetest.get_biome_data) == "function" then
		local data = minetest.get_biome_data(pos)
		if data then
			return fertility, fahrenheit_to_biome_lib_temperature(data.heat), humidity_to_biome_lib_humidity(data.humidity)
		end
	end

	local temperature = biome_lib.perlin_temperature:get2d({x=pos.x, y=pos.z})
	local humidity = biome_lib.perlin_humidity:get2d({x=pos.x+150, y=pos.z+50})

	return fertility, temperature, humidity
end
Note:
This fix will not solve the "rubber tree problem" with technic, because the biome data of the moretrees mod needs rebalancing. But with this fix moretees biome data make more sense.

Re: [mod] Biome library [git][biome_lib]

Posted: Tue Feb 04, 2020 11:21
by VanessaE
Please submit this as a Merge Request against my Gitlab repository, and be sure the code will still work with mapgen v6 (i.e. auto-switch as needed). That mapgen is what this was designed for.