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