Page 1 of 1

Can I get some biome informations?

PostPosted: Thu Apr 07, 2016 10:37
by burli
Is it possible to get informations about the biome the player is currently in? Or can I just get humidity and temperature? In MC you can see if you are in the plains, swampland and so on

Re: Can I get some biome informations?

PostPosted: Thu Apr 07, 2016 12:54
by duane
burli wrote:Is it possible to get informations about the biome the player is currently in? Or can I just get humidity and temperature? In MC you can see if you are in the plains, swampland and so on


There doesn't seem to be any way to do that directly. What you can do is get the biome noises from settings and use them to calculate the temperature and humidity, and then use that to pick the biome. This is a bit complicated in most of the mapgens, except for valleys, in which it's extremely complicated.

Re: Can I get some biome informations?

PostPosted: Thu Apr 07, 2016 13:11
by burli
Hm, but the mapgen knows the biome when he generates the map, right? What if the mg stores something like "biome:plains" in the NodeMetaRef of each node? Or would that be to much data?

Re: Can I get some biome informations?

PostPosted: Thu Apr 07, 2016 15:43
by duane
burli wrote:Hm, but the mapgen knows the biome when he generates the map, right? What if the mg stores something like "biome:plains" in the NodeMetaRef of each node? Or would that be to much data?


You could do that. Of course, if the node moves, you'll have the wrong metadata on it, and again, you need an independent way to determine the values. Otherwise you'll have people carrying desert sand to the arctic with them, to keep warm.

If you make a function called by on_generate, it can copy the heat and humidity data wherever you like. At minimum, you'd have one number for every horizontal node you're storing (31K^2 for the whole map). Then you'd have to save that data somewhere and call it back when you need it. I don't think the size would be an issue so much as finding some way to store and retrieve it that wouldn't bog down the game.

I can't think of any easy way to do it.

Re: Can I get some biome informations?

PostPosted: Fri Apr 15, 2016 19:01
by burli
In voxel.lua from valley_c you are using biomemap. Can other mods can use this information too?

Re: Can I get some biome informations?

PostPosted: Sun Apr 17, 2016 04:18
by duane
burli wrote:In voxel.lua from valley_c you are using biomemap. Can other mods can use this information too?


Sure. Bear in mind that the function I use to translate the biome numbers was only added in the last six months, so it won't be available on everyone's version of minetest.

Re: Can I get some biome informations?

PostPosted: Sun Apr 17, 2016 15:30
by burli
How could a get_biome(pos) function look like? Can you give me a hint?

Re: Can I get some biome informations?

PostPosted: Tue Apr 19, 2016 01:30
by duane
burli wrote:How could a get_biome(pos) function look like? Can you give me a hint?


It's basically this:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
-- Create a table of biome ids, so I can use the biomemap.
if not valc.biome_ids then
   local i
   valc.biome_ids = {}
   for name, desc in pairs(minetest.registered_biomes) do
      i = minetest.get_biome_id(desc.name)
      valc.biome_ids[i] = desc.name
   end
end

local function get_biome(x, z)
   index_2d = (z - minp.z) * csize.y * csize.x + (x - minp.x)
   biome = valc.biome_ids[biomemap[index_2d]]
end


However, the biome map is only there during the generate function, so it's useless after you create the chunk.

Re: Can I get some biome informations?

PostPosted: Tue Apr 19, 2016 05:31
by paramat
Sometime i might add an API for getting biome at any time after mapgen, the core code is already in mgv7.

Re: Can I get some biome informations?

PostPosted: Tue Apr 19, 2016 05:38
by burli
paramat wrote:Sometime i might add an API for getting biome at any time after mapgen, the core code is already in mgv7.

That would be awesome. Than I don't need to make a mod.

Re: Can I get some biome informations?

PostPosted: Sun May 08, 2016 19:12
by burli
[quote="duane"]
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local function get_biome(x, z)
   index_2d = (z - minp.z) * csize.y * csize.x + (x - minp.x)
   biome = valc.biome_ids[biomemap[index_2d]]
end


What is csize? Couldn't find any reference

Re: Can I get some biome informations?

PostPosted: Mon May 09, 2016 03:58
by paramat
Chunksize, usually 80 but it can be different so get it from csize.x = maxp.x - minp.x + 1.
csize.x = csize.y = csize.z as our chunks are cubic.

Re: Can I get some biome informations?

PostPosted: Mon May 09, 2016 06:09
by burli
Thx

Re: Can I get some biome informations?

PostPosted: Mon May 09, 2016 16:33
by burli
duane wrote:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
   index_2d = (z - minp.z) * csize.y * csize.x + (x - minp.x)



I think this is wrong. Should be

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
index_2d = (z * csize.z + x)


With you equation I get huge numbers and the biome map always return nil

Re: Can I get some biome informations?

PostPosted: Mon May 09, 2016 18:57
by paramat
Yes duane's equation is wrong, should be:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
index_2d = (z - minp.z) * csize + (x - minp.x) + 1

But i'm not sure about the + 1 at the end, that might be needed as c++ tables index from 0 while lua tables index from 1.

Re: Can I get some biome informations?

PostPosted: Mon May 09, 2016 20:02
by burli
Ah, you are calculating the absolute world coordinate. I just calculate the relative coordinate inside the the chunk