首页 > 解决方案 > 如何从 Biome 对象中获取生物群落名称?

问题描述

我正在使用MCreator 2021.2创建一个在屏幕顶部显示坐标和当前生物群落的 Mod。我在 GitHub 上找到了这个 mod batty-UI,但它在旧版本的 Minecraft 上运行,我希望我的 mod 在 Minecraft 1.16.5 版本上运行。

看起来getBiomeName()在 Biome 类中定义了一个函数,但它似乎被删除了。我想要一个等效于 1.16.5 版本中的以下代码:

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();
}

这是我写的代码,但它只适用于单人游戏:

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);
    }
}

另外,是我目前正在使用的文档,如果有更好的文档,请告诉我。

标签: javaminecraftminecraft-forge

解决方案


推荐阅读