Search in sources :

Example 26 with IIndividual

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);
    }
}
Also used : IIndividual(forestry.api.genetics.IIndividual) ArrayList(java.util.ArrayList) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) LinkedHashMap(java.util.LinkedHashMap) IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) IChromosomeType(forestry.api.genetics.IChromosomeType)

Example 27 with IIndividual

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());
}
Also used : IIndividual(forestry.api.genetics.IIndividual) ItemStack(net.minecraft.item.ItemStack)

Example 28 with IIndividual

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);
}
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 29 with IIndividual

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;
}
Also used : IAllele(forestry.api.genetics.IAllele) IIndividual(forestry.api.genetics.IIndividual) ErrorState(binnie.core.machines.errors.ErrorState) IGene(binnie.core.api.genetics.IGene) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Example 30 with IIndividual

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;
}
Also used : IIndividual(forestry.api.genetics.IIndividual) IGene(binnie.core.api.genetics.IGene) IItemSerum(binnie.genetics.api.IItemSerum)

Aggregations

IIndividual (forestry.api.genetics.IIndividual)49 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)30 ItemStack (net.minecraft.item.ItemStack)29 IAllele (forestry.api.genetics.IAllele)14 IGenome (forestry.api.genetics.IGenome)10 ISpeciesType (forestry.api.genetics.ISpeciesType)8 Nullable (javax.annotation.Nullable)7 Gene (binnie.core.genetics.Gene)6 IChromosomeType (forestry.api.genetics.IChromosomeType)6 ArrayList (java.util.ArrayList)6 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)5 Random (java.util.Random)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 IGene (binnie.core.api.genetics.IGene)4 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)4 IBreedingTracker (forestry.api.genetics.IBreedingTracker)3 IFilterData (forestry.api.genetics.IFilterData)3 Tolerance (binnie.core.genetics.Tolerance)2 Point (binnie.core.gui.geometry.Point)2 ControlItemDisplay (binnie.core.gui.minecraft.control.ControlItemDisplay)2