cn.nukkit.level.biome.Biome Maven / Gradle / Ivy
package cn.nukkit.level.biome;
import cn.nukkit.api.DeprecationDetails;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.api.Since;
import cn.nukkit.block.BlockID;
import cn.nukkit.level.ChunkManager;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.level.generator.populator.type.Populator;
import cn.nukkit.math.NukkitRandom;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
/**
* @author MagicDroidX (Nukkit Project)
*/
public abstract class Biome implements BlockID {
public static final int MAX_BIOMES = 256;
public static final Biome[] biomes = new Biome[MAX_BIOMES];
public static final List unorderedBiomes = new ArrayList<>();
private final ArrayList populators = new ArrayList<>();
private int id;
private float baseHeight = 0.1f;
private float heightVariation = 0.3f;
public static String getBiomeNameFromId(int biomeId) {
return BiomeLegacyId2StringIdMap.INSTANCE.legacy2String(biomeId);
}
public static int getBiomeIdOrCorrect(int biomeId) {
if (BiomeLegacyId2StringIdMap.INSTANCE.legacy2String(biomeId) == null) {
return EnumBiome.OCEAN.id;
}
return biomeId;
}
protected static void register(int id, Biome biome) {
biome.setId(id);
biomes[id] = biome;
unorderedBiomes.add(biome);
}
public static Biome getBiome(int id) {
Biome biome = biomes[id];
return biome != null ? biome : EnumBiome.OCEAN.biome;
}
/**
* Get Biome by name.
*
* @param name Name of biome. Name could contain symbol "_" instead of space
* @return Biome. Null - when biome was not found
*/
public static Biome getBiome(String name) {
for (Biome biome : biomes) {
if (biome != null) {
if (biome.getName().equalsIgnoreCase(name.replace("_", " "))) return biome;
}
}
return null;
}
public void clearPopulators() {
this.populators.clear();
}
public void addPopulator(Populator populator) {
this.populators.add(populator);
}
@Deprecated
@DeprecationDetails(since = "1.19.50-r3", reason = "populators will be modified by plugins in event calls.",
replaceWith = "populateChunk(ChunkManager, List, int, int, NukkitRandom)")
public void populateChunk(@NotNull ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
FullChunk chunk = level.getChunk(chunkX, chunkZ);
for (Populator populator : populators) {
populator.populate(level, chunkX, chunkZ, random, chunk);
}
}
public void populateChunk(@NotNull ChunkManager level, @NotNull List usedPopulators, int chunkX, int chunkZ, NukkitRandom random) {
FullChunk chunk = level.getChunk(chunkX, chunkZ);
for (Populator populator : usedPopulators) {
populator.populate(level, chunkX, chunkZ, random, chunk);
}
}
public ArrayList getPopulators() {
return populators;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public abstract String getName();
public float getBaseHeight() {
return baseHeight;
}
public void setBaseHeight(float baseHeight) {
this.baseHeight = baseHeight;
}
public float getHeightVariation() {
return heightVariation;
}
public void setHeightVariation(float heightVariation) {
this.heightVariation = heightVariation;
}
@Override
public int hashCode() {
return getId();
}
@Override
public boolean equals(Object obj) {
return hashCode() == obj.hashCode();
}
//whether or not water should freeze into ice on generation
public boolean isFreezing() {
return false;
}
/**
* Whether or not overhangs should generate in this biome (places where solid blocks generate over air)
*
* This should probably be used with a custom max elevation or things can look stupid
*
* @return overhang
*/
public boolean doesOverhang() {
return false;
}
/**
* How much offset should be added to the min/max heights at this position
*
* @param x x
* @param z z
* @return height offset
*/
public int getHeightOffset(int x, int z) {
return 0;
}
public boolean canRain() {
return true;
}
@PowerNukkitOnly
@Since("1.4.0.0-PN")
public boolean isDry() {
return false;
}
}