Search in sources :

Example 6 with IMutation

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

the class Tree method mutateSpecies.

@Nullable
private static IChromosome[] mutateSpecies(World world, @Nullable GameProfile playerProfile, BlockPos pos, ITreeGenome genomeOne, ITreeGenome genomeTwo) {
    IChromosome[] parent1 = genomeOne.getChromosomes();
    IChromosome[] parent2 = genomeTwo.getChromosomes();
    ITreeGenome genome0;
    ITreeGenome genome1;
    IAlleleTreeSpecies allele0;
    IAlleleTreeSpecies allele1;
    if (world.rand.nextBoolean()) {
        allele0 = (IAlleleTreeSpecies) parent1[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = (IAlleleTreeSpecies) parent2[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeOne;
        genome1 = genomeTwo;
    } else {
        allele0 = (IAlleleTreeSpecies) parent2[EnumTreeChromosome.SPECIES.ordinal()].getPrimaryAllele();
        allele1 = (IAlleleTreeSpecies) parent1[EnumTreeChromosome.SPECIES.ordinal()].getSecondaryAllele();
        genome0 = genomeTwo;
        genome1 = genomeOne;
    }
    IArboristTracker breedingTracker = null;
    if (playerProfile != null) {
        breedingTracker = TreeManager.treeRoot.getBreedingTracker(world, playerProfile);
    }
    List<IMutation> combinations = TreeManager.treeRoot.getCombinations(allele0, allele1, true);
    for (IMutation mutation : combinations) {
        ITreeMutation treeMutation = (ITreeMutation) mutation;
        // Stop blacklisted species.
        // if (BeeManager.breedingManager.isBlacklisted(mutation.getTemplate()[0].getUID())) {
        // continue;
        // }
        float chance = treeMutation.getChance(world, pos, allele0, allele1, genome0, genome1);
        if (chance <= 0) {
            continue;
        }
        // boost chance for researched mutations
        if (breedingTracker != null && breedingTracker.isResearched(treeMutation)) {
            float mutationBoost = chance * (Config.researchMutationBoostMultiplier - 1.0f);
            mutationBoost = Math.min(Config.maxResearchMutationBoostPercent, mutationBoost);
            chance += mutationBoost;
        }
        if (chance > world.rand.nextFloat() * 100) {
            return TreeManager.treeRoot.templateAsChromosomes(treeMutation.getTemplate());
        }
    }
    return null;
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IMutation(forestry.api.genetics.IMutation) IChromosome(forestry.api.genetics.IChromosome) ITreeMutation(forestry.api.arboriculture.ITreeMutation) ITreeGenome(forestry.api.arboriculture.ITreeGenome) IArboristTracker(forestry.api.arboriculture.IArboristTracker) Nullable(javax.annotation.Nullable)

Example 7 with IMutation

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

the class SpeciesRoot method getResultantMutations.

@Override
public List<? extends IMutation> getResultantMutations(IAllele other) {
    List<IMutation> mutations = new ArrayList<>();
    int speciesIndex = getSpeciesChromosomeType().ordinal();
    for (IMutation mutation : getMutations(false)) {
        IAllele[] template = mutation.getTemplate();
        if (template == null || template.length <= speciesIndex) {
            continue;
        }
        IAllele speciesAllele = template[speciesIndex];
        if (speciesAllele == other) {
            mutations.add(mutation);
        }
    }
    return mutations;
}
Also used : IAllele(forestry.api.genetics.IAllele) IMutation(forestry.api.genetics.IMutation) ArrayList(java.util.ArrayList)

Example 8 with IMutation

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

the class SpeciesRoot method getCombinations.

@Override
public List<IMutation> getCombinations(IAlleleSpecies parentSpecies0, IAlleleSpecies parentSpecies1, boolean shuffle) {
    List<IMutation> combinations = new ArrayList<>();
    String parentSpecies1UID = parentSpecies1.getUID();
    for (IMutation mutation : getMutations(shuffle)) {
        if (mutation.isPartner(parentSpecies0)) {
            IAllele partner = mutation.getPartner(parentSpecies0);
            if (partner.getUID().equals(parentSpecies1UID)) {
                combinations.add(mutation);
            }
        }
    }
    return combinations;
}
Also used : IAllele(forestry.api.genetics.IAllele) IMutation(forestry.api.genetics.IMutation) ArrayList(java.util.ArrayList)

Example 9 with IMutation

use of forestry.api.genetics.IMutation 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 10 with IMutation

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

the class GuiAlyzer method drawAnalyticsPageMutations.

public void drawAnalyticsPageMutations(IIndividual individual) {
    textLayout.startPage(COLUMN_0, COLUMN_1, COLUMN_2);
    textLayout.drawLine(Translator.translateToLocal("for.gui.beealyzer.mutations") + ":", COLUMN_0);
    textLayout.newLine();
    RenderHelper.enableGUIStandardItemLighting();
    IGenome genome = individual.getGenome();
    ISpeciesRoot speciesRoot = genome.getSpeciesRoot();
    IAlleleSpecies species = genome.getPrimary();
    int columnWidth = 50;
    int x = 0;
    EntityPlayer player = Minecraft.getMinecraft().player;
    IBreedingTracker breedingTracker = speciesRoot.getBreedingTracker(player.world, player.getGameProfile());
    for (IMutation mutation : speciesRoot.getCombinations(species)) {
        if (breedingTracker.isDiscovered(mutation)) {
            drawMutationInfo(mutation, species, COLUMN_0 + x, breedingTracker);
        } else {
            // Do not display secret undiscovered mutations.
            if (mutation.isSecret()) {
                continue;
            }
            drawUnknownMutation(mutation, COLUMN_0 + x, breedingTracker);
        }
        x += columnWidth;
        if (x >= columnWidth * 4) {
            x = 0;
            textLayout.newLine(16);
        }
    }
    textLayout.endPage();
}
Also used : IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IMutation(forestry.api.genetics.IMutation) IBreedingTracker(forestry.api.genetics.IBreedingTracker) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

IMutation (forestry.api.genetics.IMutation)10 IAllele (forestry.api.genetics.IAllele)3 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)3 ArrayList (java.util.ArrayList)3 IBreedingTracker (forestry.api.genetics.IBreedingTracker)2 IChromosome (forestry.api.genetics.IChromosome)2 Nullable (javax.annotation.Nullable)2 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)1 GameProfile (com.mojang.authlib.GameProfile)1 IAlleleBeeSpecies (forestry.api.apiculture.IAlleleBeeSpecies)1 IApiaristTracker (forestry.api.apiculture.IApiaristTracker)1 IBeeGenome (forestry.api.apiculture.IBeeGenome)1 IBeeMutation (forestry.api.apiculture.IBeeMutation)1 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)1 IArboristTracker (forestry.api.arboriculture.IArboristTracker)1 ITreeGenome (forestry.api.arboriculture.ITreeGenome)1 ITreeMutation (forestry.api.arboriculture.ITreeMutation)1 IGenome (forestry.api.genetics.IGenome)1 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)1 LinkedHashSet (java.util.LinkedHashSet)1