/** * This work is licensed under the Creative Commons * Attribution-ShareAlike 3.0 Unported License. To view a copy of this * license, visit http://creativecommons.org/licenses/by-sa/3.0/. */ package extrabiomes.api; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Collection; import java.util.Random; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.gen.feature.WorldGenerator; import com.google.common.base.Optional; /** * Allows direct access to Extrabiome's biomes. This class' members will * be populated during the @Init event. If a biome is absent after the * Init event, then the Extrabiomes mod is not active or not installed. *

* NOTE: Make sure to only reference members of this class in the * PostInit event or later. * * @author ScottKillen * */ // The BiomeManager will be removed following release 3.6.0. Use extrabiomes.api.Biomes instead @Deprecated public abstract class BiomeManager { protected enum GenType { TREE, GRASS; } public static Optional alpine = Optional.absent(); public static Optional autumnwoods = Optional.absent(); public static Optional birchforest = Optional.absent(); public static Optional extremejungle = Optional.absent(); public static Optional forestedisland = Optional.absent(); public static Optional forestedhills = Optional.absent(); public static Optional glacier = Optional.absent(); public static Optional greenhills = Optional.absent(); public static Optional icewasteland = Optional.absent(); public static Optional greenswamp = Optional.absent(); public static Optional marsh = Optional.absent(); public static Optional meadow = Optional.absent(); public static Optional minijungle = Optional.absent(); public static Optional mountaindesert = Optional.absent(); public static Optional mountainridge = Optional.absent(); public static Optional mountaintaiga = Optional.absent(); public static Optional pineforest = Optional.absent(); public static Optional rainforest = Optional.absent(); public static Optional redwoodforest = Optional.absent(); public static Optional redwoodlush = Optional.absent(); public static Optional savanna = Optional.absent(); public static Optional shrubland = Optional.absent(); public static Optional snowforest = Optional.absent(); public static Optional snowyrainforest = Optional.absent(); public static Optional temperaterainforest = Optional.absent(); public static Optional tundra = Optional.absent(); public static Optional wasteland = Optional.absent(); public static Optional woodlands = Optional.absent(); protected static Optional instance = Optional.absent(); /** * This method allows the addition of grasses to custom biomes by * weight. * * @param biome * the biomes to add the tree to. * @param grassGen * the grass generator * @param weight * the relative probabilty of picking this grass to * generate. To establish a relative priority, some * function should be applied to the current total weight * for a biome. */ public static void addWeightedGrassGenForBiome(BiomeGenBase biome, WorldGenerator grassGen, int weight) { checkArgument(instance.isPresent(), "Cannot add weighted grass gens until after API is initialized."); checkNotNull(biome, "Biome is required."); checkNotNull(grassGen, "Grass generator is required."); checkArgument(weight > 0, "Weight must be greater than zero."); instance.get().addBiomeGen(GenType.GRASS, biome, grassGen, weight); } /** * This method allows the addition of trees to custom biomes by * weight. * * @param biome * the biomes to add the tree to. * @param treeGen * the tree generator * @param weight * the relative probabilty of picking this tree to * generate. To establish a relative priority, some * function should be applied to the current total weight * for a biome. */ public static void addWeightedTreeGenForBiome(BiomeGenBase biome, WorldGenerator treeGen, int weight) { checkArgument(instance.isPresent(), "Cannot add weighted tree gens until after API is initialized."); checkNotNull(biome, "Biome is required."); checkNotNull(treeGen, "Tree Generator is required."); checkArgument(weight > 0, "Weight must be greater than zero."); instance.get() .addBiomeGen(GenType.TREE, biome, treeGen, weight); } /** * Returns a random choice from the weighted list of grass * generators * * @param biome * The biome for which to select a grass gen * @return the selected grass generator. */ public static Optional chooseRandomGrassGenforBiome( Random rand, BiomeGenBase biome) { return instance.get().chooseBiomeRandomGen(GenType.GRASS, rand, biome); } /** * Returns a random choice from the weighted list of tree generators * * @param biome * The biome for which to select a tree gen * @return the selected tree generator. */ public static Optional chooseRandomTreeGenforBiome( Random rand, BiomeGenBase biome) { return instance.get().chooseBiomeRandomGen(GenType.TREE, rand, biome); } /** * @return An immutable collection of this mod's biomes. */ public static Collection getBiomes() { checkArgument(instance.isPresent(), "Biome list not available until after API is initialized."); return instance.get().getBiomeCollection(); } /** * @param biome * The biome for which to calculate the total weight. * @return the total weight of all grassGen choices for a given * biome */ public static int getTotalGrassWeightForBiome(BiomeGenBase biome) { checkNotNull(biome, "Biome is required."); return instance.get().getBiomeTotalWeight(GenType.GRASS, biome); } /** * @param biome * The biome for which to calculate the total weight. * @return the total weight of all treeGen choices for a given biome */ public static int getTotalTreeWeightForBiome(BiomeGenBase biome) { checkNotNull(biome, "Biome is required."); return instance.get().getBiomeTotalWeight(GenType.TREE, biome); } static boolean isActive() { return instance.isPresent(); } protected abstract void addBiomeGen(GenType genType, BiomeGenBase biome, WorldGenerator treeGen, int weight); protected abstract Optional chooseBiomeRandomGen( GenType genType, Random rand, BiomeGenBase biome); protected abstract Collection getBiomeCollection(); protected abstract int getBiomeTotalWeight(GenType genType, BiomeGenBase biome); }