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);
}
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;
}
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);
}
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);
}
}
}
}
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));
}
Aggregations