Search in sources :

Example 1 with IGenome

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

the class Butterfly method mutateSpecies.

@Nullable
private static IChromosome[] mutateSpecies(World world, IButterflyNursery nursery, IGenome genomeOne, IGenome genomeTwo) {
    IChromosome[] parent1 = genomeOne.getChromosomes();
    IChromosome[] parent2 = genomeTwo.getChromosomes();
    IGenome genome0;
    IGenome genome1;
    IAllele allele0;
    IAllele allele1;
    if (rand.nextBoolean()) {
        allele0 = parent1[EnumButterflyChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = parent2[EnumButterflyChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeOne;
        genome1 = genomeTwo;
    } else {
        allele0 = parent2[EnumButterflyChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = parent1[EnumButterflyChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeTwo;
        genome1 = genomeOne;
    }
    for (IButterflyMutation mutation : ButterflyManager.butterflyRoot.getMutations(true)) {
        float chance = mutation.getChance(world, nursery, allele0, allele1, genome0, genome1);
        if (chance > rand.nextFloat() * 100) {
            return ButterflyManager.butterflyRoot.templateAsChromosomes(mutation.getTemplate());
        }
    }
    return null;
}
Also used : IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) IChromosome(forestry.api.genetics.IChromosome) IButterflyMutation(forestry.api.lepidopterology.IButterflyMutation) Nullable(javax.annotation.Nullable)

Example 2 with IGenome

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

the class FilterLogic method isValid.

public boolean isValid(EnumFacing facing, ItemStack itemStack, IFilterData filterData) {
    IFilterRuleType rule = getRule(facing);
    if (rule == DefaultFilterRuleType.CLOSED) {
        return false;
    }
    if (rule == DefaultFilterRuleType.ITEM && !filterData.isPresent()) {
        return true;
    }
    String requiredRoot = rule.getRootUID();
    if (requiredRoot != null && (!filterData.isPresent() || !filterData.getRoot().getUID().equals(requiredRoot))) {
        return false;
    }
    if (rule == DefaultFilterRuleType.ANYTHING || rule.isValid(itemStack, filterData)) {
        if (filterData.isPresent()) {
            IIndividual ind = filterData.getIndividual();
            IGenome genome = ind.getGenome();
            IAllele active = genome.getPrimary();
            IAllele inactive = genome.getSecondary();
            if (!isValidAllelePair(facing, active.getUID(), inactive.getUID())) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : IAllele(forestry.api.genetics.IAllele) IFilterRuleType(forestry.api.genetics.IFilterRuleType) IGenome(forestry.api.genetics.IGenome) IIndividual(forestry.api.genetics.IIndividual)

Example 3 with IGenome

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

the class EscritoireGameBoard method initialize.

public boolean initialize(ItemStack specimen) {
    IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen);
    if (individual == null) {
        return false;
    }
    IGenome genome = individual.getGenome();
    ISpeciesRoot root = genome.getPrimary().getRoot();
    tokenCount = getTokenCount(genome);
    for (int i = 0; i < tokenCount / 2; i++) {
        IAllele[] randomTemplate = root.getRandomTemplate(rand);
        String speciesUid = randomTemplate[root.getSpeciesChromosomeType().ordinal()].getUID();
        gameTokens.add(new EscritoireGameToken(speciesUid));
        gameTokens.add(new EscritoireGameToken(speciesUid));
    }
    Collections.shuffle(gameTokens);
    return true;
}
Also used : IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual)

Example 4 with IGenome

use of forestry.api.genetics.IGenome in project EnderIO by SleepyTrousers.

the class SpeciesItemFilter method itemMatched.

private boolean itemMatched(@Nonnull ItemStack item) {
    if (Prep.isInvalid(item)) {
        return false;
    }
    ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(item);
    if (speciesRoot == null) {
        return false;
    }
    IIndividual member = speciesRoot.getMember(item);
    if (member == null) {
        return false;
    }
    IGenome genome = member.getGenome();
    String primarySpeciesUid = genome.getPrimary().getUID();
    String secondarySpeciesUid = genome.getSecondary().getUID();
    for (int slot = 0; slot < items.size(); slot++) {
        ItemStack slotItem = items.get(slot);
        if (slotItem.getItem() == item.getItem()) {
            switch(speciesMode) {
                case BOTH:
                    if (primarySpeciesUids[slot].equals(primarySpeciesUid) && secondarySpeciesUids[slot].equals(secondarySpeciesUid)) {
                        return true;
                    }
                    break;
                case PRIMARY:
                    if (primarySpeciesUids[slot].equals(primarySpeciesUid)) {
                        return true;
                    }
                    break;
                case SECONDARY:
                    if (secondarySpeciesUids[slot].equals(secondarySpeciesUid)) {
                        return true;
                    }
                    break;
            }
        }
    }
    return false;
}
Also used : IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) TextComponentString(net.minecraft.util.text.TextComponentString) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IGenome

use of forestry.api.genetics.IGenome 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)

Aggregations

IGenome (forestry.api.genetics.IGenome)13 IIndividual (forestry.api.genetics.IIndividual)10 IAllele (forestry.api.genetics.IAllele)7 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)7 ItemStack (net.minecraft.item.ItemStack)5 Gene (binnie.core.genetics.Gene)2 Tolerance (binnie.core.genetics.Tolerance)2 IAlleleTolerance (forestry.api.genetics.IAlleleTolerance)2 IChromosome (forestry.api.genetics.IChromosome)2 IChromosomeType (forestry.api.genetics.IChromosomeType)2 Random (java.util.Random)2 Nullable (javax.annotation.Nullable)2 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)1 IGene (binnie.core.api.genetics.IGene)1 MachineUtil (binnie.core.machines.MachineUtil)1 ErrorState (binnie.core.machines.errors.ErrorState)1 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)1 IBreedingTracker (forestry.api.genetics.IBreedingTracker)1 IFilterRuleType (forestry.api.genetics.IFilterRuleType)1 IMutation (forestry.api.genetics.IMutation)1