Search in sources :

Example 6 with IChromosomeType

use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.

the class WindowFieldKit method refreshSpecies.

private void refreshSpecies() {
    final ItemStack item = this.getWindowInventory().getStackInSlot(INDIVIDUAL_SLOT);
    if (item.isEmpty() || !AlleleManager.alleleRegistry.isIndividual(item)) {
        return;
    }
    final IIndividual ind = AlleleManager.alleleRegistry.getIndividual(item);
    if (ind == null) {
        return;
    }
    final ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(item);
    if (root == null) {
        return;
    }
    IBreedingSystem system = Binnie.GENETICS.getSystem(root);
    this.chromo.setSystem(system);
    final Random rand = new Random();
    this.info.clear();
    for (final IChromosomeType type : root.getKaryotype()) {
        if (!Binnie.GENETICS.isInvalidChromosome(type)) {
            final IAllele allele = ind.getGenome().getActiveAllele(type);
            final List<String> infos = new ArrayList<>();
            int i = 0;
            for (String pref = root.getUID() + ".fieldkit." + type.getName().toLowerCase() + '.'; I18N.canLocalise(pref + i); ++i) {
                infos.add(I18N.localise(pref + i));
            }
            String text = system.getAlleleName(type, allele);
            if (!infos.isEmpty()) {
                text = infos.get(rand.nextInt(infos.size()));
            }
            this.info.put(type, text);
            this.chromo.setSystem(system);
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IIndividual(forestry.api.genetics.IIndividual) Random(java.util.Random) ArrayList(java.util.ArrayList) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack) Point(binnie.core.gui.geometry.Point)

Example 7 with IChromosomeType

use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.

the class ManagerGenetics method loadAlleles.

private void loadAlleles() {
    this.invalidChromosomeTypes.clear();
    for (IBreedingSystem system : BREEDING_SYSTEMS.values()) {
        ISpeciesRoot root = system.getSpeciesRoot();
        Map<IChromosomeType, List<IAllele>> chromosomeMap = new LinkedHashMap<>();
        for (IChromosomeType chromosome : root.getKaryotype()) {
            TreeSet<IAllele> alleles = new TreeSet<>(new ComparatorAllele());
            for (IIndividual individual : root.getIndividualTemplates()) {
                IGenome genome = individual.getGenome();
                IAllele activeAllele = genome.getActiveAllele(chromosome);
                IAllele inactiveAllele = genome.getInactiveAllele(chromosome);
                if (chromosome.getAlleleClass().isInstance(activeAllele)) {
                    alleles.add(activeAllele);
                }
                if (!chromosome.getAlleleClass().isInstance(inactiveAllele)) {
                    continue;
                }
                alleles.add(inactiveAllele);
            }
            system.addExtraAlleles(chromosome, alleles);
            if (alleles.size() == 0) {
                this.invalidChromosomeTypes.add(chromosome);
            } else {
                final List<IAllele> alleleList = new ArrayList<>(alleles);
                chromosomeMap.put(chromosome, alleleList);
            }
        }
        this.chromosomeArray.put(root, chromosomeMap);
    }
}
Also used : IIndividual(forestry.api.genetics.IIndividual) ArrayList(java.util.ArrayList) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) LinkedHashMap(java.util.LinkedHashMap) IAllele(forestry.api.genetics.IAllele) IGenome(forestry.api.genetics.IGenome) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) List(java.util.List) IChromosomeType(forestry.api.genetics.IChromosomeType)

Example 8 with IChromosomeType

use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.

the class WindowGeneBank method initialiseClient.

@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
    super.initialiseClient();
    this.addEventHandler(EventValueChanged.class, event -> {
        if (event.getValue() instanceof BreedingSystem) {
            WindowGeneBank.this.genes.setValue((IBreedingSystem) event.getValue());
        }
    });
    int x = 16;
    final int y = 32;
    new ControlPlayerInventory(this, x, y);
    x += 124;
    int boxX = x;
    final int geneBoxWidth = 120;
    new Panel(this, boxX + 24, 32, geneBoxWidth, 120, MinecraftGUI.PanelType.BLACK);
    new Panel(this, boxX + 24 + geneBoxWidth, 32, 14, 120, MinecraftGUI.PanelType.GRAY);
    final ControlScrollableContent<ControlGeneScroll> scroll = new ControlScrollableContent<>(this, boxX + 24 + 2, 34, geneBoxWidth + 10, 116, 12);
    final ControlTextEdit edit = new ControlTextEdit(this, boxX + 27 + geneBoxWidth - 70, 18, 80, 12);
    this.addEventHandler(EventTextEdit.class, EventHandlerOrigin.SELF, edit, event -> {
        String value = event.getValue();
        if (value == null) {
            value = "";
        }
        WindowGeneBank.this.genes.setFilter(value);
    });
    this.genes = new ControlGeneScroll(scroll, 1, 1, geneBoxWidth, 116);
    scroll.setScrollableContent(this.genes);
    this.genes.setGenes(Binnie.GENETICS.getFirstActiveSystem());
    final ControlTabBar<IBreedingSystem> tabBar = new GeneBankTabBar(this, boxX);
    tabBar.setValue(Binnie.GENETICS.getFirstActiveSystem());
    boxX -= 8;
    final ControlTabBar<String> infoTabs = new ControlTabBar<>(this, boxX + 8, 160, 16, 50, Alignment.LEFT, Arrays.asList("Info", "Stats", "Ranking"));
    final Panel panelProject = new Panel(this, boxX + 24, 160, geneBoxWidth + 20, 50, MinecraftGUI.PanelType.BLACK);
    int totalGenes = 0;
    int seqGenes = 0;
    for (final IBreedingSystem system : Binnie.GENETICS.getActiveSystems()) {
        final GeneTracker tracker = GeneTracker.getTracker(this.getWorld(), this.getUsername());
        final Map<IChromosomeType, List<IAllele>> genes = Binnie.GENETICS.getChromosomeMap(system.getSpeciesRoot());
        for (final Map.Entry<IChromosomeType, List<IAllele>> entry : genes.entrySet()) {
            totalGenes += entry.getValue().size();
            for (final IAllele allele : entry.getValue()) {
                final Gene gene = new Gene(allele, entry.getKey(), system.getSpeciesRoot());
                if (tracker.isSequenced(gene)) {
                    ++seqGenes;
                }
            }
        }
    }
    new ControlText(panelProject, new Point(4, 4), "§nFull Genome Project");
    new ControlText(panelProject, new Point(4, 18), "§oSequenced §r" + seqGenes + '/' + totalGenes + " §oGenes");
}
Also used : BreedingSystem(binnie.core.genetics.BreedingSystem) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) ControlTextEdit(binnie.core.gui.controls.ControlTextEdit) ControlText(binnie.core.gui.controls.ControlText) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) Point(binnie.core.gui.geometry.Point) Point(binnie.core.gui.geometry.Point) ControlTabBar(binnie.core.gui.controls.tab.ControlTabBar) IAllele(forestry.api.genetics.IAllele) Panel(binnie.core.gui.window.Panel) Gene(binnie.core.genetics.Gene) ControlPlayerInventory(binnie.core.gui.minecraft.control.ControlPlayerInventory) List(java.util.List) IChromosomeType(forestry.api.genetics.IChromosomeType) GeneTracker(binnie.genetics.genetics.GeneTracker) Map(java.util.Map) ControlScrollableContent(binnie.core.gui.controls.scroll.ControlScrollableContent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 9 with IChromosomeType

use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.

the class ItemSerum method getSubItems.

@Override
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
    if (this.isInCreativeTab(tab)) {
        for (ISpeciesRoot root : AlleleManager.alleleRegistry.getSpeciesRoot().values()) {
            Map<IChromosomeType, List<IAllele>> chromosomeMap = Binnie.GENETICS.getChromosomeMap(root);
            if (chromosomeMap != null) {
                for (Map.Entry<IChromosomeType, List<IAllele>> entry : chromosomeMap.entrySet()) {
                    IChromosomeType chromosome = entry.getKey();
                    for (final IAllele allele : entry.getValue()) {
                        Gene gene = Gene.create(allele, chromosome, root);
                        IGeneItem geneItem = new GeneItem(gene);
                        ItemStack stack = new ItemStack(this);
                        geneItem.writeToItem(stack);
                        items.add(stack);
                    }
                }
            }
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IGeneItem(binnie.genetics.genetics.IGeneItem) Gene(binnie.core.genetics.Gene) IGene(binnie.core.api.genetics.IGene) GeneItem(binnie.genetics.genetics.GeneItem) IGeneItem(binnie.genetics.genetics.IGeneItem) List(java.util.List) NonNullList(net.minecraft.util.NonNullList) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map)

Example 10 with IChromosomeType

use of forestry.api.genetics.IChromosomeType in project Binnie by ForestryMC.

the class ItemSerumArray method getSubItems.

@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);
            }
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) IGeneItem(binnie.genetics.genetics.IGeneItem) IIndividual(forestry.api.genetics.IIndividual) Gene(binnie.core.genetics.Gene) IGene(binnie.core.api.genetics.IGene) IChromosome(forestry.api.genetics.IChromosome) IChromosomeType(forestry.api.genetics.IChromosomeType) ItemStack(net.minecraft.item.ItemStack) GeneArrayItem(binnie.genetics.genetics.GeneArrayItem)

Aggregations

IChromosomeType (forestry.api.genetics.IChromosomeType)20 IAllele (forestry.api.genetics.IAllele)14 Gene (binnie.core.genetics.Gene)11 ISpeciesRoot (forestry.api.genetics.ISpeciesRoot)11 ArrayList (java.util.ArrayList)8 ItemStack (net.minecraft.item.ItemStack)7 IIndividual (forestry.api.genetics.IIndividual)6 IBreedingSystem (binnie.core.api.genetics.IBreedingSystem)5 List (java.util.List)5 IGene (binnie.core.api.genetics.IGene)4 Point (binnie.core.gui.geometry.Point)4 IChromosome (forestry.api.genetics.IChromosome)4 Map (java.util.Map)4 ControlText (binnie.core.gui.controls.ControlText)3 ControlPlayerInventory (binnie.core.gui.minecraft.control.ControlPlayerInventory)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 BreedingSystem (binnie.core.genetics.BreedingSystem)2 Area (binnie.core.gui.geometry.Area)2