Search in sources :

Example 1 with IButterflyMutation

use of forestry.api.lepidopterology.IButterflyMutation in project ForestryMC by ForestryMC.

the class Butterfly method mutateSpecies.

@Nullable
private static IChromosome[] mutateSpecies(World world, IButterflyNursery nursery, IGenome genomeOne, IGenome genomeTwo) {
    IChromosome[] parent1 = genomeOne.getChromosomes();
    IChromosome[] parent2 = genomeTwo.getChromosomes();
    IGenome genome0;
    IGenome genome1;
    IAllele allele0;
    IAllele allele1;
    if (rand.nextBoolean()) {
        allele0 = parent1[EnumButterflyChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = parent2[EnumButterflyChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeOne;
        genome1 = genomeTwo;
    } else {
        allele0 = parent2[EnumButterflyChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = parent1[EnumButterflyChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeTwo;
        genome1 = genomeOne;
    }
    for (IButterflyMutation mutation : ButterflyManager.butterflyRoot.getMutations(true)) {
        float chance = mutation.getChance(world, nursery, allele0, allele1, genome0, genome1);
        if (chance > rand.nextFloat() * 100) {
            return ButterflyManager.butterflyRoot.templateAsChromosomes(mutation.getTemplate());
        }
    }
    return null;
}
Also used : IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) IChromosome(forestry.api.genetics.IChromosome) IButterflyMutation(forestry.api.lepidopterology.IButterflyMutation) Nullable(javax.annotation.Nullable)

Aggregations

IAllele (forestry.api.genetics.IAllele)1 IChromosome (forestry.api.genetics.IChromosome)1 IGenome (forestry.api.genetics.IGenome)1 IButterflyMutation (forestry.api.lepidopterology.IButterflyMutation)1 Nullable (javax.annotation.Nullable)1