Search in sources :

Example 1 with IArboristTracker

use of forestry.api.arboriculture.IArboristTracker in project ForestryMC by ForestryMC.

the class TreeRoot method getBreedingTracker.

/* BREEDING TRACKER */
@Override
public IArboristTracker getBreedingTracker(World world, @Nullable GameProfile player) {
    String filename = "ArboristTracker." + (player == null ? "common" : player.getId());
    ArboristTracker tracker = (ArboristTracker) world.loadData(ArboristTracker.class, filename);
    // Create a tracker if there is none yet.
    if (tracker == null) {
        tracker = new ArboristTracker(filename);
        world.setData(filename, tracker);
    }
    tracker.setUsername(player);
    tracker.setWorld(world);
    return tracker;
}
Also used : IArboristTracker(forestry.api.arboriculture.IArboristTracker)

Example 2 with IArboristTracker

use of forestry.api.arboriculture.IArboristTracker in project ForestryMC by ForestryMC.

the class TreeRoot method getTreekeepingMode.

@Override
public ITreekeepingMode getTreekeepingMode(World world) {
    if (activeTreekeepingMode != null) {
        return activeTreekeepingMode;
    }
    // No Treekeeping mode yet, item it.
    IArboristTracker tracker = getBreedingTracker(world, null);
    String modeName = tracker.getModeName();
    ITreekeepingMode mode = getTreekeepingMode(modeName);
    Preconditions.checkNotNull(mode);
    setTreekeepingMode(world, mode);
    FMLCommonHandler.instance().getFMLLogger().debug("Set Treekeeping mode for a world to " + mode);
    return activeTreekeepingMode;
}
Also used : ITreekeepingMode(forestry.api.arboriculture.ITreekeepingMode) IArboristTracker(forestry.api.arboriculture.IArboristTracker)

Example 3 with IArboristTracker

use of forestry.api.arboriculture.IArboristTracker 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)

Aggregations

IArboristTracker (forestry.api.arboriculture.IArboristTracker)3 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)1 ITreeGenome (forestry.api.arboriculture.ITreeGenome)1 ITreeMutation (forestry.api.arboriculture.ITreeMutation)1 ITreekeepingMode (forestry.api.arboriculture.ITreekeepingMode)1 IChromosome (forestry.api.genetics.IChromosome)1 IMutation (forestry.api.genetics.IMutation)1 Nullable (javax.annotation.Nullable)1