How to get biome name from Biome object?

Started by mzage31 on

Topic category: Help with modding (Java Edition)

Last seen on 01:56, 3. Oct 2021
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to get biome name from Biome object?

I'm using MCreator 2021.2 to create a Mod that shows coordinates and current biome on the top of the screen. I found this mod batty-UI on GitHub but it operates on old versions of Minecraft and I want my mod to operate on version 1.16.5 of Minecraft.

It looks like there was a function defined as getBiomeName() inside the Biome class, But it appears to be removed. I want an equivalent to the following code in 1.16.5 version:

World _world = entity.world;
String _biome = "???";
BlockPos myBlock = new BlockPos(_x, _y, _z);
if(_world != null && _world.isBlockLoaded(myBlock)){
    Chunk myChunk = _world.getChunkFromBlockCoords(myBlock);
    _biome = myChunk.getBiome(myBlock, _world.getBiomeProvider()).getBiomeName();
}

This is the code I wrote, But it only works in single player:

World _world = entity.world;
String _biome = "???";
Biome biome = _world.getBiome(new BlockPos(_x, _y, _z));
if(biome != null){
    ResourceLocation regName = biome.getRegistryName();
    if(regName != null){ //getRegistryName() returns null in multiplayer mode
        _biome = regName.getPath();
        _biome = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, _biome);
    }
}

Also, this is the document I'm currently using, If there are any better documents out there, please let me know.

Last seen on 01:56, 3. Oct 2021
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I really need this to be…
Fri, 10/01/2021 - 20:56

I really need this to be working, Any help would be appreciated. Thanks in advance