Search in sources :

Example 16 with IChromosome

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

the class Genome method getAllele.

public static IAllele getAllele(ItemStack itemStack, IChromosomeType type, boolean active) {
    IAllele allele = getSpeciesDirectly(itemStack, type, active);
    if (allele == null) {
        IChromosome chromosome = getChromosome(itemStack, type, type.getSpeciesRoot());
        allele = active ? chromosome.getActiveAllele() : chromosome.getInactiveAllele();
    }
    return allele;
}
Also used : IAllele(forestry.api.genetics.IAllele) IChromosome(forestry.api.genetics.IChromosome)

Example 17 with IChromosome

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

the class Genome method chromosomesToString.

private String chromosomesToString(IChromosome[] chromosomes) {
    StringBuilder stringBuilder = new StringBuilder();
    IChromosomeType[] karyotype = getSpeciesRoot().getKaryotype();
    for (int i = 0; i < chromosomes.length; i++) {
        IChromosomeType chromosomeType = karyotype[i];
        IChromosome chromosome = chromosomes[i];
        stringBuilder.append(chromosomeType.getName()).append(": ").append(chromosome).append("\n");
    }
    return stringBuilder.toString();
}
Also used : IChromosome(forestry.api.genetics.IChromosome) IChromosomeType(forestry.api.genetics.IChromosomeType)

Example 18 with IChromosome

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

the class Bee method mutateSpecies.

@Nullable
private static IChromosome[] mutateSpecies(IBeeHousing housing, IBeeGenome genomeOne, IBeeGenome genomeTwo) {
    World world = housing.getWorldObj();
    IChromosome[] parent1 = genomeOne.getChromosomes();
    IChromosome[] parent2 = genomeTwo.getChromosomes();
    IBeeGenome genome0;
    IBeeGenome genome1;
    IAlleleBeeSpecies allele0;
    IAlleleBeeSpecies allele1;
    if (world.rand.nextBoolean()) {
        allele0 = (IAlleleBeeSpecies) parent1[EnumBeeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = (IAlleleBeeSpecies) parent2[EnumBeeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeOne;
        genome1 = genomeTwo;
    } else {
        allele0 = (IAlleleBeeSpecies) parent2[EnumBeeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = (IAlleleBeeSpecies) parent1[EnumBeeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeTwo;
        genome1 = genomeOne;
    }
    GameProfile playerProfile = housing.getOwner();
    IApiaristTracker breedingTracker = BeeManager.beeRoot.getBreedingTracker(world, playerProfile);
    List<IMutation> combinations = BeeManager.beeRoot.getCombinations(allele0, allele1, true);
    for (IMutation mutation : combinations) {
        IBeeMutation beeMutation = (IBeeMutation) mutation;
        float chance = beeMutation.getChance(housing, allele0, allele1, genome0, genome1);
        if (chance <= 0) {
            continue;
        }
        // boost chance for researched mutations
        if (breedingTracker.isResearched(beeMutation)) {
            float mutationBoost = chance * (Config.researchMutationBoostMultiplier - 1.0f);
            mutationBoost = Math.min(Config.maxResearchMutationBoostPercent, mutationBoost);
            chance += mutationBoost;
        }
        if (chance > world.rand.nextFloat() * 100) {
            breedingTracker.registerMutation(mutation);
            return BeeManager.beeRoot.templateAsChromosomes(mutation.getTemplate());
        }
    }
    return null;
}
Also used : IAlleleBeeSpecies(forestry.api.apiculture.IAlleleBeeSpecies) IMutation(forestry.api.genetics.IMutation) GameProfile(com.mojang.authlib.GameProfile) IBeeMutation(forestry.api.apiculture.IBeeMutation) IChromosome(forestry.api.genetics.IChromosome) IApiaristTracker(forestry.api.apiculture.IApiaristTracker) World(net.minecraft.world.World) IBeeGenome(forestry.api.apiculture.IBeeGenome) Nullable(javax.annotation.Nullable)

Example 19 with IChromosome

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

the class Flower method getOffspring.

@Override
public IFlower getOffspring(World world, BlockPos pos) {
    if (mate != null) {
        IChromosome[] chromosomes = new IChromosome[genome.getChromosomes().length];
        IChromosome[] parentFirst = mutateSpecies(world, pos, genome, mate);
        IChromosome[] parentSecond = mutateSpecies(world, pos, mate, genome);
        for (int i = 0; i < parentFirst.length; ++i) {
            if (parentFirst[i] != null && parentSecond[i] != null) {
                chromosomes[i] = Chromosome.inheritChromosome(world.rand, parentFirst[i], parentSecond[i]);
            }
        }
        return new Flower(new FlowerGenome(chromosomes), 0);
    }
    NBTTagCompound nbt = new NBTTagCompound();
    writeToNBT(nbt);
    return new Flower(nbt);
}
Also used : IFlower(binnie.botany.api.genetics.IFlower) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChromosome(forestry.api.genetics.IChromosome) IFlowerGenome(binnie.botany.api.genetics.IFlowerGenome)

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