use of forestry.api.genetics.IIndividual in project Binnie by ForestryMC.
the class ManagerGenetics method loadAlleles.
private void loadAlleles() {
this.invalidChromosomeTypes.clear();
for (IBreedingSystem system : BREEDING_SYSTEMS.values()) {
ISpeciesRoot root = system.getSpeciesRoot();
Map<IChromosomeType, List<IAllele>> chromosomeMap = new LinkedHashMap<>();
for (IChromosomeType chromosome : root.getKaryotype()) {
TreeSet<IAllele> alleles = new TreeSet<>(new ComparatorAllele());
for (IIndividual individual : root.getIndividualTemplates()) {
IGenome genome = individual.getGenome();
IAllele activeAllele = genome.getActiveAllele(chromosome);
IAllele inactiveAllele = genome.getInactiveAllele(chromosome);
if (chromosome.getAlleleClass().isInstance(activeAllele)) {
alleles.add(activeAllele);
}
if (!chromosome.getAlleleClass().isInstance(inactiveAllele)) {
continue;
}
alleles.add(inactiveAllele);
}
system.addExtraAlleles(chromosome, alleles);
if (alleles.size() == 0) {
this.invalidChromosomeTypes.add(chromosome);
} else {
final List<IAllele> alleleList = new ArrayList<>(alleles);
chromosomeMap.put(chromosome, alleleList);
}
}
this.chromosomeArray.put(root, chromosomeMap);
}
}
use of forestry.api.genetics.IIndividual in project Binnie by ForestryMC.
the class ControlIndividualDisplay method getTooltip.
@Override
public void getTooltip(Tooltip tooltip, ITooltipFlag tooltipFlag) {
ItemStack stack = getItemStack();
if (stack.isEmpty()) {
return;
}
IIndividual ind = AlleleManager.alleleRegistry.getIndividual(stack);
if (ind == null) {
return;
}
tooltip.add(ind.getGenome().getPrimary().getAlleleName());
}
use of forestry.api.genetics.IIndividual 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.IIndividual in project Binnie by ForestryMC.
the class SplicerLogic method isValidSerum.
@Nullable
public ErrorState isValidSerum() {
final ItemStack serum = this.getUtil().getStack(Splicer.SLOT_SERUM_VIAL);
if (serum.isEmpty()) {
return null;
}
final ItemStack target = this.getUtil().getStack(Splicer.SLOT_TARGET);
final IGene[] genes = Engineering.getGenes(serum);
if (genes.length == 0) {
return new ErrorState(GeneticsErrorCode.INVALID_SERUM_NO);
}
if (!genes[0].getSpeciesRoot().isMember(target)) {
return new ErrorState(GeneticsErrorCode.INVALID_SERUM_MISMATCH);
}
final IIndividual individual = genes[0].getSpeciesRoot().getMember(target);
boolean hasAll = true;
for (final IGene gene : genes) {
if (hasAll) {
final IAllele a = individual.getGenome().getActiveAllele(gene.getChromosome());
final IAllele b = individual.getGenome().getInactiveAllele(gene.getChromosome());
hasAll = (hasAll && a.getUID().equals(gene.getAllele().getUID()) && b.getUID().equals(gene.getAllele().getUID()));
}
}
if (hasAll) {
return new ErrorState(GeneticsErrorCode.DEFUNCT_SERUM);
}
return null;
}
use of forestry.api.genetics.IIndividual in project Binnie by ForestryMC.
the class SplicerLogic method getGenesToUse.
public static int getGenesToUse(ItemStack serum, ItemStack target) {
if (serum.isEmpty() || target.isEmpty()) {
return 1;
}
final IIndividual ind = AlleleManager.alleleRegistry.getIndividual(target);
final IGene[] genes = ((IItemSerum) serum.getItem()).getGenes(serum);
if (ind.getGenome().getSpeciesRoot() != ((IItemSerum) serum.getItem()).getSpeciesRoot(serum)) {
return 1;
}
int i = 0;
for (final IGene gene : genes) {
if (ind.getGenome().getActiveAllele(gene.getChromosome()) != gene.getAllele() || ind.getGenome().getInactiveAllele(gene.getChromosome()) != gene.getAllele()) {
++i;
}
}
return (i < 1) ? 1 : i;
}
Aggregations