Search in sources :

Example 16 with IAlleleTreeSpecies

use of forestry.api.arboriculture.IAlleleTreeSpecies 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 17 with IAlleleTreeSpecies

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

the class Tree method addTooltip.

@Override
public void addTooltip(List<String> list) {
    // No info 4 u!
    if (!isAnalyzed) {
        list.add("<" + Translator.translateToLocal("for.gui.unknown") + ">");
        return;
    }
    // You analyzed it? Juicy tooltip coming up!
    IAlleleTreeSpecies primary = genome.getPrimary();
    IAlleleTreeSpecies secondary = genome.getSecondary();
    if (!isPureBred(EnumTreeChromosome.SPECIES)) {
        list.add(TextFormatting.BLUE + Translator.translateToLocal("for.trees.hybrid").replaceAll("%PRIMARY", primary.getAlleleName()).replaceAll("%SECONDARY", secondary.getAlleleName()));
    }
    String sappiness = TextFormatting.GOLD + "S: " + genome.getActiveAllele(EnumTreeChromosome.SAPPINESS).getAlleleName();
    String maturation = TextFormatting.RED + "M: " + genome.getActiveAllele(EnumTreeChromosome.MATURATION).getAlleleName();
    String height = TextFormatting.LIGHT_PURPLE + "H: " + genome.getActiveAllele(EnumTreeChromosome.HEIGHT).getAlleleName();
    String girth = TextFormatting.AQUA + "G: " + String.format("%sx%s", genome.getGirth(), genome.getGirth());
    String saplings = TextFormatting.YELLOW + "S: " + genome.getActiveAllele(EnumTreeChromosome.FERTILITY).getAlleleName();
    String yield = TextFormatting.WHITE + "Y: " + genome.getActiveAllele(EnumTreeChromosome.YIELD).getAlleleName();
    String carbonization = TextFormatting.GRAY + "CA: " + secondary.getWoodProvider().getCarbonization();
    list.add(String.format("%s, %s", saplings, maturation));
    list.add(String.format("%s, %s", height, girth));
    list.add(String.format("%s, %s", yield, sappiness));
    list.add(String.format("%s", carbonization));
    IAlleleBoolean primaryFireproof = (IAlleleBoolean) genome.getActiveAllele(EnumTreeChromosome.FIREPROOF);
    if (primaryFireproof.getValue()) {
        list.add(TextFormatting.RED + Translator.translateToLocal("for.gui.fireresist"));
    }
    IAllele fruit = getGenome().getActiveAllele(EnumTreeChromosome.FRUITS);
    if (fruit != AlleleFruits.fruitNone) {
        String strike = "";
        if (!canBearFruit()) {
            strike = TextFormatting.STRIKETHROUGH.toString();
        }
        list.add(strike + TextFormatting.GREEN + "F: " + genome.getFruitProvider().getDescription());
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleBoolean(forestry.api.genetics.IAlleleBoolean) IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies)

Example 18 with IAlleleTreeSpecies

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

the class TreeGenHelper method getTreeGenome.

private static ITreeGenome getTreeGenome(String speciesName) throws SpeciesNotFoundException, TemplateNotFoundException {
    IAlleleTreeSpecies species = null;
    for (String uid : AlleleManager.alleleRegistry.getRegisteredAlleles().keySet()) {
        if (!uid.equals(speciesName)) {
            continue;
        }
        IAllele allele = AlleleManager.alleleRegistry.getAllele(uid);
        if (allele instanceof IAlleleTreeSpecies) {
            species = (IAlleleTreeSpecies) allele;
            break;
        }
    }
    if (species == null) {
        for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) {
            if (allele instanceof IAlleleTreeSpecies && allele.getAlleleName().replaceAll("\\s", "").equals(speciesName)) {
                species = (IAlleleTreeSpecies) allele;
                break;
            }
        }
    }
    if (species == null) {
        throw new SpeciesNotFoundException(speciesName);
    }
    IAllele[] template = TreeManager.treeRoot.getTemplate(species);
    return TreeManager.treeRoot.templateAsGenome(template);
}
Also used : IAllele(forestry.api.genetics.IAllele) IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) SpeciesNotFoundException(forestry.core.commands.SpeciesNotFoundException)

Example 19 with IAlleleTreeSpecies

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

the class PropertyTree method parseValue.

@Override
public Optional<IAlleleTreeSpecies> parseValue(String value) {
    if (namesMap.isEmpty()) {
        List<IAlleleTreeSpecies> allowedValues = getAllowedValues();
        for (IAlleleTreeSpecies allowedValue : allowedValues) {
            String propertyName = getName(allowedValue);
            namesMap.put(propertyName, allowedValue);
        }
    }
    return Optional.fromNullable(namesMap.get(value));
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies)

Example 20 with IAlleleTreeSpecies

use of forestry.api.arboriculture.IAlleleTreeSpecies in project Binnie by ForestryMC.

the class PagePlanksTrees method getTreesThatMakePlanks.

private static Collection<IAlleleSpecies> getTreesThatMakePlanks(ItemStack fruit, boolean master, World world, GameProfile player) {
    if (fruit == null) {
        return new ArrayList<>();
    }
    ITreeRoot treeRoot = TreeManager.treeRoot;
    IBreedingSystem system = Binnie.GENETICS.getSystem(treeRoot);
    final Collection<IAlleleSpecies> set = master ? system.getAllSpecies() : system.getDiscoveredSpecies(world, player);
    final List<IAlleleSpecies> found = new ArrayList<>();
    for (final IAlleleSpecies species : set) {
        final IAlleleTreeSpecies tSpecies = (IAlleleTreeSpecies) species;
        ITreeGenome genome = treeRoot.templateAsGenome(treeRoot.getTemplate(tSpecies));
        IAlleleTreeSpecies treeSpecies = genome.getPrimary();
        final ItemStack woodStack = treeSpecies.getWoodProvider().getWoodStack();
        ItemStack plankProduct = LumbermillRecipeManager.getPlankProduct(woodStack, world);
        if (!plankProduct.isEmpty() && fruit.isItemEqual(plankProduct)) {
            found.add(species);
        }
    }
    return found;
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) ITreeRoot(forestry.api.arboriculture.ITreeRoot) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) ArrayList(java.util.ArrayList) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) ItemStack(net.minecraft.item.ItemStack) ITreeGenome(forestry.api.arboriculture.ITreeGenome)

Aggregations

IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)24 ITreeGenome (forestry.api.arboriculture.ITreeGenome)14 IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)7 ItemStack (net.minecraft.item.ItemStack)7 IAllele (forestry.api.genetics.IAllele)6 ArrayList (java.util.ArrayList)6 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)6 ResourceLocation (net.minecraft.util.ResourceLocation)6 ILeafSpriteProvider (forestry.api.arboriculture.ILeafSpriteProvider)5 TextureMap (net.minecraft.client.renderer.texture.TextureMap)5 ITree (forestry.api.arboriculture.ITree)4 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)2 IChromosome (forestry.api.genetics.IChromosome)2 IFruitFamily (forestry.api.genetics.IFruitFamily)2 IBlockState (net.minecraft.block.state.IBlockState)2 Biome (net.minecraft.world.biome.Biome)2 ControlText (binnie.core.gui.controls.ControlText)1 Control (binnie.core.gui.controls.core.Control)1 ControlScrollableContent (binnie.core.gui.controls.scroll.ControlScrollableContent)1 Area (binnie.core.gui.geometry.Area)1