Jump to content

Getting Biome from Coords during SurfaceBuilder#buildSurface


FrozenFarmer64

Recommended Posts

Hello all, I have been trying to access the biome for a given coordinate during chunk generation in SurfaceBuilder#buildSurface and have been running into some struggles. I have tried finding an instance of World to use the getBiome method, but the following attempts have not worked:

1) Using Minecraft.getInstance().world.getBiome. Occasionally Minecraft will crash under a nullPointerException, but even if there is no crash, the getBiome command will return PlainsBiome regardless of the entered coordinates.

2) Using IChunk#getWorldForge().getBiome. getWorldForge seems to always return null, as is discussed but not excatly resolved in this forum post.

3) I have also tried copying the getBiome method from FuzzedBiomeMagnifier#getBiome. This works okay, but there are odd blocks that will seemingly randomly return the wrong biome, which is causing some disruption. I have been using the following code for the BiomeManager.IBiomeReader and seed, which I think could possibly (but unlikely) be the problem:

public Biome getBiome(int x, int y, int z, IChunk chunkIn) {
		BiomeManager.IBiomeReader biomeReader = chunkIn.getBiomes();
		long seed = Minecraft.getInstance().world.getSeed();

        /* ... rest of the code here ... */
}

 

If anybody has any ideas or thoughts about this problem, I would appreciate the assistance. Thank you all!

Edited by FrozenFarmer64
Fixing a Typo
Link to comment
Share on other sites

1 hour ago, FrozenFarmer64 said:

Using Minecraft.getInstance().world.getBiome.

You're not allowed to reach across logical sides.

 

1 hour ago, FrozenFarmer64 said:

IChunk#getWorldForge()

It is a nullable method that only returns the current world if IChunk is an instance of Chunk. I'm pretty sure Chunk is not the instance of IChunk called when constructing a biome for the first time.

1 hour ago, FrozenFarmer64 said:

FuzzedBiomeMagnifier#getBiome

The noise would make sense as its supposed to MAGNIFY the biome being created and fudge the sides to more fluently transition in.

1 hour ago, FrozenFarmer64 said:

Minecraft.getInstance().world.getSeed();

Didn't I just mention this?

 

So question. If you're inside the SurfaceBuilder::buildSurface method, I believe it takes in a Biome as a parameter for the current biome. If so, why do you need to get the biome somewhere else? You're generating the surface for that specific chunk in that specific biome. If you're calling it to read from a different chunk, why?

  • Like 1
Link to comment
Share on other sites

Thank you for the help @ChampionAsh5357--the logical sides issue makes sense, and I didn't realize that getWorldForge defaulted to null for instances of ChunkPrimer.

 

 

For a second I thought that I was just being dumb about the Biome argument, but no, there is still an issue with that. The Biome parameter is always a reference to the custom biome which is being built, regardless of what the biome ACTUALLY is at the position (specifically, in the case of biome transitions, rivers, etc.). I was trying to determine what the "dominant" biome was at a position (i.e. the one that you get from World#getBiome). I can't think of any way to do this, however, without crossing over logical sides--any ideas on this would be incredibly helpful!

Link to comment
Share on other sites

25 minutes ago, FrozenFarmer64 said:

The Biome parameter is always a reference to the custom biome which is being built, regardless of what the biome ACTUALLY is at the position

So you're trying to access a RiverBiome, for example, while the surface of the biome being built. If the biome hasn't been built before, and the method is just getting called, the biome would be generated before or after your custom one. So, you're trying to access something that won't properly exist until the chunk is completely built. You would need to get a specific coordinate after the chunk has generated. I believe this is how biomes are generated.

  • Like 1
Link to comment
Share on other sites

Doesn't the function take in an x and z coordinate? If I go up, I find that the entire chunk is iterated through in NoiseChunkGenerator::generateSurface and passes the x and z coordinate of each block into the function. This means that the function does get called 256 times. It also gets the specific biome the surface generator is calling from at that coordinate.

  • Like 1
Link to comment
Share on other sites

Yes, the function does take in an x and a z coordinate, but my understanding of the function is that for chunks with multiple biomes, the registered surface builder is run across the entire chunk for EACH biome in the region, passing the Biome that the surface builder is registered under as the Biome parameter. I am fairly confident that the biome parameter doesn’t actually indicate the unique biome at the position, but rather the biome of the surface builder being ran. 

Link to comment
Share on other sites

7 minutes ago, FrozenFarmer64 said:

I am fairly confident that the biome parameter doesn’t actually indicate the unique biome at the position, but rather the biome of the surface builder being ran. 

I'm guessing you didn't even look at NoiseChunkGenerator::generateSurface. It calls WorldGenRegion::getBiome which gets a biome at a certain position. Then, Biome::buildSurface is called which passes the biome parameter to the SurfaceBuilder. The biome locations are already determined at this point or else it wouldn't be accessible.

  • Thanks 1
Link to comment
Share on other sites

Ah, yes, I see what you are saying and why I was confused—I tried outputting the biome parameter to console in my custom buildSurface method, and since it only output my custom biome, I assumed that there were just multiple passes of the method, one for each biome in the chunk. I don’t know why I just assumed that the entire chunk was being passed through...

 

Thank you so much for the assistance @ChampionAsh5357!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.