Search in sources :

Example 1 with IBeeMutation

use of forestry.api.apiculture.IBeeMutation 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)

Aggregations

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 IChromosome (forestry.api.genetics.IChromosome)1 IMutation (forestry.api.genetics.IMutation)1 Nullable (javax.annotation.Nullable)1 World (net.minecraft.world.World)1