Jump to content

Getting Biome from Coords during SurfaceBuilder#buildSurface


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:


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:


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:


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.

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.

  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hey. I created shield mod like kaupenjoe did on his course but blocking animation doesn't work. Forge 1.20.1. Here's some information: Mod structure image and code: https://ibb.co/z5Y1G26 https://www.online-java.com/crhUHmPoJt
    • i was playing forge modded singleplayer server then i added optifine to mods but it crashed with optifine is there anything to do without deleting optifine  crash report: https://paste.ee/p/Z13LO
    • package com.projectmushroom.lavapotions.item; import java.util.List;   import com.projectmushroom.lavapotions.LavaPotions;   import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.stats.Stats; import net.minecraft.tags.FluidTags; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.boss.enderdragon.EnderDragon; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemUtils; import net.minecraft.world.item.Items; import net.minecraft.world.item.alchemy.PotionUtils; import net.minecraft.world.item.alchemy.Potions; import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult;   public class ReinforcedBottle extends Item { public ReinforcedBottle(Item.Properties p_40648_) { super(p_40648_); }   public InteractionResultHolder<ItemStack> use(Level p_40656_, Player p_40657_, InteractionHand p_40658_) { List<AreaEffectCloud> list = p_40656_.getEntitiesOfClass(AreaEffectCloud.class, p_40657_.getBoundingBox().inflate(2.0D), (p_40650_) -> { return p_40650_ != null && p_40650_.isAlive() && p_40650_.getOwner() instanceof EnderDragon; }); ItemStack itemstack = p_40657_.getItemInHand(p_40658_); if (!list.isEmpty()) { AreaEffectCloud areaeffectcloud = list.get(0); areaeffectcloud.setRadius(areaeffectcloud.getRadius() - 0.5F); p_40656_.playSound((Player)null, p_40657_.getX(), p_40657_.getY(), p_40657_.getZ(), SoundEvents.BOTTLE_FILL_DRAGONBREATH, SoundSource.NEUTRAL, 1.0F, 1.0F); p_40656_.gameEvent(p_40657_, GameEvent.FLUID_PICKUP, p_40657_.blockPosition()); return InteractionResultHolder.sidedSuccess(this.turnBottleIntoItem(itemstack, p_40657_, new ItemStack(Items.DRAGON_BREATH)), p_40656_.isClientSide()); } else { HitResult hitresult = getPlayerPOVHitResult(p_40656_, p_40657_, ClipContext.Fluid.SOURCE_ONLY); if (hitresult.getType() == HitResult.Type.MISS) { return InteractionResultHolder.pass(itemstack); } else { if (hitresult.getType() == HitResult.Type.BLOCK) { BlockPos blockpos = ((BlockHitResult)hitresult).getBlockPos(); if (!p_40656_.mayInteract(p_40657_, blockpos)) { return InteractionResultHolder.pass(itemstack); }   if (p_40656_.getFluidState(blockpos).is(FluidTags.LAVA)) { p_40656_.playSound(p_40657_, p_40657_.getX(), p_40657_.getY(), p_40657_.getZ(), SoundEvents.BOTTLE_FILL, SoundSource.NEUTRAL, 1.0F, 1.0F); p_40656_.gameEvent(p_40657_, GameEvent.FLUID_PICKUP, blockpos); return InteractionResultHolder.sidedSuccess(this.turnBottleIntoItem(itemstack, p_40657_,(new ItemStack(LavaPotions.REINFORCED_BOTTLE), .LAVA)), p_40656_.isClientSide()); } } return InteractionResultHolder.pass(itemstack); } } }   protected ItemStack turnBottleIntoItem(ItemStack p_40652_, Player p_40653_, ItemStack p_40654_) { p_40653_.awardStat(Stats.ITEM_USED.get(this)); return ItemUtils.createFilledResult(p_40652_, p_40653_, p_40654_); } }   This is what I have so far, it's pretty much just the waterbottle code but I'm just trying to figure out how to get it to pick up lava rather than water
    • I never started my own server manually but I follow every single step i saw in a youtube video.
  • Topics

  • Create New...

Important Information

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