Search in sources :

Example 1 with IAlleleSpecies

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

the class TreeGenome method getSpecies.

// NBT RETRIEVAL
public static IAlleleTreeSpecies getSpecies(ItemStack itemStack) {
    Preconditions.checkArgument(TreeManager.treeRoot.isMember(itemStack), "ItemStack must be a tree");
    IAlleleSpecies species = getSpeciesDirectly(TreeManager.treeRoot, itemStack);
    if (species instanceof IAlleleTreeSpecies) {
        return (IAlleleTreeSpecies) species;
    }
    return (IAlleleTreeSpecies) getActiveAllele(itemStack, EnumTreeChromosome.SPECIES, TreeManager.treeRoot);
}
Also used : IAlleleTreeSpecies(forestry.api.arboriculture.IAlleleTreeSpecies) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies)

Example 2 with IAlleleSpecies

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

the class Genome method getSpeciesDirectly.

// NBT RETRIEVAL
/**
 * Quickly gets the species without loading the whole genome.
 * We need this because the client uses the species for rendering.
 */
@Nullable
public static IAlleleSpecies getSpeciesDirectly(ISpeciesRoot speciesRoot, ItemStack itemStack) {
    NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
    if (nbtTagCompound == null) {
        return null;
    }
    NBTTagCompound genomeNBT = nbtTagCompound.getCompoundTag("Genome");
    if (genomeNBT.hasNoTags()) {
        return null;
    }
    NBTTagList chromosomesNBT = genomeNBT.getTagList("Chromosomes", 10);
    if (chromosomesNBT.hasNoTags()) {
        return null;
    }
    NBTTagCompound chromosomeNBT = chromosomesNBT.getCompoundTagAt(0);
    Chromosome chromosome = Chromosome.create(null, null, speciesRoot.getSpeciesChromosomeType(), chromosomeNBT);
    IAllele activeAllele = chromosome.getActiveAllele();
    if (!(activeAllele instanceof IAlleleSpecies)) {
        return null;
    }
    return (IAlleleSpecies) activeAllele;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IAllele(forestry.api.genetics.IAllele) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChromosome(forestry.api.genetics.IChromosome) Nullable(javax.annotation.Nullable)

Example 3 with IAlleleSpecies

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

the class SpeciesWidget method createEntries.

private static ImmutableMap<IAlleleSpecies, ItemStack> createEntries() {
    ImmutableMap.Builder<IAlleleSpecies, ItemStack> entries = ImmutableMap.builder();
    for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
        for (IIndividual individual : root.getIndividualTemplates()) {
            IAlleleSpecies species = individual.getGenome().getPrimary();
            ItemStack itemStack = root.getMemberStack(root.templateAsIndividual(root.getTemplate(species)), root.getIconType());
            entries.put(species, itemStack);
        }
    }
    return entries.build();
}
Also used : ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) ItemStack(net.minecraft.item.ItemStack) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with IAlleleSpecies

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

the class SpeciesWidget method getToolTip.

@Nullable
@Override
public ToolTip getToolTip(int mouseX, int mouseY) {
    IFilterLogic logic = gui.getLogic();
    IAlleleSpecies allele = (IAlleleSpecies) logic.getGenomeFilter(facing, index, active);
    if (allele == null) {
        return null;
    }
    ToolTip tooltip = new ToolTip();
    tooltip.add(getName(allele));
    return tooltip;
}
Also used : ToolTip(forestry.core.gui.tooltips.ToolTip) IFilterLogic(forestry.api.genetics.IFilterLogic) IAlleleSpecies(forestry.api.genetics.IAlleleSpecies) Nullable(javax.annotation.Nullable)

Example 5 with IAlleleSpecies

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

the class EscritoireGameBoard method getTokenCount.

private static int getTokenCount(IGenome genome) {
    IAlleleSpecies species1 = genome.getPrimary();
    IAlleleSpecies species2 = genome.getSecondary();
    int tokenCount = species1.getComplexity() + species2.getComplexity();
    if (tokenCount % 2 != 0) {
        tokenCount = Math.round((float) tokenCount / 2) * 2;
    }
    if (tokenCount > TOKEN_COUNT_MAX) {
        tokenCount = TOKEN_COUNT_MAX;
    } else if (tokenCount < TOKEN_COUNT_MIN) {
        tokenCount = TOKEN_COUNT_MIN;
    }
    return tokenCount;
}
Also used : IAlleleSpecies(forestry.api.genetics.IAlleleSpecies)

Aggregations

IAlleleSpecies (forestry.api.genetics.IAlleleSpecies)37 ItemStack (net.minecraft.item.ItemStack)11 IAlleleTreeSpecies (forestry.api.arboriculture.IAlleleTreeSpecies)7 ITreeGenome (forestry.api.arboriculture.ITreeGenome)6 IAllele (forestry.api.genetics.IAllele)6 ArrayList (java.util.ArrayList)6 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)5 IIndividual (forestry.api.genetics.IIndividual)4 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)4 ControlText (binnie.core.gui.controls.ControlText)3 ControlSpeciesBox (binnie.core.gui.database.ControlSpeciesBox)3 WindowAbstractDatabase (binnie.core.gui.database.WindowAbstractDatabase)3 Area (binnie.core.gui.geometry.Area)3 IBreedingTracker (forestry.api.genetics.IBreedingTracker)3 IClassification (forestry.api.genetics.IClassification)3 IMutation (forestry.api.genetics.IMutation)3 Nullable (javax.annotation.Nullable)3 ITreeBreedingSystem (binnie.genetics.api.ITreeBreedingSystem)2 GameProfile (com.mojang.authlib.GameProfile)2 Alignment (binnie.core.api.gui.Alignment)1