Search in sources :

Example 11 with IChromosome

use of forestry.api.genetics.IChromosome 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 12 with IChromosome

use of forestry.api.genetics.IChromosome 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 13 with IChromosome

use of forestry.api.genetics.IChromosome in project ForestryMC by ForestryMC.

the class Chromosome method inheritChromosome.

/* HELPER FUNCTIONS */
public static IChromosome inheritChromosome(Random rand, IChromosome parent1, IChromosome parent2) {
    IAllele choice1;
    if (rand.nextBoolean()) {
        choice1 = parent1.getPrimaryAllele();
    } else {
        choice1 = parent1.getSecondaryAllele();
    }
    IAllele choice2;
    if (rand.nextBoolean()) {
        choice2 = parent2.getPrimaryAllele();
    } else {
        choice2 = parent2.getSecondaryAllele();
    }
    if (rand.nextBoolean()) {
        return new Chromosome(choice1, choice2);
    } else {
        return new Chromosome(choice2, choice1);
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) IChromosome(forestry.api.genetics.IChromosome)

Example 14 with IChromosome

use of forestry.api.genetics.IChromosome in project ForestryMC by ForestryMC.

the class Genome method getChromosome.

private static IChromosome getChromosome(ItemStack itemStack, IChromosomeType chromosomeType, ISpeciesRoot speciesRoot) {
    NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
    if (nbtTagCompound == null) {
        nbtTagCompound = new NBTTagCompound();
        itemStack.setTagCompound(nbtTagCompound);
    }
    NBTTagCompound genomeNbt = nbtTagCompound.getCompoundTag("Genome");
    if (genomeNbt.hasNoTags()) {
        Log.error("Got a genetic item with no genome, setting it to a default value.");
        genomeNbt = new NBTTagCompound();
        IAllele[] defaultTemplate = speciesRoot.getDefaultTemplate();
        IGenome genome = speciesRoot.templateAsGenome(defaultTemplate);
        genome.writeToNBT(genomeNbt);
        nbtTagCompound.setTag("Genome", genomeNbt);
    }
    IChromosome[] chromosomes = getChromosomes(genomeNbt, speciesRoot);
    return chromosomes[chromosomeType.ordinal()];
}
Also used : IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChromosome(forestry.api.genetics.IChromosome)

Example 15 with IChromosome

use of forestry.api.genetics.IChromosome in project ForestryMC by ForestryMC.

the class Genome method toString.

@Override
public String toString() {
    MoreObjects.ToStringHelper toStringHelper = MoreObjects.toStringHelper(this);
    int i = 0;
    for (IChromosome chromosome : chromosomes) {
        toStringHelper.add(String.valueOf(i++), chromosome);
    }
    return toStringHelper.toString();
}
Also used : MoreObjects(com.google.common.base.MoreObjects) IChromosome(forestry.api.genetics.IChromosome)

Aggregations

IChromosome (forestry.api.genetics.IChromosome)19 IAllele (forestry.api.genetics.IAllele)8 IChromosomeType (forestry.api.genetics.IChromosomeType)4 Nullable (javax.annotation.Nullable)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 IFlowerGenome (binnie.botany.api.genetics.IFlowerGenome)2 IBee (forestry.api.apiculture.IBee)2 IBeeGenome (forestry.api.apiculture.IBeeGenome)2 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)2 ITreeGenome (forestry.api.arboriculture.ITreeGenome)2 IGenome (forestry.api.genetics.IGenome)2 IIndividual (forestry.api.genetics.IIndividual)2 IMutation (forestry.api.genetics.IMutation)2 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)2 World (net.minecraft.world.World)2 EnumFlowerChromosome (binnie.botany.api.genetics.EnumFlowerChromosome)1 IAlleleFlowerSpecies (binnie.botany.api.genetics.IAlleleFlowerSpecies)1 IColorMix (binnie.botany.api.genetics.IColorMix)1 IFlower (binnie.botany.api.genetics.IFlower)1 IFlowerColor (binnie.botany.api.genetics.IFlowerColor)1