Search in sources :

Example 1 with IChromosome

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

the class TreeGenome method calculateMatchesTemplateGenome.

private boolean calculateMatchesTemplateGenome() {
    IAlleleTreeSpecies primary = getPrimary();
    IAllele[] template = getSpeciesRoot().getTemplate(primary);
    IChromosome[] chromosomes = getChromosomes();
    for (int i = 0; i < chromosomes.length; i++) {
        IChromosome chromosome = chromosomes[i];
        String templateUid = template[i].getUID();
        IAllele primaryAllele = chromosome.getPrimaryAllele();
        if (!primaryAllele.getUID().equals(templateUid)) {
            return false;
        }
        IAllele secondaryAllele = chromosome.getSecondaryAllele();
        if (!secondaryAllele.getUID().equals(templateUid)) {
            return false;
        }
    }
    return true;
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IChromosome(forestry.api.genetics.IChromosome)

Example 2 with IChromosome

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

the class Genome method getChromosomes.

private static IChromosome[] getChromosomes(NBTTagCompound genomeNBT, ISpeciesRoot speciesRoot) {
    NBTTagList chromosomesNBT = genomeNBT.getTagList("Chromosomes", 10);
    IChromosome[] chromosomes = new IChromosome[speciesRoot.getDefaultTemplate().length];
    String primarySpeciesUid = null;
    String secondarySpeciesUid = null;
    for (int i = 0; i < chromosomesNBT.tagCount(); i++) {
        NBTTagCompound chromosomeNBT = chromosomesNBT.getCompoundTagAt(i);
        byte chromosomeOrdinal = chromosomeNBT.getByte(SLOT_TAG);
        if (chromosomeOrdinal >= 0 && chromosomeOrdinal < chromosomes.length) {
            IChromosomeType chromosomeType = speciesRoot.getKaryotype()[chromosomeOrdinal];
            Chromosome chromosome = Chromosome.create(primarySpeciesUid, secondarySpeciesUid, chromosomeType, chromosomeNBT);
            chromosomes[chromosomeOrdinal] = chromosome;
            if (chromosomeOrdinal == speciesRoot.getSpeciesChromosomeType().ordinal()) {
                primarySpeciesUid = chromosome.getPrimaryAllele().getUID();
                secondarySpeciesUid = chromosome.getSecondaryAllele().getUID();
            }
        }
    }
    return chromosomes;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChromosome(forestry.api.genetics.IChromosome) IChromosome(forestry.api.genetics.IChromosome) IChromosomeType(forestry.api.genetics.IChromosomeType)

Example 3 with IChromosome

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

the class Genome method checkChromosomes.

private void checkChromosomes(IChromosome[] chromosomes) {
    if (chromosomes.length != getDefaultTemplate().length) {
        String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template.\n%s", getSpeciesRoot().getUID(), chromosomesToString(chromosomes));
        throw new IllegalArgumentException(message);
    }
    IChromosomeType[] karyotype = getSpeciesRoot().getKaryotype();
    for (int i = 0; i < karyotype.length; i++) {
        IChromosomeType chromosomeType = karyotype[i];
        IChromosome chromosome = chromosomes[i];
        if (chromosome == null) {
            String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing chromosome '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
            throw new IllegalArgumentException(message);
        }
        IAllele primary = chromosome.getPrimaryAllele();
        if (primary == null) {
            String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing primary allele for '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
            throw new IllegalArgumentException(message);
        }
        IAllele secondary = chromosome.getSecondaryAllele();
        if (secondary == null) {
            String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing secondary allele for '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
            throw new IllegalArgumentException(message);
        }
        Class<? extends IAllele> chromosomeAlleleClass = chromosomeType.getAlleleClass();
        if (!chromosomeAlleleClass.isAssignableFrom(primary.getClass())) {
            String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Incorrect type for primary allele '%s'.\n%s.", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
            throw new IllegalArgumentException(message);
        }
        if (!chromosomeAlleleClass.isAssignableFrom(secondary.getClass())) {
            String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Incorrect type for secondary allele '%s'.\n%s.", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
            throw new IllegalArgumentException(message);
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) IChromosome(forestry.api.genetics.IChromosome) IChromosomeType(forestry.api.genetics.IChromosomeType)

Example 4 with IChromosome

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

the class Genome method isGeneticEqual.

@Override
public boolean isGeneticEqual(IGenome other) {
    IChromosome[] genetics = other.getChromosomes();
    if (chromosomes.length != genetics.length) {
        return false;
    }
    for (int i = 0; i < chromosomes.length; i++) {
        IChromosome chromosome = chromosomes[i];
        IChromosome otherChromosome = genetics[i];
        if (chromosome == null && otherChromosome == null) {
            continue;
        }
        if (chromosome == null || otherChromosome == null) {
            return false;
        }
        if (!chromosome.getPrimaryAllele().getUID().equals(otherChromosome.getPrimaryAllele().getUID())) {
            return false;
        }
        if (!chromosome.getSecondaryAllele().getUID().equals(otherChromosome.getSecondaryAllele().getUID())) {
            return false;
        }
    }
    return true;
}
Also used : IChromosome(forestry.api.genetics.IChromosome)

Example 5 with IChromosome

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

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