Search in sources :

Example 6 with IAlleleTreeSpecies

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);
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies)

Example 7 with IAlleleTreeSpecies

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;
                    }
                }
            }
        }
    }
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) Biome(net.minecraft.world.biome.Biome) BlockPos(net.minecraft.util.math.BlockPos) ITree(forestry.api.arboriculture.ITree)

Example 8 with IAlleleTreeSpecies

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);
            }
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) Biome(net.minecraft.world.biome.Biome) IGrowthProvider(forestry.api.arboriculture.IGrowthProvider) ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 9 with IAlleleTreeSpecies

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;
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 10 with IAlleleTreeSpecies

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());
    }
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) ItemStack(net.minecraft.item.ItemStack) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Aggregations

IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)24 ITreeGenome (forestry.api.arboriculture.ITreeGenome)14 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)7 ItemStack (net.minecraft.item.ItemStack)7 IAllele (forestry.api.genetics.IAllele)6 ArrayList (java.util.ArrayList)6 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 ILeafSpriteProvider (forestry.api.arboriculture.ILeafSpriteProvider)5 TextureMap (net.minecraft.client.renderer.texture.TextureMap)5 ITree (forestry.api.arboriculture.ITree)4 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)2 IChromosome (forestry.api.genetics.IChromosome)2 IFruitFamily (forestry.api.genetics.IFruitFamily)2 IBlockState (net.minecraft.block.state.IBlockState)2 Biome (net.minecraft.world.biome.Biome)2 ControlText (binnie.core.gui.controls.ControlText)1 Control (binnie.core.gui.controls.core.Control)1 ControlScrollableContent (binnie.core.gui.controls.scroll.ControlScrollableContent)1 Area (binnie.core.gui.geometry.Area)1