I need to use code of CraftWorldInfo.vanillaBiomeProvider(); in my plugin, but I don't understand how to initialize it.
I found this code in 0760 patch - "0760-Expose-vanilla-BiomeProvider-from-WorldInfo.patch"
I was creating a class that extends CraftWorldInfo, but I got a "java.lang.CastClassException" error when I tried to use
I found this code in 0760 patch - "0760-Expose-vanilla-BiomeProvider-from-WorldInfo.patch"
Java:
@Override
public org.bukkit.generator.BiomeProvider vanillaBiomeProvider() {
final net.minecraft.world.level.levelgen.RandomState randomState;
if (vanillaChunkGenerator instanceof net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator noiseBasedChunkGenerator) {
randomState = net.minecraft.world.level.levelgen.RandomState.create(noiseBasedChunkGenerator.generatorSettings().value(),
registryAccess.lookupOrThrow(net.minecraft.core.registries.Registries.NOISE), getSeed());
} else {
randomState = net.minecraft.world.level.levelgen.RandomState.create(net.minecraft.world.level.levelgen.NoiseGeneratorSettings.dummy(),
registryAccess.lookupOrThrow(net.minecraft.core.registries.Registries.NOISE), getSeed());
}
final net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> biomeRegistry = CraftWorldInfo.this.registryAccess.registryOrThrow(net.minecraft.core.registries.Registries.BIOME);
final java.util.List<org.bukkit.block.Biome> possibleBiomes = CraftWorldInfo.this.vanillaChunkGenerator.getBiomeSource().possibleBiomes().stream()
.map(biome -> org.bukkit.craftbukkit.block.CraftBlock.biomeBaseToBiome(biomeRegistry, biome))
.toList();
return new org.bukkit.generator.BiomeProvider() {
@Override
public org.bukkit.block.Biome getBiome(final WorldInfo worldInfo, final int x, final int y, final int z) {
return org.bukkit.craftbukkit.block.CraftBlock.biomeBaseToBiome(biomeRegistry,
CraftWorldInfo.this.vanillaChunkGenerator.getBiomeSource().getNoiseBiome(x >> 2, y >> 2, z >> 2, randomState.sampler()));
}
@Override
public java.util.List<org.bukkit.block.Biome> getBiomes(final org.bukkit.generator.WorldInfo worldInfo) {
return possibleBiomes;
}
};
}
Java:
((CustomWorldInfo) worldinfo).customBiomeProvider().getBiome(worldInfo, x, y, z);