use of forestry.api.arboriculture.IAlleleTreeSpecies in project ForestryMC by ForestryMC.
the class TreeGenome method getSpecies.
// NBT RETRIEVAL
public static IAlleleTreeSpecies getSpecies(ItemStack itemStack) {
Preconditions.checkArgument(TreeManager.treeRoot.isMember(itemStack), "ItemStack must be a tree");
IAlleleSpecies species = getSpeciesDirectly(TreeManager.treeRoot, itemStack);
if (species instanceof IAlleleTreeSpecies) {
return (IAlleleTreeSpecies) species;
}
return (IAlleleTreeSpecies) getActiveAllele(itemStack, EnumTreeChromosome.SPECIES, TreeManager.treeRoot);
}
use of forestry.api.arboriculture.IAlleleTreeSpecies in project ForestryMC by ForestryMC.
the class TreeDecorator method decorateTrees.
public static void decorateTrees(World world, Random rand, int worldX, int worldZ) {
if (!Config.isValidTreeDim(world.provider.getDimension())) {
return;
}
if (biomeCache.isEmpty()) {
generateBiomeCache(world, rand);
}
for (int tries = 0; tries < 4 + rand.nextInt(2); tries++) {
int x = worldX + rand.nextInt(16);
int z = worldZ + rand.nextInt(16);
BlockPos pos = new BlockPos(x, 0, z);
Biome biome = world.getBiome(pos);
Set<ITree> trees = biomeCache.computeIfAbsent(biome.getRegistryName(), k -> new HashSet<>());
for (ITree tree : trees) {
IAlleleTreeSpecies species = tree.getGenome().getPrimary();
if (species.getRarity() >= rand.nextFloat()) {
pos = getValidPos(world, x, z, tree);
if (pos == null) {
continue;
}
if (species.getGrowthProvider().canSpawn(tree, world, pos)) {
if (TreeGenHelper.generateTree(tree, world, pos)) {
return;
}
}
}
}
}
}
use of forestry.api.arboriculture.IAlleleTreeSpecies in project ForestryMC by ForestryMC.
the class TreeDecorator method generateBiomeCache.
private static void generateBiomeCache(World world, Random rand) {
for (IAlleleTreeSpecies species : getSpecies()) {
IAllele[] template = TreeManager.treeRoot.getTemplate(species);
ITreeGenome genome = TreeManager.treeRoot.templateAsGenome(template);
ITree tree = TreeManager.treeRoot.getTree(world, genome);
IGrowthProvider growthProvider = species.getGrowthProvider();
for (Biome biome : Biome.REGISTRY) {
Set<ITree> trees = biomeCache.computeIfAbsent(biome.getRegistryName(), k -> new HashSet<>());
if (growthProvider.isBiomeValid(tree, biome)) {
trees.add(tree);
}
}
}
}
use of forestry.api.arboriculture.IAlleleTreeSpecies in project Binnie by ForestryMC.
the class TreeBreedingSystem method getTreesThatHaveWood.
@Override
public Collection<IAlleleSpecies> getTreesThatHaveWood(final ItemStack wood, final boolean master, final World world, final GameProfile player) {
final Collection<IAlleleSpecies> set = master ? this.getAllSpecies() : this.getDiscoveredSpecies(world, player);
final List<IAlleleSpecies> found = new ArrayList<>();
for (final IAlleleSpecies species : set) {
IAlleleTreeSpecies tSpecies = (IAlleleTreeSpecies) species;
ITreeGenome genome = TreeManager.treeRoot.templateAsGenome(TreeManager.treeRoot.getTemplate(tSpecies));
IAlleleTreeSpecies treeSpecies = genome.getPrimary();
final ItemStack woodStack = treeSpecies.getWoodProvider().getWoodStack();
if (woodStack.isItemEqual(wood)) {
found.add(species);
}
}
return found;
}
use of forestry.api.arboriculture.IAlleleTreeSpecies in project Binnie by ForestryMC.
the class TreeBreedingSystem method calculateArrays.
@Override
public final void calculateArrays() {
super.calculateArrays();
for (final IAlleleSpecies species : this.allActiveSpecies) {
final IAlleleTreeSpecies tSpecies = (IAlleleTreeSpecies) species;
final ITreeGenome genome = (ITreeGenome) this.getSpeciesRoot().templateAsGenome(this.getSpeciesRoot().getTemplate(tSpecies));
IAlleleTreeSpecies treeSpecies = genome.getPrimary();
final ItemStack wood = treeSpecies.getWoodProvider().getWoodStack();
if (!wood.isEmpty()) {
this.allWoods.add(wood);
}
/*for (final ItemStack wood : tSpecies.getRoot().templateAsIndividual(getSpeciesRoot().getTemplate(tSpecies.getUID())).getProduceList()) {
this.allWoods.add(wood);
}*/
this.allFruits.addAll(genome.getFruitProvider().getProducts().keySet());
}
}
Aggregations