Search in sources :

Example 1 with IChromosomeType

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

the class Genome method getChromosomes.

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;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChromosome(forestry.api.genetics.IChromosome) IChromosome(forestry.api.genetics.IChromosome) IChromosomeType(forestry.api.genetics.IChromosomeType)

Example 2 with IChromosomeType

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

the class Genome method checkChromosomes.

private void checkChromosomes(IChromosome[] chromosomes) {
    if (chromosomes.length != getDefaultTemplate().length) {
        String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template.\n%s", getSpeciesRoot().getUID(), chromosomesToString(chromosomes));
        throw new IllegalArgumentException(message);
    }
    IChromosomeType[] karyotype = getSpeciesRoot().getKaryotype();
    for (int i = 0; i < karyotype.length; i++) {
        IChromosomeType chromosomeType = karyotype[i];
        IChromosome chromosome = chromosomes[i];
        if (chromosome == null) {
            String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing chromosome '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
            throw new IllegalArgumentException(message);
        }
        IAllele primary = chromosome.getPrimaryAllele();
        if (primary == null) {
            String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing primary allele for '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
            throw new IllegalArgumentException(message);
        }
        IAllele secondary = chromosome.getSecondaryAllele();
        if (secondary == null) {
            String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing secondary allele for '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
            throw new IllegalArgumentException(message);
        }
        Class<? extends IAllele> chromosomeAlleleClass = chromosomeType.getAlleleClass();
        if (!chromosomeAlleleClass.isAssignableFrom(primary.getClass())) {
            String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Incorrect type for primary allele '%s'.\n%s.", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
            throw new IllegalArgumentException(message);
        }
        if (!chromosomeAlleleClass.isAssignableFrom(secondary.getClass())) {
            String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Incorrect type for secondary allele '%s'.\n%s.", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes));
            throw new IllegalArgumentException(message);
        }
    }
}
Also used : IAllele(forestry.api.genetics.IAllele) IChromosome(forestry.api.genetics.IChromosome) IChromosomeType(forestry.api.genetics.IChromosomeType)

Example 3 with IChromosomeType

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

the class AlleleRegistry method addValidAlleleTypes.

@Override
public void addValidAlleleTypes(IAllele allele, IChromosomeType... chromosomeTypes) {
    for (IChromosomeType chromosomeType : chromosomeTypes) {
        if (!chromosomeType.getAlleleClass().isAssignableFrom(allele.getClass())) {
            throw new IllegalArgumentException("Allele class (" + allele.getClass() + ") does not match chromosome type (" + chromosomeType.getAlleleClass() + ").");
        }
        allelesByType.put(chromosomeType, allele);
        typesByAllele.put(allele, chromosomeType);
    }
}
Also used : IChromosomeType(forestry.api.genetics.IChromosomeType)

Example 4 with IChromosomeType

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

the class WindowGenesis method initialiseClient.

@Override
@SideOnly(Side.CLIENT)
public void initialiseClient() {
    new ControlPlayerInventory(this);
    this.setTitle(I18N.localise("binniecore.gui.genesis.title"));
    final ControlTabBar<IBreedingSystem> tabSystems = new GenesisTabSystems(this);
    this.root = Binnie.GENETICS.getActiveSystems().iterator().next().getSpeciesRoot();
    this.template = this.root.getDefaultTemplate();
    final Area one = new Area(32, 28, 170, 100);
    final Area two = new Area(214, 28, 100, 100);
    new Panel(this, one.outset(1), MinecraftGUI.PanelType.BLACK);
    new Panel(this, two.outset(1), MinecraftGUI.PanelType.BLACK);
    this.geneList = new GeneList(this, one);
    this.geneOptions = new GeneOptions(this, two);
    tabSystems.addEventHandler(EventValueChanged.class, EventHandlerOrigin.SELF, tabSystems, event -> {
        Object value = event.getValue();
        if (!(value instanceof BreedingSystem)) {
            return;
        }
        IBreedingSystem breedingSystem = (IBreedingSystem) value;
        root = breedingSystem.getSpeciesRoot();
        template = root.getDefaultTemplate();
        refreshTemplate(null);
    });
    this.geneList.addEventHandler(EventValueChanged.class, EventHandlerOrigin.SELF, this.geneList, event -> {
        Object value = event.getValue();
        if (!(value instanceof Gene)) {
            return;
        }
        Gene gene = (Gene) value;
        Map<IChromosomeType, List<IAllele>> map = Binnie.GENETICS.getChromosomeMap(root);
        List<Gene> options = new ArrayList<>();
        IChromosomeType chromosomeType = gene.getChromosome();
        List<IAllele> alleles = map.get(chromosomeType);
        for (IAllele allele : alleles) {
            options.add(new Gene(allele, chromosomeType, root));
        }
        geneOptions.setOptions(options);
    });
    this.geneOptions.addEventHandler(EventValueChanged.class, EventHandlerOrigin.SELF, this.geneOptions, event -> {
        Object value = event.getValue();
        if (!(value instanceof Gene)) {
            return;
        }
        Gene gene = (Gene) value;
        IChromosomeType chromosomeType = gene.getChromosome();
        ISpeciesRoot speciesRoot = gene.getSpeciesRoot();
        IAllele allele = gene.getAllele();
        if (chromosomeType == speciesRoot.getSpeciesChromosomeType()) {
            template = speciesRoot.getTemplate(allele.getUID());
        } else {
            template[chromosomeType.ordinal()] = allele;
        }
        refreshTemplate(chromosomeType);
    });
    this.panelPickup = new Panel(this, 16, 140, 60, 42, MinecraftGUI.PanelType.BLACK);
    this.refreshTemplate(null);
}
Also used : BreedingSystem(binnie.core.genetics.BreedingSystem) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) ArrayList(java.util.ArrayList) IBreedingSystem(binnie.core.api.genetics.IBreedingSystem) IAllele(forestry.api.genetics.IAllele) Panel(binnie.core.gui.window.Panel) Area(binnie.core.gui.geometry.Area) ISpeciesRoot(forestry.api.genetics.ISpeciesRoot) Gene(binnie.core.genetics.Gene) ControlPlayerInventory(binnie.core.gui.minecraft.control.ControlPlayerInventory) ArrayList(java.util.ArrayList) List(java.util.List) IChromosomeType(forestry.api.genetics.IChromosomeType) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with IChromosomeType

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

the class ControlChromosome method setSystem.

public void setSystem(@Nullable IBreedingSystem breedingSystem) {
    if (this.breedingSystem != breedingSystem) {
        this.breedingSystem = breedingSystem;
        deleteAllChildren();
        if (breedingSystem != null) {
            IFieldKitPlugin fieldKitPlugin = breedingSystem.getFieldKitPlugin();
            fieldKitPlugin.getChromosomePickerPositions();
            for (Map.Entry<IChromosomeType, IPoint> entry : fieldKitPlugin.getChromosomePickerPositions().entrySet()) {
                IChromosomeType chromosomeType = entry.getKey();
                IPoint position = entry.getValue();
                new ControlChromoPicker(this, position.xPos(), position.yPos(), chromosomeType);
            }
        }
    }
}
Also used : IFieldKitPlugin(binnie.core.api.genetics.IFieldKitPlugin) IPoint(binnie.core.api.gui.IPoint) IChromosomeType(forestry.api.genetics.IChromosomeType) Map(java.util.Map)

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