Referencing Custom Biomes
In addition to being able to keep references to your CustomBiomes
in your own code, BiomesAPI also provides a built-in RegisteredBiomes
that allows you to get a reference to your custom biomes just from a ResourceKey.
RegisteredBiomes exposes the following methods. The *Lazily variants return a Lazy that defers the lookup until first accessed.
get(ResourceKey): Returns the custom biome for the given resource key, ornullif none is registered.getOrThrow(ResourceKey): Returns the custom biome for the given resource key, or throwsUnknownBiomeExceptionif none is registered.getLazily(ResourceKey): A lazy version ofget— the lookup runs on first access and may resolve tonull.getOrThrowLazily(ResourceKey): A lazy version ofgetOrThrow. TheUnknownBiomeExceptionis thrown on first access if the biome is not registered.isRegistered(ResourceKey): Returnstrueif a biome with the given resource key is registered.isRegisteredLazily(ResourceKey): A lazy version ofisRegistered.iterator(): Returns an iterator over all registered custom biomes (RegisteredBiomesimplementsIterable<CustomBiome>).size(): Returns the number of registered custom biomes.isEmpty(): Returnstrueif no custom biomes are registered.
Example Usage
Section titled “Example Usage”import me.outspending.biomesapi.biome.RegisteredBiomes;
import me.outspending.biomesapi.biome.CustomBiome;
import me.outspending.biomesapi.registry.ResourceKey;
import me.outspending.biomesapi.wrapper.BiomeSettings;
import org.bukkit.plugin.java.JavaPlugin;
public class ExamplePlugin extends JavaPlugin {
@Override
public void onEnable() {
CustomBiome.builder()
.resourceKey(ResourceKey.of("test", "custombiome"))
.settings(BiomeSettings.defaultSettings())
.waterColor("#F5F2EB")
.register();
}
private void example() {
CustomBiome reference = RegisteredBiomes.getOrThrow(ResourceKey.of("test", "custombiome"));
// Do something with the reference!
}
}