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;
}
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;
}
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;
}
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;
}
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();
}
Aggregations