Search in sources :

Example 16 with ITreeGenome

use of forestry.api.arboriculture.ITreeGenome in project ForestryMC by ForestryMC.

the class ModelDefaultLeaves method bakeBlock.

@Override
protected void bakeBlock(BlockDefaultLeaves block, TreeDefinition treeDefinition, IModelBaker baker, boolean inventory) {
    TextureMap map = Minecraft.getMinecraft().getTextureMapBlocks();
    ITreeGenome genome = treeDefinition.getGenome();
    IAlleleTreeSpecies species = genome.getPrimary();
    ILeafSpriteProvider leafSpriteProvider = species.getLeafSpriteProvider();
    ResourceLocation leafSpriteLocation = leafSpriteProvider.getSprite(false, Proxies.render.fancyGraphicsEnabled());
    TextureAtlasSprite leafSprite = map.getAtlasSprite(leafSpriteLocation.toString());
    // Render the plain leaf block.
    baker.addBlockModel(null, leafSprite, BlockAbstractLeaves.FOLIAGE_COLOR_INDEX);
    // Render overlay for fruit leaves.
    ResourceLocation fruitSpriteLocation = genome.getFruitProvider().getDecorativeSprite();
    if (fruitSpriteLocation != null) {
        TextureAtlasSprite fruitSprite = map.getAtlasSprite(fruitSpriteLocation.toString());
        baker.addBlockModel(null, fruitSprite, BlockAbstractLeaves.FRUIT_COLOR_INDEX);
    }
    // Set the particle sprite
    baker.setParticleSprite(leafSprite);
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) TextureMap(net.minecraft.client.renderer.texture.TextureMap) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) ILeafSpriteProvider(forestry.api.arboriculture.ILeafSpriteProvider) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 17 with ITreeGenome

use of forestry.api.arboriculture.ITreeGenome in project ForestryMC by ForestryMC.

the class ClimateGrowthProvider method isBiomeValid.

@Override
public boolean isBiomeValid(ITree tree, Biome biome) {
    EnumTemperature biomeTemperature = EnumTemperature.getFromBiome(biome);
    EnumHumidity biomeHumidity = EnumHumidity.getFromValue(biome.getRainfall());
    ITreeGenome genome = tree.getGenome();
    if (temperature == null) {
        temperature = genome.getPrimary().getTemperature();
    }
    if (humidity == null) {
        humidity = genome.getPrimary().getHumidity();
    }
    return AlleleManager.climateHelper.isWithinLimits(biomeTemperature, biomeHumidity, temperature, temperatureTolerance, humidity, humidityTolerance);
}
Also used : EnumHumidity(forestry.api.core.EnumHumidity) ITreeGenome(forestry.api.arboriculture.ITreeGenome) EnumTemperature(forestry.api.core.EnumTemperature)

Example 18 with ITreeGenome

use of forestry.api.arboriculture.ITreeGenome in project ForestryMC by ForestryMC.

the class Tree method createOffspring.

private ITree createOffspring(World world, ITreeGenome mate, @Nullable GameProfile playerProfile, BlockPos pos) {
    IChromosome[] chromosomes = new IChromosome[genome.getChromosomes().length];
    IChromosome[] parent1 = genome.getChromosomes();
    IChromosome[] parent2 = mate.getChromosomes();
    // Check for mutation. Replace one of the parents with the mutation
    // template if mutation occured.
    IChromosome[] mutated = mutateSpecies(world, playerProfile, pos, genome, mate);
    if (mutated == null) {
        mutated = mutateSpecies(world, playerProfile, pos, mate, genome);
    }
    if (mutated != null) {
        return new Tree(new TreeGenome(mutated));
    }
    for (int i = 0; i < parent1.length; i++) {
        if (parent1[i] != null && parent2[i] != null) {
            chromosomes[i] = Chromosome.inheritChromosome(world.rand, parent1[i], parent2[i]);
        }
    }
    return new Tree(new TreeGenome(chromosomes));
}
Also used : IChromosome(forestry.api.genetics.IChromosome) ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Example 19 with ITreeGenome

use of forestry.api.arboriculture.ITreeGenome in project ForestryMC by ForestryMC.

the class Tree method mutateSpecies.

@Nullable
private static IChromosome[] mutateSpecies(World world, @Nullable GameProfile playerProfile, BlockPos pos, ITreeGenome genomeOne, ITreeGenome genomeTwo) {
    IChromosome[] parent1 = genomeOne.getChromosomes();
    IChromosome[] parent2 = genomeTwo.getChromosomes();
    ITreeGenome genome0;
    ITreeGenome genome1;
    IAlleleTreeSpecies allele0;
    IAlleleTreeSpecies allele1;
    if (world.rand.nextBoolean()) {
        allele0 = (IAlleleTreeSpecies) parent1[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = (IAlleleTreeSpecies) parent2[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeOne;
        genome1 = genomeTwo;
    } else {
        allele0 = (IAlleleTreeSpecies) parent2[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = (IAlleleTreeSpecies) parent1[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeTwo;
        genome1 = genomeOne;
    }
    IArboristTracker breedingTracker = null;
    if (playerProfile != null) {
        breedingTracker = TreeManager.treeRoot.getBreedingTracker(world, playerProfile);
    }
    List<IMutation> combinations = TreeManager.treeRoot.getCombinations(allele0, allele1, true);
    for (IMutation mutation : combinations) {
        ITreeMutation treeMutation = (ITreeMutation) mutation;
        // Stop blacklisted species.
        // if (BeeManager.breedingManager.isBlacklisted(mutation.getTemplate()[0].getUID())) {
        // continue;
        // }
        float chance = treeMutation.getChance(world, pos, allele0, allele1, genome0, genome1);
        if (chance <= 0) {
            continue;
        }
        // boost chance for researched mutations
        if (breedingTracker != null && breedingTracker.isResearched(treeMutation)) {
            float mutationBoost = chance * (Config.researchMutationBoostMultiplier - 1.0f);
            mutationBoost = Math.min(Config.maxResearchMutationBoostPercent, mutationBoost);
            chance += mutationBoost;
        }
        if (chance > world.rand.nextFloat() * 100) {
            return TreeManager.treeRoot.templateAsChromosomes(treeMutation.getTemplate());
        }
    }
    return null;
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IMutation(forestry.api.genetics.IMutation) IChromosome(forestry.api.genetics.IChromosome) ITreeMutation(forestry.api.arboriculture.ITreeMutation) ITreeGenome(forestry.api.arboriculture.ITreeGenome) IArboristTracker(forestry.api.arboriculture.IArboristTracker) Nullable(javax.annotation.Nullable)

Example 20 with ITreeGenome

use of forestry.api.arboriculture.ITreeGenome in project ForestryMC by ForestryMC.

the class TreeGenHelper method getWorldGen.

public static WorldGenerator getWorldGen(String treeName, EntityPlayer player, BlockPos pos) throws SpeciesNotFoundException, TemplateNotFoundException {
    ITreeGenome treeGenome = getTreeGenome(treeName);
    ITree tree = TreeManager.treeRoot.getTree(player.world, treeGenome);
    return tree.getTreeGenerator(player.world, pos, true);
}
Also used : ITree(forestry.api.arboriculture.ITree) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Aggregations

ITreeGenome (forestry.api.arboriculture.ITreeGenome)28 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)14 IFruitProvider (forestry.api.arboriculture.IFruitProvider)11 ItemStack (net.minecraft.item.ItemStack)9 ITree (forestry.api.arboriculture.ITree)8 ILeafSpriteProvider (forestry.api.arboriculture.ILeafSpriteProvider)7 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 ArrayList (java.util.ArrayList)5 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)5 TextureMap (net.minecraft.client.renderer.texture.TextureMap)5 ResourceLocation (net.minecraft.util.ResourceLocation)5 ETTreeDefinition (binnie.extratrees.genetics.ETTreeDefinition)3 TreeDefinition (forestry.arboriculture.genetics.TreeDefinition)3 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)2 ITreeMutation (forestry.api.arboriculture.ITreeMutation)2 IAllele (forestry.api.genetics.IAllele)2 IChromosome (forestry.api.genetics.IChromosome)2 ControlText (binnie.core.gui.controls.ControlText)1 Control (binnie.core.gui.controls.core.Control)1