[mod] Biome library [git][biome_lib]

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

[mod] Biome library [git][biome_lib]

by VanessaE » Post

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.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
Clouds
Member
Posts: 102
Joined: Sat Aug 01, 2015 01:58
In-game: Cloud

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

by Clouds » Post

Can i replace plant_lib with this and not have any issues?

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

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

by VanessaE » Post

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.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
Clouds
Member
Posts: 102
Joined: Sat Aug 01, 2015 01:58
In-game: Cloud

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

by Clouds » Post

Ah thank you. Can you tell me whats the true difference between the two there than its not in the plantlife modpack?

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

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

by VanessaE » Post

The two mods are identical, save for the various functions' namespaces. Hence the deprecation warning.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
Clouds
Member
Posts: 102
Joined: Sat Aug 01, 2015 01:58
In-game: Cloud

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

by Clouds » Post

Mhmm alright then I see no reason to update since my plant_lib is not even a week old.

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

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

by VanessaE » Post

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.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

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

by VanessaE » Post

Small update: fixed a typo in deprecated function call handler.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
afflatus
Member
Posts: 362
Joined: Tue Apr 01, 2014 19:47
GitHub: 0-afflatus
IRC: afflatus
In-game: afflatus
Location: Avalonia
Contact:

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

by afflatus » Post

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?
Grailtest is stirring ...

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

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

by VanessaE » Post

I'm bothered by that as well, but I haven't really had much time to fiddle with it.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
afflatus
Member
Posts: 362
Joined: Tue Apr 01, 2014 19:47
GitHub: 0-afflatus
IRC: afflatus
In-game: afflatus
Location: Avalonia
Contact:

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

by afflatus » Post

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.
Grailtest is stirring ...

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

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

by duane » Post

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.
Believe in people and you don't need to believe anything else.

User avatar
afflatus
Member
Posts: 362
Joined: Tue Apr 01, 2014 19:47
GitHub: 0-afflatus
IRC: afflatus
In-game: afflatus
Location: Avalonia
Contact:

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

by afflatus » Post

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?
Grailtest is stirring ...

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

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

by duane » Post

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.
Believe in people and you don't need to believe anything else.

User avatar
afflatus
Member
Posts: 362
Joined: Tue Apr 01, 2014 19:47
GitHub: 0-afflatus
IRC: afflatus
In-game: afflatus
Location: Avalonia
Contact:

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

by afflatus » Post

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.
Grailtest is stirring ...

User avatar
afflatus
Member
Posts: 362
Joined: Tue Apr 01, 2014 19:47
GitHub: 0-afflatus
IRC: afflatus
In-game: afflatus
Location: Avalonia
Contact:

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

by afflatus » Post

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 ...
Grailtest is stirring ...

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

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

by VanessaE » Post

That's actually a lot simpler than I expected! I look forward to your pull request if it works out. :-)
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
afflatus
Member
Posts: 362
Joined: Tue Apr 01, 2014 19:47
GitHub: 0-afflatus
IRC: afflatus
In-game: afflatus
Location: Avalonia
Contact:

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

by afflatus » Post

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. :-)
Grailtest is stirring ...

DoyleChris
Member
Posts: 265
Joined: Sat Jul 25, 2015 19:54
In-game: DoyleChris

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

by DoyleChris » Post

Do i need this enabled to run moretrees.

User avatar
burli
Member
Posts: 1643
Joined: Fri Apr 10, 2015 13:18

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

by burli » Post

How about mgv7 support? Any progress?

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

Image
Attachments
screenshot_20170129_171332.jpg
screenshot_20170129_171332.jpg (262.23 KiB) Viewed 63260 times

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

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

by VanessaE » Post

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.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

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

by VanessaE » Post

This project has been moved to Gitlab.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

izzyb
Member
Posts: 35
Joined: Thu May 07, 2015 22:41

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

by izzyb » Post

Is there a known issue with biome_lib running in 0.5?

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

RobertBuilder
New member
Posts: 4
Joined: Mon Feb 03, 2020 23:42

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

by RobertBuilder » Post

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.

User avatar
VanessaE
Moderator
Posts: 4655
Joined: Sun Apr 01, 2012 12:38
GitHub: VanessaE
IRC: VanessaE
In-game: VanessaE
Location: Western NC
Contact:

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

by VanessaE » Post

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.
You might like some of my stuff: Plantlife ~ More Trees ~ Home Decor ~ Pipeworks ~ HDX Textures (64-512px)

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Wuzzy and 10 guests