結論
Java Code
java
public BiomeBase getBiomeBase(Location location) {
World bukkitWorld = location.getWorld();
if(bukkitWorld == null)
return null;
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
net.minecraft.world.level.World nmsWorld = ((CraftWorld) bukkitWorld).getHandle();
return nmsWorld.getNoiseBiome(x >> 2, y >> 2, z >> 2).a();
}
public MinecraftKey getBiomeKey(Location location) {
DedicatedServer dedicatedServer = ((CraftServer) Bukkit.getServer()).getServer();
IRegistry<BiomeBase> registry = dedicatedServer.aZ().d(Registries.at);
return registry.b(getBiomeBase(location));
}
Kotlin Code
Kotlin
private fun getBiomeBase(loc: Location): BiomeBase {
val bukkitWorld = loc.world
val x = loc.blockX
val y = loc.blockY
val z = loc.blockZ
val nmsWorld: net.minecraft.world.level.World = (bukkitWorld as CraftWorld).handle
return nmsWorld.getNoiseBiome(x shr 2, y shr 2, z shr 2).a()
}
fun getBiomeKey(loc: Location): MinecraftKey? {
val dedicatedServer = (Bukkit.getServer() as CraftServer).server
val registry: IRegistry<BiomeBase?> = dedicatedServer.aZ().d(Registries.at)
return registry.b(getBiomeBase(loc))
}
未来のためのメモ
- dedicatedServer.aZ()
- MinecraftServer.registryAccess()
- dedicatedServer.aZ().d()
- RegistryAccess.ownedRegistryOrThrow()
- Registries.at
- Registries.BIOME