Search in sources :

Example 6 with IChromosome

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

the class Bee method createOffspring.

private IBee createOffspring(IBeeHousing housing, IBeeGenome mate, int generation) {
    World world = housing.getWorldObj();
    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 occurred.
    IChromosome[] mutated1 = mutateSpecies(housing, genome, mate);
    if (mutated1 != null) {
        parent1 = mutated1;
    }
    IChromosome[] mutated2 = mutateSpecies(housing, mate, genome);
    if (mutated2 != null) {
        parent2 = mutated2;
    }
    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]);
        }
    }
    IBeekeepingMode mode = BeeManager.beeRoot.getBeekeepingMode(world);
    return new Bee(new BeeGenome(chromosomes), mode.isNaturalOffspring(this), generation);
}
Also used : IBeeGenome(forestry.api.apiculture.IBeeGenome) IBee(forestry.api.apiculture.IBee) IChromosome(forestry.api.genetics.IChromosome) IBeekeepingMode(forestry.api.apiculture.IBeekeepingMode) World(net.minecraft.world.World)

Example 7 with IChromosome

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

the class Flower method mutateSpecies.

private IChromosome[] mutateSpecies(World world, BlockPos pos, IFlowerGenome genomeFirst, IFlowerGenome genomeSecond) {
    IChromosome[] parentFirst = genomeFirst.getChromosomes();
    IChromosome[] parentSecond = genomeSecond.getChromosomes();
    IAlleleFlowerSpecies alleleFirst;
    IAlleleFlowerSpecies alleleSecond;
    IFlowerGenome genome0;
    IFlowerGenome genome2;
    if (world.rand.nextBoolean()) {
        alleleFirst = (IAlleleFlowerSpecies) parentFirst[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        alleleSecond = (IAlleleFlowerSpecies) parentSecond[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeFirst;
        genome2 = genomeSecond;
    } else {
        alleleFirst = (IAlleleFlowerSpecies) parentSecond[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        alleleSecond = (IAlleleFlowerSpecies) parentFirst[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeSecond;
        genome2 = genomeFirst;
    }
    IFlowerColor colorFirst = genome0.getPrimaryColor();
    IFlowerColor colorSecond = genome2.getPrimaryColor();
    if (colorFirst != colorSecond) {
        for (IColorMix mutation : BotanyCore.getFlowerRoot().getColorMixes(true)) {
            if (mutation.isMutation(colorFirst, colorSecond) && world.rand.nextFloat() * 100.0f < mutation.getChance()) {
                parentFirst[EnumFlowerChromosome.PRIMARY.ordinal()] = new Chromosome(mutation.getResult().getAllele());
            }
        }
    }
    colorFirst = genome0.getSecondaryColor();
    colorSecond = genome2.getSecondaryColor();
    if (colorFirst != colorSecond) {
        for (IColorMix mutation : BotanyCore.getFlowerRoot().getColorMixes(true)) {
            if (mutation.isMutation(colorFirst, colorSecond) && world.rand.nextFloat() * 100.0f < mutation.getChance()) {
                parentFirst[EnumFlowerChromosome.SECONDARY.ordinal()] = new Chromosome(mutation.getResult().getAllele());
            }
        }
    }
    colorFirst = genome0.getStemColor();
    colorSecond = genome2.getStemColor();
    if (colorFirst != colorSecond) {
        for (IColorMix mutation : BotanyCore.getFlowerRoot().getColorMixes(true)) {
            if (mutation.isMutation(colorFirst, colorSecond) && world.rand.nextFloat() * 100.0f < mutation.getChance()) {
                parentFirst[EnumFlowerChromosome.STEM.ordinal()] = new Chromosome(mutation.getResult().getAllele());
            }
        }
    }
    IChromosome[] template = null;
    for (IFlowerMutation mutation2 : BotanyCore.getFlowerRoot().getMutations(true)) {
        float chance = mutation2.getChance(world, pos, alleleFirst, alleleSecond, genome0, genome2);
        if (chance > 0.0f && world.rand.nextFloat() * 100.0f < chance && template == null) {
            template = BotanyCore.getFlowerRoot().templateAsChromosomes(mutation2.getTemplate());
        }
    }
    if (template != null) {
        parentFirst = template;
    }
    return parentFirst;
}
Also used : IFlowerGenome(binnie.botany.api.genetics.IFlowerGenome) IColorMix(binnie.botany.api.genetics.IColorMix) IFlowerMutation(binnie.botany.api.genetics.IFlowerMutation) IChromosome(forestry.api.genetics.IChromosome) IFlowerColor(binnie.botany.api.genetics.IFlowerColor) Chromosome(forestry.core.genetics.Chromosome) IChromosome(forestry.api.genetics.IChromosome) EnumTreeChromosome(forestry.api.arboriculture.EnumTreeChromosome) EnumFlowerChromosome(binnie.botany.api.genetics.EnumFlowerChromosome) IAlleleFlowerSpecies(binnie.botany.api.genetics.IAlleleFlowerSpecies)

Example 8 with IChromosome

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

the class Splicer method setGene.

public static void setGene(IGene gene, ItemStack target, boolean setPrimary, boolean setSecondary) {
    int chromosomeID = gene.getChromosome().ordinal();
    Class<? extends IAllele> cls = gene.getChromosome().getAlleleClass();
    if (!cls.isInstance(gene.getAllele())) {
        return;
    }
    NBTTagCompound targetTag = target.getTagCompound();
    NBTTagCompound mate = null;
    if (targetTag != null && targetTag.hasKey("Mate")) {
        mate = targetTag.getCompoundTag("Mate").copy();
    }
    ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(target);
    Preconditions.checkNotNull(speciesRoot);
    IIndividual original = speciesRoot.getMember(target);
    Preconditions.checkNotNull(original);
    IChromosome[] chromosomes = original.getGenome().getChromosomes();
    IAllele[] primaryAlleles = new IAllele[chromosomes.length];
    IAllele[] secondaryAlleles = new IAllele[chromosomes.length];
    for (int i = 0; i < chromosomes.length; i++) {
        IChromosome chromosome = chromosomes[i];
        if (i == chromosomeID && setPrimary) {
            primaryAlleles[i] = gene.getAllele();
        } else {
            primaryAlleles[i] = chromosome.getPrimaryAllele();
        }
        if (i == chromosomeID && setSecondary) {
            secondaryAlleles[i] = gene.getAllele();
        } else {
            secondaryAlleles[i] = chromosome.getSecondaryAllele();
        }
    }
    IIndividual individual = speciesRoot.templateAsIndividual(primaryAlleles, secondaryAlleles);
    if (original.isAnalyzed()) {
        individual.analyze();
    }
    if (original instanceof IBee) {
        IBee individualBee = (IBee) individual;
        IBee originalBee = (IBee) original;
        individualBee.setIsNatural(originalBee.isNatural());
    }
    NBTTagCompound nbt = new NBTTagCompound();
    individual.writeToNBT(nbt);
    if (mate != null) {
        nbt.setTag("Mate", mate);
    }
    target.setTagCompound(nbt);
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChromosome(forestry.api.genetics.IChromosome) IBee(forestry.api.apiculture.IBee)

Example 9 with IChromosome

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

the class ItemSerumArray method getSubItems.

@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
    if (this.isInCreativeTab(tab)) {
        for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
            for (IIndividual template : root.getIndividualTemplates()) {
                if (template.getGenome().getPrimary().isSecret()) {
                    continue;
                }
                IGeneItem geneItem = new GeneArrayItem();
                for (IChromosomeType type : root.getKaryotype()) {
                    IChromosome chromosome = template.getGenome().getChromosomes()[type.ordinal()];
                    if (chromosome != null) {
                        IAllele active = chromosome.getActiveAllele();
                        geneItem.addGene(new Gene(active, type, root));
                    }
                }
                ItemStack array = new ItemStack(this);
                geneItem.writeToItem(array);
                items.add(array);
            }
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IGeneItem(binnie.genetics.genetics.IGeneItem) IIndividual(forestry.api.genetics.IIndividual) Gene(binnie.core.genetics.Gene) IGene(binnie.core.api.genetics.IGene) IChromosome(forestry.api.genetics.IChromosome) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack) GeneArrayItem(binnie.genetics.genetics.GeneArrayItem)

Example 10 with IChromosome

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

the class Butterfly method spawnCaterpillar.

@Override
@Nullable
public IButterfly spawnCaterpillar(World world, IButterflyNursery nursery) {
    // We need a mated queen to produce offspring.
    if (mate == null) {
        return null;
    }
    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[] mutated1 = mutateSpecies(world, nursery, genome, mate);
    if (mutated1 != null) {
        parent1 = mutated1;
    }
    IChromosome[] mutated2 = mutateSpecies(world, nursery, mate, genome);
    if (mutated2 != null) {
        parent2 = mutated2;
    }
    for (int i = 0; i < parent1.length; i++) {
        if (parent1[i] != null && parent2[i] != null) {
            chromosomes[i] = Chromosome.inheritChromosome(rand, parent1[i], parent2[i]);
        }
    }
    return new Butterfly(new ButterflyGenome(chromosomes));
}
Also used : IButterflyGenome(forestry.api.lepidopterology.IButterflyGenome) IButterfly(forestry.api.lepidopterology.IButterfly) IEntityButterfly(forestry.api.lepidopterology.IEntityButterfly) IChromosome(forestry.api.genetics.IChromosome) 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