@Nullable public IGene getGene(int chromosome) { for (IGene gene : genes) { if (gene.getChromosome().ordinal() == chromosome) { return gene; } } return null; }
@Override public IAllele getActiveAllele(IChromosomeType chromosomeType) { return chromosomes[chromosomeType.ordinal()].getActiveAllele(); }
@Override public IAllele getInactiveAllele(IChromosomeType chromosomeType) { return chromosomes[chromosomeType.ordinal()].getInactiveAllele(); }
@Override public Collection<? extends IMutation> getPaths(IAllele result, IChromosomeType chromosomeType) { ArrayList<IMutation> paths = new ArrayList<>(); for (IMutation mutation : getMutations(false)) { if (mutation.getTemplate()[chromosomeType.ordinal()] == result) { paths.add(mutation); } } return paths; }
@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; }
private static IAllele validateAllele(@Nullable String speciesUid, IChromosomeType chromosomeType, @Nullable IAllele allele) { if (!chromosomeType.getAlleleClass().isInstance(allele)) { ISpeciesRoot speciesRoot = chromosomeType.getSpeciesRoot(); IAllele[] template = null; if (speciesUid != null) { template = speciesRoot.getTemplate(speciesUid); } if (template == null) { template = speciesRoot.getDefaultTemplate(); } return template[chromosomeType.ordinal()]; } return allele; }
private void refreshTemplate(@Nullable IChromosomeType selection) { List<Gene> genes = new ArrayList<>(); IChromosomeType[] chromosomeTypes = Binnie.GENETICS.getChromosomeMap(this.root).keySet().toArray(new IChromosomeType[0]); for (IChromosomeType type : chromosomeTypes) { IAllele allele = this.template[type.ordinal()]; if (allele == null) { throw new NullPointerException("Allele missing for Chromosome " + type.getName()); } genes.add(new Gene(allele, type, this.root)); } geneList.setOptions(genes); if (selection != null) { this.geneList.setValue(new Gene(this.template[selection.ordinal()], selection, this.root)); } else { this.geneOptions.setOptions(new ArrayList<>()); } this.refreshPickup(); }
public static List<SequencerRecipeWrapper> create() { List<SequencerRecipeWrapper> recipes = new ArrayList<>(); Collection<ISpeciesRoot> roots = AlleleManager.alleleRegistry.getSpeciesRoot().values(); for (ISpeciesRoot root : roots) { IChromosomeType speciesChromosomeType = root.getSpeciesChromosomeType(); IAllele[] defaultTemplate = root.getDefaultTemplate(); IAllele species = defaultTemplate[speciesChromosomeType.ordinal()]; ItemStack filledSequence = ItemSequence.create(new Gene(species, speciesChromosomeType, root), false); recipes.add(new SequencerRecipeWrapper(filledSequence)); filledSequence = filledSequence.copy(); filledSequence.setItemDamage(0); recipes.add(new SequencerRecipeWrapper(filledSequence)); } return recipes; } }
@Override public void readFromNBT(NBTTagCompound nbt) { for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) { if (!nbt.hasKey(root.getUID())) { continue; } NBTTagCompound nbtRoot = nbt.getCompoundTag(root.getUID()); for (IChromosomeType chromo : root.getKaryotype()) { if (!nbtRoot.hasKey(String.valueOf(chromo.ordinal()))) { continue; } NBTTagList nbtChromo = nbtRoot.getTagList(String.valueOf(chromo.ordinal()), 8); for (int i = 0; i < nbtChromo.tagCount(); ++i) { String uid = nbtChromo.getStringTagAt(i); IAllele allele = AlleleManager.alleleRegistry.getAllele(uid); if (allele == null) { continue; } Gene gene = new Gene(allele, chromo, root); if (!discoveredGenes.contains(gene)) { discoveredGenes.add(gene); } } } } }
public static List<IsolatorRecipeWrapper> create() { List<IsolatorRecipeWrapper> recipes = new ArrayList<>(); Collection<ISpeciesRoot> roots = AlleleManager.alleleRegistry.getSpeciesRoot().values(); for (ISpeciesRoot root : roots) { ISpeciesType[] speciesTypes = root.getIconType().getClass().getEnumConstants(); IChromosomeType speciesChromosomeType = root.getSpeciesChromosomeType(); IAllele[] defaultTemplate = root.getDefaultTemplate(); IIndividual individual = root.templateAsIndividual(defaultTemplate); for (ISpeciesType speciesType : speciesTypes) { ItemStack memberStack = root.getMemberStack(individual, speciesType); memberStack.setItemDamage(OreDictionary.WILDCARD_VALUE); IAllele species = defaultTemplate[speciesChromosomeType.ordinal()]; ItemStack filledSequence = ItemSequence.create(new Gene(species, speciesChromosomeType, root), false); IsolatorRecipeWrapper recipeWrapper = new IsolatorRecipeWrapper(memberStack, filledSequence); recipes.add(recipeWrapper); } } return recipes; } }
@Override public NBTTagCompound writeToNBT(final NBTTagCompound nbt) { nbt.setString("allele", this.allele.getUID()); nbt.setString("root", this.root.getUID()); nbt.setByte("chromo", (byte) this.chromosome.ordinal()); return nbt; }
public boolean initialize(ItemStack specimen) { IIndividual individual = AlleleManager.alleleRegistry.getIndividual(specimen); if (individual == null) { return false; } IGenome genome = individual.getGenome(); ISpeciesRoot root = genome.getPrimary().getRoot(); tokenCount = getTokenCount(genome); for (int i = 0; i < tokenCount / 2; i++) { IAllele[] randomTemplate = root.getRandomTemplate(rand); String speciesUid = randomTemplate[root.getSpeciesChromosomeType().ordinal()].getUID(); gameTokens.add(new EscritoireGameToken(speciesUid)); gameTokens.add(new EscritoireGameToken(speciesUid)); } Collections.shuffle(gameTokens); return true; }
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) { NBTTagCompound nbtRoot = new NBTTagCompound(); for (IChromosomeType chromo : root.getKaryotype()) { NBTTagList nbtChromo = new NBTTagList(); for (IGene gene : discoveredGenes) { if (gene.getSpeciesRoot() == root && gene.getChromosome() == chromo) { nbtChromo.appendTag(new NBTTagString(gene.getAllele().getUID())); } } nbtRoot.setTag(String.valueOf(chromo.ordinal()), nbtChromo); } nbt.setTag(root.getUID(), nbtRoot); } return nbt; }
@Nullable public IElementGroup createMutation(int x, int y, int width, int height, IMutation mutation, IAllele species, IBreedingTracker breedingTracker) { if (breedingTracker.isDiscovered(mutation)) { PaneLayout element = new PaneLayout(x, y, width, height); ISpeciesRoot speciesRoot = mutation.getRoot(); int speciesIndex = speciesRoot.getSpeciesChromosomeType().ordinal(); IDatabasePlugin plugin = mutation.getRoot().getSpeciesPlugin(); Map<String, ItemStack> iconStacks = plugin.getIndividualStacks(); ItemStack partner = iconStacks.get(mutation.getPartner(species).getUID()); IAllele resultAllele = mutation.getTemplate()[speciesIndex]; ItemStack result = iconStacks.get(resultAllele.getUID()); element.add(new ItemElement(0, 0, partner), new ItemElement(33, 0, result)); createProbabilityArrow(element, mutation, 18, 4, breedingTracker); return element; } // Do not display secret undiscovered mutations. if (mutation.isSecret()) { return null; } return createUnknownMutationGroup(x, y, width, height, mutation, breedingTracker); }
private static IChromosome getChromosome(ItemStack itemStack, IChromosomeType chromosomeType, ISpeciesRoot speciesRoot) { NBTTagCompound nbtTagCompound = itemStack.getTagCompound(); if (nbtTagCompound == null) { nbtTagCompound = new NBTTagCompound(); itemStack.setTagCompound(nbtTagCompound); } NBTTagCompound genomeNbt = nbtTagCompound.getCompoundTag("Genome"); if (genomeNbt.isEmpty()) { Log.error("Got a genetic item with no genome, setting it to a default value."); genomeNbt = new NBTTagCompound(); IAllele[] defaultTemplate = speciesRoot.getDefaultTemplate(); IGenome genome = speciesRoot.templateAsGenome(defaultTemplate); genome.writeToNBT(genomeNbt); nbtTagCompound.setTag("Genome", genomeNbt); } IChromosome[] chromosomes = getChromosomes(genomeNbt, speciesRoot); return chromosomes[chromosomeType.ordinal()]; }
private static IChromosome[] getChromosomes(NBTTagCompound genomeNBT, ISpeciesRoot speciesRoot) { NBTTagList chromosomesNBT = genomeNBT.getTagList("Chromosomes", 10); IChromosome[] chromosomes = new IChromosome[speciesRoot.getDefaultTemplate().length]; String primarySpeciesUid = null; String secondarySpeciesUid = null; for (int i = 0; i < chromosomesNBT.tagCount(); i++) { NBTTagCompound chromosomeNBT = chromosomesNBT.getCompoundTagAt(i); byte chromosomeOrdinal = chromosomeNBT.getByte(SLOT_TAG); if (chromosomeOrdinal >= 0 && chromosomeOrdinal < chromosomes.length) { IChromosomeType chromosomeType = speciesRoot.getKaryotype()[chromosomeOrdinal]; Chromosome chromosome = Chromosome.create(primarySpeciesUid, secondarySpeciesUid, chromosomeType, chromosomeNBT); chromosomes[chromosomeOrdinal] = chromosome; if (chromosomeOrdinal == speciesRoot.getSpeciesChromosomeType().ordinal()) { primarySpeciesUid = chromosome.getPrimaryAllele().getUID(); secondarySpeciesUid = chromosome.getSecondaryAllele().getUID(); } } } return chromosomes; }
@Override public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) { if (this.isInCreativeTab(tab)) { for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) { for (IIndividual template : root.getIndividualTemplates()) { if (template.getGenome().getPrimary().isSecret()) { continue; } IGeneItem geneItem = new GeneArrayItem(); for (IChromosomeType type : root.getKaryotype()) { IChromosome chromosome = template.getGenome().getChromosomes()[type.ordinal()]; if (chromosome != null) { IAllele active = chromosome.getActiveAllele(); geneItem.addGene(new Gene(active, type, root)); } } ItemStack array = new ItemStack(this); geneItem.writeToItem(array); items.add(array); } } } }
@Override public void getTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) { IBreedingSystem system = Binnie.GENETICS.getSystem(this.gene.getSpeciesRoot()); final String cName = system.getChromosomeName(this.gene.getChromosome()); tooltip.add(cName + ": " + this.gene.getName()); if (this.isMouseOver() && this.canFill(Window.get(this).getHeldItemStack())) { tooltip.add("Left click to assign gene"); final IGene existingGene = Engineering.getGene(Window.get(this).getHeldItemStack(), this.gene.getChromosome().ordinal()); if (existingGene == null) { return; } final String dName = system.getChromosomeName(this.gene.getChromosome()); tooltip.add("Will replace " + dName + ": " + existingGene.getName()); } }